# Author:: Nicolas Pouillard . # Copyright:: Copyright (c) 2005 Uttk Team. All rights reserved. # License:: LGPL # $Id$ test_section __FILE__ do module Uttk module Strategies class SuiteTest < ::Test::Unit::TestCase # # Tests # def test_example output_ref = %q{ |--- |A set of tests: !S::Suite | attributes: | strategy: Uttk::Strategies::Cmd | exit: 0 | contents: | - I'm suppose to pass 1: !S::Cmd | command: 'true' | running: 'true' | status: PASS | - I'm suppose to fail 2: !S::Cmd | weight: -1 | command: 'false' | running: 'false' | my_exit: 1 | status: FAIL | reason: wrong exit value | - I'm suppose to pass 3: !S::Cmd | command: 'false' | running: 'false' | status: PASS | status: PASS |}.head_cut! output_ref2 = %q{ |A set of tests: !S::Suite | attributes: | strategy: Uttk::Strategies::Cmd | exit: 0 | contents: | - I'm suppose to pass 4: !S::Cmd | command: 'true' | running: 'true' | status: PASS | - I'm suppose to fail 5: !S::Cmd | weight: -1 | command: 'false' | running: 'false' | my_exit: 1 | status: FAIL | reason: wrong exit value | - I'm suppose to pass 6: !S::Cmd | command: 'false' | running: 'false' | status: PASS | status: PASS |}.head_cut! # Dynamically fix the reference output for ruby 1.8.2 since there is a # strange bug with Yaml and/or Dumpers::Yaml # But it's ok with ruby 1.8.3 unless HAVE_YAML_TAGURI output_ref.gsub!(/'(true|false)'/, '\1') output_ref2.gsub!(/'(true|false)'/, '\1') end TempPath.new do |tmp| log = Logger.new(Dumpers::Yaml.new(tmp.open('w'))) log.severity_level = Logger::Severity::INFO log.verbosity_level = 0 loader = Loaders::Yaml.new symtbl = SymTbl.new symtbl[:loader] = loader symtbl[:log] = log aDoc = { :name => 'A set of tests', :strategy => Strategies::Suite, :symtbl => symtbl, :wclass => Weights::WFloat, :attributes => { :strategy => Strategies::Cmd, :exit => 0 }, :contents => OHash[ "I'm suppose to pass 1", { :command => 'true' }, "I'm suppose to fail 2", { :command => 'false', :weight => -1 }, "I'm suppose to pass 3", { :command => 'false', :exit => 1 } ] } aSuite = aDoc.testify(:loader => loader) aSuite.run # mini_diff(output_ref, tmp.read) assert_nothing_raised { @my = YAML::load(tmp.read) } assert_equal(YAML::load(output_ref), @my) aSuite = Strategies::Suite.new aSuite.name = 'A set of tests' aSuite.symtbl = symtbl aSuite.wclass = Weights::WFloat aSuite.strategyclass = Strategies::Cmd aSuite.exit = 0 # a sugar when its unambiguous. t1 = aSuite.create t1.name = "I'm suppose to pass 4" t1.command = 'true' aSuite.create(:name => "I'm suppose to fail 5", :command => 'false', :weight => -1) io = StringIO.new io << "|--- |I'm suppose to pass 6: | command: 'false' | exit: 1".gsub(/^\s*\|/, '') io.rewind aSuite.create(io) aSuite.run # mini_diff(output_ref, tmp.read) assert_nothing_raised { @my = YAML::load(tmp.read) } assert_equal(YAML::load(output_ref2), @my) end end def mini_diff ( a, b ) a = a.split(/\n/) b = b.split(/\n/) d = a.zip(b).delete_if { |x, y| x == y } d.each do |x, y| puts "-#{x}" puts "+#{y}" end end end # class SuiteTest end # module Strategies end # module Uttk end