Class: TestSyslog
- Inherits:
-
Test::Unit::TestCase
- Object
- Test::Unit::TestCase
- TestSyslog
- Defined in:
- test.rb
Instance Method Summary collapse
- #test_close ⇒ Object
- #test_inspect ⇒ Object
- #test_instance ⇒ Object
- #test_log ⇒ Object
- #test_mask ⇒ Object
- #test_new ⇒ Object
- #test_open ⇒ Object
- #test_opened? ⇒ Boolean
Instance Method Details
#test_close ⇒ Object
90 91 92 93 94 |
# File 'test.rb', line 90 def test_close assert_raises(RuntimeError) { Syslog.close } end |
#test_inspect ⇒ Object
151 152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'test.rb', line 151 def test_inspect Syslog.open { |sl| assert_equal(format('<#%s: opened=true, ident="%s", options=%d, facility=%d, mask=%d>', Syslog, sl.ident, sl., sl.facility, sl.mask), sl.inspect) } assert_equal(format('<#%s: opened=false>', Syslog), Syslog.inspect) end |
#test_instance ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 |
# File 'test.rb', line 22 def test_instance sl1 = Syslog.instance sl2 = Syslog.open sl3 = Syslog.instance assert_equal(Syslog, sl1) assert_equal(Syslog, sl2) assert_equal(Syslog, sl3) ensure Syslog.close if Syslog.opened? end |
#test_log ⇒ Object
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'test.rb', line 114 def test_log stderr = IO::pipe pid = fork { stderr[0].close STDERR.reopen(stderr[1]) stderr[1].close = Syslog::LOG_PERROR | Syslog::LOG_NDELAY Syslog.open("syslog_test", ) { |sl| sl.log(Syslog::LOG_NOTICE, "test1 - hello, %s!", "world") sl.notice("test1 - hello, %s!", "world") } Syslog.open("syslog_test", | Syslog::LOG_PID) { |sl| sl.log(Syslog::LOG_CRIT, "test2 - pid") sl.crit("test2 - pid") } exit! } stderr[1].close Process.waitpid(pid) # LOG_PERROR is not yet implemented on Cygwin. return if RUBY_PLATFORM =~ /cygwin/ 2.times { assert_equal("syslog_test: test1 - hello, world!\n", stderr[0].gets) } 2.times { assert_equal(format("syslog_test[%d]: test2 - pid\n", pid), stderr[0].gets) } end |
#test_mask ⇒ Object
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'test.rb', line 96 def test_mask assert_equal(nil, Syslog.mask) Syslog.open orig = Syslog.mask Syslog.mask = Syslog.LOG_UPTO(Syslog::LOG_ERR) assert_equal(Syslog.LOG_UPTO(Syslog::LOG_ERR), Syslog.mask) Syslog.mask = Syslog.LOG_MASK(Syslog::LOG_CRIT) assert_equal(Syslog.LOG_MASK(Syslog::LOG_CRIT), Syslog.mask) Syslog.mask = orig ensure Syslog.close if Syslog.opened? end |
#test_new ⇒ Object
16 17 18 19 20 |
# File 'test.rb', line 16 def test_new assert_raises(NoMethodError) { Syslog.new } end |
#test_open ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'test.rb', line 34 def test_open # default parameters Syslog.open assert_equal($0, Syslog.ident) assert_equal(Syslog::LOG_PID | Syslog::LOG_CONS, Syslog.) assert_equal(Syslog::LOG_USER, Syslog.facility) # open without close assert_raises(RuntimeError) { Syslog.open } Syslog.close # given parameters Syslog.open("foo", Syslog::LOG_NDELAY | Syslog::LOG_PERROR, Syslog::LOG_DAEMON) assert_equal('foo', Syslog.ident) assert_equal(Syslog::LOG_NDELAY | Syslog::LOG_PERROR, Syslog.) assert_equal(Syslog::LOG_DAEMON, Syslog.facility) Syslog.close # default parameters again (after close) Syslog.open Syslog.close assert_equal(nil, Syslog.ident) assert_equal(nil, Syslog.) assert_equal(nil, Syslog.facility) # block param = nil Syslog.open { |param| } assert_equal(Syslog, param) ensure Syslog.close if Syslog.opened? end |
#test_opened? ⇒ Boolean
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'test.rb', line 74 def test_opened? assert_equal(false, Syslog.opened?) Syslog.open assert_equal(true, Syslog.opened?) Syslog.close assert_equal(false, Syslog.opened?) Syslog.open { assert_equal(true, Syslog.opened?) } assert_equal(false, Syslog.opened?) end |