Fumitoshi Ukai | 119dc91 | 2015-03-30 16:52:41 +0900 | [diff] [blame] | 1 | #!/usr/bin/env ruby |
| 2 | |
| 3 | require 'fileutils' |
| 4 | |
| 5 | def get_output_filenames |
| 6 | files = Dir.glob('*') |
| 7 | files.delete('Makefile') |
| 8 | files |
| 9 | end |
| 10 | |
| 11 | def cleanup |
| 12 | get_output_filenames.each do |fname| |
Shinichiro Hamaji | c671360 | 2015-04-01 01:03:34 +0900 | [diff] [blame^] | 13 | FileUtils.rm_rf fname |
Fumitoshi Ukai | 119dc91 | 2015-03-30 16:52:41 +0900 | [diff] [blame] | 14 | end |
| 15 | end |
| 16 | |
Shinichiro Hamaji | c671360 | 2015-04-01 01:03:34 +0900 | [diff] [blame^] | 17 | expected_failures = [] |
| 18 | unexpected_passes = [] |
| 19 | failures = [] |
| 20 | passes = [] |
| 21 | |
Fumitoshi Ukai | 119dc91 | 2015-03-30 16:52:41 +0900 | [diff] [blame] | 22 | Dir.glob('test/*.mk').sort.each do |mk| |
| 23 | c = File.read(mk) |
| 24 | |
Shinichiro Hamaji | 91b105c | 2015-03-30 18:39:05 +0900 | [diff] [blame] | 25 | expected_failure = c =~ /\A# TODO/ |
| 26 | |
Fumitoshi Ukai | 119dc91 | 2015-03-30 16:52:41 +0900 | [diff] [blame] | 27 | name = mk[/([^\/]+)\.mk$/, 1] |
| 28 | dir = "out/#{name}" |
Shinichiro Hamaji | 52e4203 | 2015-03-31 23:20:13 +0900 | [diff] [blame] | 29 | |
Fumitoshi Ukai | 119dc91 | 2015-03-30 16:52:41 +0900 | [diff] [blame] | 30 | FileUtils.mkdir_p(dir) |
Shinichiro Hamaji | 52e4203 | 2015-03-31 23:20:13 +0900 | [diff] [blame] | 31 | Dir.glob("#{dir}/*").each do |fname| |
| 32 | FileUtils.rm_rf(fname) |
| 33 | end |
Fumitoshi Ukai | 119dc91 | 2015-03-30 16:52:41 +0900 | [diff] [blame] | 34 | |
| 35 | Dir.chdir(dir) do |
| 36 | File.open("Makefile", 'w') do |ofile| |
| 37 | ofile.print(c) |
| 38 | end |
| 39 | |
| 40 | expected = '' |
| 41 | output = '' |
| 42 | |
Shinichiro Hamaji | e5be014 | 2015-03-30 19:26:01 +0900 | [diff] [blame] | 43 | testcases = c.scan(/^test\d*/).sort |
Shinichiro Hamaji | 497754d | 2015-03-31 02:02:11 +0900 | [diff] [blame] | 44 | if testcases.empty? |
| 45 | testcases = [''] |
| 46 | end |
Shinichiro Hamaji | e5be014 | 2015-03-30 19:26:01 +0900 | [diff] [blame] | 47 | |
| 48 | cleanup |
| 49 | testcases.each do |tc| |
| 50 | expected += "=== #{tc} ===\n" + `make #{tc} 2>&1` |
Fumitoshi Ukai | 119dc91 | 2015-03-30 16:52:41 +0900 | [diff] [blame] | 51 | expected_files = get_output_filenames |
Fumitoshi Ukai | 119dc91 | 2015-03-30 16:52:41 +0900 | [diff] [blame] | 52 | expected += "\n=== FILES ===\n#{expected_files * "\n"}\n" |
Shinichiro Hamaji | e5be014 | 2015-03-30 19:26:01 +0900 | [diff] [blame] | 53 | end |
| 54 | |
| 55 | cleanup |
| 56 | testcases.each do |tc| |
| 57 | output += "=== #{tc} ===\n" + `../../kati #{tc} 2>&1` |
| 58 | output_files = get_output_filenames |
Fumitoshi Ukai | 119dc91 | 2015-03-30 16:52:41 +0900 | [diff] [blame] | 59 | output += "\n=== FILES ===\n#{output_files * "\n"}\n" |
| 60 | end |
| 61 | |
Shinichiro Hamaji | e5be014 | 2015-03-30 19:26:01 +0900 | [diff] [blame] | 62 | expected.gsub!(/^make\[.*\n/, '') |
Shinichiro Hamaji | 5971b4b | 2015-03-31 00:37:11 +0900 | [diff] [blame] | 63 | # Normalizations for old/new GNU make. |
| 64 | expected.gsub!(/[`'"]/, '"') |
| 65 | expected.gsub!(/ (?:commands|recipe) for target /, |
| 66 | ' commands for target ') |
Shinichiro Hamaji | fed074e | 2015-03-31 21:51:43 +0900 | [diff] [blame] | 67 | expected.gsub!(/ (?:commands|recipe) commences /, |
| 68 | ' commands commence ') |
Shinichiro Hamaji | 0ec0770 | 2015-03-31 00:50:32 +0900 | [diff] [blame] | 69 | expected.gsub!(' (did you mean TAB instead of 8 spaces?)', '') |
| 70 | expected.gsub!(/\s+Stop\.$/, '') |
Shinichiro Hamaji | e5be014 | 2015-03-30 19:26:01 +0900 | [diff] [blame] | 71 | output.gsub!(/^\*kati\*.*\n/, '') |
| 72 | |
Fumitoshi Ukai | 119dc91 | 2015-03-30 16:52:41 +0900 | [diff] [blame] | 73 | File.open('out.make', 'w'){|ofile|ofile.print(expected)} |
| 74 | File.open('out.kati', 'w'){|ofile|ofile.print(output)} |
| 75 | |
| 76 | if expected != output |
Shinichiro Hamaji | 91b105c | 2015-03-30 18:39:05 +0900 | [diff] [blame] | 77 | if expected_failure |
| 78 | puts "#{name}: FAIL (expected)" |
Shinichiro Hamaji | c671360 | 2015-04-01 01:03:34 +0900 | [diff] [blame^] | 79 | expected_failures << name |
Shinichiro Hamaji | 91b105c | 2015-03-30 18:39:05 +0900 | [diff] [blame] | 80 | else |
| 81 | puts "#{name}: FAIL" |
| 82 | puts `diff -u out.make out.kati` |
Shinichiro Hamaji | c671360 | 2015-04-01 01:03:34 +0900 | [diff] [blame^] | 83 | failures << name |
Shinichiro Hamaji | 91b105c | 2015-03-30 18:39:05 +0900 | [diff] [blame] | 84 | end |
Fumitoshi Ukai | 119dc91 | 2015-03-30 16:52:41 +0900 | [diff] [blame] | 85 | else |
Shinichiro Hamaji | 91b105c | 2015-03-30 18:39:05 +0900 | [diff] [blame] | 86 | if expected_failure |
| 87 | puts "#{name}: PASS (unexpected)" |
Shinichiro Hamaji | c671360 | 2015-04-01 01:03:34 +0900 | [diff] [blame^] | 88 | unexpected_passes << name |
Shinichiro Hamaji | 91b105c | 2015-03-30 18:39:05 +0900 | [diff] [blame] | 89 | else |
| 90 | puts "#{name}: PASS" |
Shinichiro Hamaji | c671360 | 2015-04-01 01:03:34 +0900 | [diff] [blame^] | 91 | passes << name |
Shinichiro Hamaji | 91b105c | 2015-03-30 18:39:05 +0900 | [diff] [blame] | 92 | end |
Fumitoshi Ukai | 119dc91 | 2015-03-30 16:52:41 +0900 | [diff] [blame] | 93 | end |
| 94 | end |
| 95 | end |
Shinichiro Hamaji | c671360 | 2015-04-01 01:03:34 +0900 | [diff] [blame^] | 96 | |
| 97 | puts |
| 98 | |
| 99 | if !expected_failures.empty? |
| 100 | puts "=== Expected failures ===" |
| 101 | expected_failures.each do |n| |
| 102 | puts n |
| 103 | end |
| 104 | end |
| 105 | |
| 106 | if !unexpected_passes.empty? |
| 107 | puts "=== Unexpected passes ===" |
| 108 | unexpected_passes.each do |n| |
| 109 | puts n |
| 110 | end |
| 111 | end |
| 112 | |
| 113 | if !failures.empty? |
| 114 | puts "=== Failures ===" |
| 115 | failures.each do |n| |
| 116 | puts n |
| 117 | end |
| 118 | end |
| 119 | |
| 120 | puts |
| 121 | |
| 122 | if !unexpected_passes.empty? || !failures.empty? |
| 123 | puts 'FAIL!' |
| 124 | else |
| 125 | puts 'PASS!' |
| 126 | end |