#!/usr/local/bin/ruby -w require 'rubygems' require 'minitest/autorun' require 'stringio' $TESTING = true require 'unit_diff' class TestUnitDiff < Minitest::Test def setup @diff = UnitDiff.new end def test_input header = "Loaded suite ./blah\nStarted\nFF\nFinished in 0.035332 seconds.\n\n" input = "#{header} 1) Failure:\ntest_test1(TestBlah) [./blah.rb:25]:\n<\"line1\\nline2\\nline3\\n\"> expected but was\n<\"line4\\nline5\\nline6\\n\">.\n\n 2) Failure:\ntest_test2(TestBlah) [./blah.rb:29]:\n<\"line1\"> expected but was\n<\"line2\\nline3\\n\\n\">.\n\n2 tests, 2 assertions, 2 failures, 0 errors\n" # TODO: I think I'd like a separate footer array as well expected = [[[" 1) Failure:\n", "test_test1(TestBlah) [./blah.rb:25]:\n", "<\"line1\\nline2\\nline3\\n\"> expected but was\n", "<\"line4\\nline5\\nline6\\n\">.\n"], [" 2) Failure:\n", "test_test2(TestBlah) [./blah.rb:29]:\n", "<\"line1\"> expected but was\n", "<\"line2\\nline3\\n\\n\">.\n"]], ["\n", "2 tests, 2 assertions, 2 failures, 0 errors\n"]] util_unit_diff(header, input, expected, :parse_input) end def test_input_miniunit header = "Loaded suite -e\nStarted\nF\nFinished in 0.035332 seconds.\n\n" input = "#{header} 1) Failure: test_blah(TestBlah) [./blah.rb:25]: Expected ['a', 'b', 'c'], not ['a', 'c', 'b']. 1 tests, 1 assertions, 1 failures, 0 errors " expected = [[[" 1) Failure:\n", "test_blah(TestBlah) [./blah.rb:25]:\n", "Expected ['a', 'b', 'c'], not ['a', 'c', 'b'].\n"]], ["\n", "1 tests, 1 assertions, 1 failures, 0 errors\n"]] util_unit_diff(header, input, expected, :parse_input) end def test_input_miniunit_multiline header = "Loaded suite -e\nStarted\nF\nFinished in 0.035332 seconds.\n\n" input = "#{header} 1) Failure: test_blah(TestBlah) [./blah.rb:25]: Expected ['a', 'b', 'c'], not ['a', 'c', 'b']. 1 tests, 1 assertions, 1 failures, 0 errors " expected = [[[" 1) Failure:\n", "test_blah(TestBlah) [./blah.rb:25]:\n", "Expected ['a',\n 'b',\n 'c'], not ['a',\n 'c',\n 'b'].\n"]], ["\n", "1 tests, 1 assertions, 1 failures, 0 errors\n"]] util_unit_diff(header, input, expected, :parse_input) end def test_input_mspec header = <<-HEADER Started .......F Finished in 0.1 seconds HEADER failure = <<-FAILURE 1) The unless expression should fail FAILED Expected nil to equal "baz": FAILURE backtrace = <<-BACKTRACE PositiveExpectation#== at spec/mspec.rb:217 main.__script__ {} at spec/language/unless_spec.rb:49 Proc#call at kernel/core/proc.rb:127 SpecRunner#it at spec/mspec.rb:368 main.it at spec/mspec.rb:412 main.__script__ {} at spec/language/unless_spec.rb:48 Proc#call at kernel/core/proc.rb:127 SpecRunner#describe at spec/mspec.rb:378 main.describe at spec/mspec.rb:408 main.__script__ at spec/language/unless_spec.rb:3 CompiledMethod#as_script at kernel/bootstrap/primitives.rb:41 main.load at kernel/core/compile.rb:150 main.__script__ {} at last_mspec.rb:11 Array#each {} at kernel/core/array.rb:545 Integer(Fixnum)#times at kernel/core/integer.rb:15 Array#each at kernel/core/array.rb:545 main.__script__ at last_mspec.rb:16 CompiledMethod#as_script at kernel/bootstrap/primitives.rb:41 main.load at kernel/core/compile.rb:150 main.__script__ at kernel/loader.rb:145 BACKTRACE footer = "\n8 examples, 1 failures\n" input = header + failure + backtrace + footer expected_backtrace = backtrace.split("\n").map {|l| "#{l}\n"} expected = [[["1)\n", "The unless expression should fail FAILED\n", "Expected nil to equal \"baz\":\n", *expected_backtrace]], ["\n", "8 examples, 1 failures\n"]] util_unit_diff(header, input, expected, :parse_input) end def test_input_mspec_multiline header = <<-HEADER Started .......F Finished in 0.1 seconds HEADER failure = <<-FAILURE 1) Compiler compiles a case without an argument FAILED Expected #], [:push_literal, "foo"], [:string_dup], [:goto, #