test-users-guide.rb 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. ###
  2. ### $Release: 2.7.0 $
  3. ### copyright(c) 2006-2011 kuwata-lab.com all rights reserved.
  4. ###
  5. require "#{File.dirname(__FILE__)}/test.rb"
  6. class KwarkUsersGuideTest < Test::Unit::TestCase
  7. DIR = File.expand_path(File.dirname(__FILE__) + '/data/users-guide')
  8. CWD = Dir.pwd()
  9. def setup
  10. Dir.chdir DIR
  11. end
  12. def teardown
  13. Dir.chdir CWD
  14. end
  15. def _test
  16. @name = (caller()[0] =~ /`(.*?)'/) && $1
  17. s = File.read(@filename)
  18. s =~ /\A\$ (.*?)\n/
  19. command = $1
  20. expected = $'
  21. if ruby19?
  22. case @name
  23. when 'test_main_program1_result'
  24. expected.sub!('["eruby", "items", "x", "_buf"]', '[:_buf, :eruby, :items, :x]')
  25. when 'test_main_program2_result'
  26. expected.sub!('["_context", "x", "_buf"]', '[:_buf, :x, :_context]')
  27. end
  28. elsif rubinius?
  29. command.sub!(/^ruby\b/, 'rbx')
  30. case @name
  31. when 'test_main_program1_result'
  32. expected.sub!('["eruby", "items", "x", "_buf"]', '["_buf", "eruby", "items", "x"]')
  33. when 'test_main_program2_result'
  34. expected.sub!('["_context", "x", "_buf"]', '["_buf", "x", "_context"]')
  35. end
  36. end
  37. result = `#{command}`
  38. assert_text_equal(expected, result)
  39. end
  40. Dir.chdir DIR do
  41. filenames = []
  42. filenames += Dir.glob('*.result')
  43. filenames += Dir.glob('*.source')
  44. filenames.each do |filename|
  45. name = filename.gsub(/[^\w]/, '_')
  46. s = <<-END
  47. def test_#{name}
  48. # $stderr.puts "*** debug: test_#{name}"
  49. @name = '#{name}'
  50. @filename = '#{filename}'
  51. _test()
  52. end
  53. END
  54. eval s
  55. end
  56. end
  57. self.post_definition()
  58. end