From 39eea54cfe59d69282271e75703fd053b377a2f0 Mon Sep 17 00:00:00 2001 From: knu Date: Fri, 5 Aug 2011 08:26:42 +0000 Subject: * test/test_syslog.rb (TestSyslog#test_log): Do not be too specific about the log line format. Fixes #5081. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32859 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/test_syslog.rb | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'test/test_syslog.rb') 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 -- cgit v1.2.3