From 92e549dfb5f19125f4b6131937b738eee5b046c7 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Thu, 4 Apr 2013 22:46:10 +0000 Subject: test: be more flexible with Mahoro::NONE matches Different versions/installations of libmagic may return different results. --- test.rb | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/test.rb b/test.rb index 574979d..fe00b36 100755 --- a/test.rb +++ b/test.rb @@ -9,9 +9,19 @@ class MahoroTestCase < Test::Unit::TestCase @m = Mahoro.new end + # Different versions of libmagic may generate different values. + # So far, we have seen: + # - ASCII C program text + # - C source, ASCII text + def assert_c_text(buf) + assert_match(/\bC\b/, buf, "contains the letter C") + assert_match(/\s/, buf, "contains spaces") + assert_match(/(?:source|text)/, buf, "is source or text") + end + def test_file @m.flags = Mahoro::NONE - assert_equal('ASCII C program text', @m.file('mahoro.c')) + assert_c_text(@m.file('mahoro.c')) end def test_mime_file @@ -28,14 +38,13 @@ class MahoroTestCase < Test::Unit::TestCase def test_buffer @m.flags = Mahoro::NONE - assert_equal('ASCII C program text', - @m.buffer(File.read('mahoro.c'))) + assert_c_text(@m.buffer(File.read('mahoro.c'))) end def test_buffer_string_convert tmp = File.read('mahoro.c') buf = Struct.new(:to_str).new(tmp) - assert_equal('ASCII C program text', @m.buffer(buf)) + assert_c_text(@m.buffer(buf)) end def test_buffer_invalid -- cgit v1.2.3-24-ge0c7