diff options
Diffstat (limited to 'test/test_syslog.rb')
-rw-r--r-- | test/test_syslog.rb | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/test/test_syslog.rb b/test/test_syslog.rb index 063d3b1e11..4be12ff798 100644 --- a/test/test_syslog.rb +++ b/test/test_syslog.rb @@ -115,6 +115,10 @@ class TestSyslog < Test::Unit::TestCase Syslog.close if Syslog.opened? end + def syslog_line_regex(ident, message) + /(?:^| )#{Regexp.quote(ident)}(?:\[([1-9][0-9]*)\])?(?: |[: ].* )#{Regexp.quote(message)}$/ + end + def test_log stderr = IO::pipe @@ -145,11 +149,23 @@ class TestSyslog < Test::Unit::TestCase return unless Syslog.const_defined?(:LOG_PERROR) 2.times { - assert_equal("syslog_test: test1 - hello, world!\n", stderr[0].gets) + re = syslog_line_regex("syslog_test", "test1 - hello, world!") + line = stderr[0].gets + m = re.match(line) + assert_not_nil(m) + if m[1] + # pid is written regardless of LOG_PID on OS X 10.7+ + assert_equal(pid, m[1].to_i) + end } 2.times { - assert_equal(format("syslog_test[%d]: test2 - pid\n", pid), stderr[0].gets) + re = syslog_line_regex("syslog_test", "test2 - pid") + line = stderr[0].gets + m = re.match(line) + assert_not_nil(m) + assert_not_nil(m[1]) + assert_equal(pid, m[1].to_i) } end |