about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2013-04-04 22:46:10 +0000
committerEric Wong <normalperson@yhbt.net>2013-04-04 22:46:10 +0000
commit92e549dfb5f19125f4b6131937b738eee5b046c7 (patch)
tree9a50f834f8e7f258ca9be6735f2247c514bcd876
parent7027149ddd5d2cafb8483e88fcfd9e5b49ed141f (diff)
downloadmahoro-92e549dfb5f19125f4b6131937b738eee5b046c7.tar.gz
test: be more flexible with Mahoro::NONE matches
Different versions/installations of libmagic may return
different results.
-rwxr-xr-xtest.rb17
1 files 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