Fumitoshi Ukai | 119dc91 | 2015-03-30 16:52:41 +0900 | [diff] [blame] | 1 | #!/usr/bin/env ruby |
Shinichiro Hamaji | b69bf8a | 2015-06-10 14:52:06 +0900 | [diff] [blame] | 2 | # |
| 3 | # Copyright 2015 Google Inc. All rights reserved |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
Fumitoshi Ukai | 119dc91 | 2015-03-30 16:52:41 +0900 | [diff] [blame] | 16 | |
| 17 | require 'fileutils' |
| 18 | |
Shinichiro Hamaji | 8ac8171 | 2015-07-16 09:15:54 +0900 | [diff] [blame] | 19 | while true |
| 20 | if ARGV[0] == '-s' |
| 21 | test_serialization = true |
| 22 | ARGV.shift |
| 23 | elsif ARGV[0] == '-c' |
| 24 | ckati = true |
| 25 | ARGV.shift |
| 26 | ENV['KATI_VARIANT'] = 'c' |
| 27 | elsif ARGV[0] == '-n' |
| 28 | via_ninja = true |
| 29 | ARGV.shift |
| 30 | else |
| 31 | break |
| 32 | end |
Shinichiro Hamaji | 9f4f5d3 | 2015-04-28 03:53:49 +0900 | [diff] [blame] | 33 | end |
| 34 | |
Fumitoshi Ukai | 119dc91 | 2015-03-30 16:52:41 +0900 | [diff] [blame] | 35 | def get_output_filenames |
| 36 | files = Dir.glob('*') |
| 37 | files.delete('Makefile') |
Shinichiro Hamaji | 8ac8171 | 2015-07-16 09:15:54 +0900 | [diff] [blame] | 38 | files.delete('build.ninja') |
| 39 | files.delete('ninja.sh') |
Shinichiro Hamaji | 65489db | 2015-06-29 20:44:26 +0900 | [diff] [blame] | 40 | files.delete('gmon.out') |
Shinichiro Hamaji | b674d58 | 2015-04-28 03:40:57 +0900 | [diff] [blame] | 41 | files.reject!{|f|f =~ /\.json$/} |
Fumitoshi Ukai | 6450d0f | 2015-07-10 16:34:06 +0900 | [diff] [blame] | 42 | files.reject!{|f|f =~ /^kati\.*/} |
Fumitoshi Ukai | 119dc91 | 2015-03-30 16:52:41 +0900 | [diff] [blame] | 43 | files |
| 44 | end |
| 45 | |
| 46 | def cleanup |
Shinichiro Hamaji | a9bda7a | 2015-05-20 17:50:42 +0900 | [diff] [blame] | 47 | (get_output_filenames + Dir.glob('.*')).each do |fname| |
| 48 | next if fname == '.' || fname == '..' |
Shinichiro Hamaji | c671360 | 2015-04-01 01:03:34 +0900 | [diff] [blame] | 49 | FileUtils.rm_rf fname |
Fumitoshi Ukai | 119dc91 | 2015-03-30 16:52:41 +0900 | [diff] [blame] | 50 | end |
| 51 | end |
| 52 | |
Shinichiro Hamaji | 74a6600 | 2015-04-27 16:42:30 +0900 | [diff] [blame] | 53 | def move_circular_dep(l) |
| 54 | # We don't care when circular dependency detection happens. |
| 55 | circ = '' |
| 56 | while l.sub!(/Circular .* dropped\.\n/, '') do |
| 57 | circ += $& |
| 58 | end |
| 59 | circ + l |
| 60 | end |
| 61 | |
Shinichiro Hamaji | c671360 | 2015-04-01 01:03:34 +0900 | [diff] [blame] | 62 | expected_failures = [] |
| 63 | unexpected_passes = [] |
| 64 | failures = [] |
| 65 | passes = [] |
| 66 | |
Shinichiro Hamaji | ec42b4e | 2015-05-14 16:20:03 +0900 | [diff] [blame] | 67 | if !ARGV.empty? |
Shinichiro Hamaji | a9bda7a | 2015-05-20 17:50:42 +0900 | [diff] [blame] | 68 | test_files = ARGV.map do |test| |
| 69 | "testcase/#{File.basename(test)}" |
Shinichiro Hamaji | ec42b4e | 2015-05-14 16:20:03 +0900 | [diff] [blame] | 70 | end |
| 71 | else |
Shinichiro Hamaji | a9bda7a | 2015-05-20 17:50:42 +0900 | [diff] [blame] | 72 | test_files = Dir.glob('testcase/*.mk').sort |
| 73 | test_files += Dir.glob('testcase/*.sh').sort |
Shinichiro Hamaji | ec42b4e | 2015-05-14 16:20:03 +0900 | [diff] [blame] | 74 | end |
| 75 | |
Shinichiro Hamaji | a9bda7a | 2015-05-20 17:50:42 +0900 | [diff] [blame] | 76 | def run_in_testdir(test_filename) |
| 77 | c = File.read(test_filename) |
| 78 | name = File.basename(test_filename) |
Fumitoshi Ukai | 119dc91 | 2015-03-30 16:52:41 +0900 | [diff] [blame] | 79 | dir = "out/#{name}" |
Shinichiro Hamaji | 52e4203 | 2015-03-31 23:20:13 +0900 | [diff] [blame] | 80 | |
Fumitoshi Ukai | 119dc91 | 2015-03-30 16:52:41 +0900 | [diff] [blame] | 81 | FileUtils.mkdir_p(dir) |
Shinichiro Hamaji | 52e4203 | 2015-03-31 23:20:13 +0900 | [diff] [blame] | 82 | Dir.glob("#{dir}/*").each do |fname| |
| 83 | FileUtils.rm_rf(fname) |
| 84 | end |
Fumitoshi Ukai | 119dc91 | 2015-03-30 16:52:41 +0900 | [diff] [blame] | 85 | |
| 86 | Dir.chdir(dir) do |
Shinichiro Hamaji | a9bda7a | 2015-05-20 17:50:42 +0900 | [diff] [blame] | 87 | yield name |
| 88 | end |
| 89 | end |
| 90 | |
Shinichiro Hamaji | 86e1133 | 2015-07-28 15:24:17 +0900 | [diff] [blame] | 91 | def normalize_ninja_log(log, mk) |
Shinichiro Hamaji | 8ac8171 | 2015-07-16 09:15:54 +0900 | [diff] [blame] | 92 | log.gsub!(/^\[\d+\/\d+\] .*\n/, '') |
Shinichiro Hamaji | cecc358 | 2015-07-28 15:56:59 +0900 | [diff] [blame] | 93 | log.gsub!(/^ninja: no work to do\.\n/, '') |
Fumitoshi Ukai | 786846d | 2015-07-28 18:08:47 +0900 | [diff] [blame] | 94 | log.gsub!(/^ninja: error: (.*, needed by .*),.*/, |
| 95 | '*** No rule to make target \\1.') |
Shinichiro Hamaji | 86e1133 | 2015-07-28 15:24:17 +0900 | [diff] [blame] | 96 | if mk =~ /err_error_in_recipe.mk/ |
| 97 | # This test expects ninja fails. Strip ninja specific error logs. |
| 98 | log.gsub!(/^FAILED: .*\n/, '') |
| 99 | log.gsub!(/^ninja: .*\n/, '') |
| 100 | end |
Shinichiro Hamaji | 8ac8171 | 2015-07-16 09:15:54 +0900 | [diff] [blame] | 101 | log |
| 102 | end |
| 103 | |
Shinichiro Hamaji | a9bda7a | 2015-05-20 17:50:42 +0900 | [diff] [blame] | 104 | def normalize_make_log(expected) |
| 105 | expected.gsub!(/^make(?:\[\d+\])?: (Entering|Leaving) directory.*\n/, '') |
| 106 | expected.gsub!(/^make(?:\[\d+\])?: /, '') |
| 107 | expected = move_circular_dep(expected) |
| 108 | |
| 109 | # Normalizations for old/new GNU make. |
| 110 | expected.gsub!(/[`'"]/, '"') |
| 111 | expected.gsub!(/ (?:commands|recipe) for target /, |
| 112 | ' commands for target ') |
| 113 | expected.gsub!(/ (?:commands|recipe) commences /, |
| 114 | ' commands commence ') |
| 115 | expected.gsub!(' (did you mean TAB instead of 8 spaces?)', '') |
| 116 | expected.gsub!('Extraneous text after', 'extraneous text after') |
| 117 | # Not sure if this is useful. |
| 118 | expected.gsub!(/\s+Stop\.$/, '') |
| 119 | # GNU make 4.0 has this output. |
| 120 | expected.gsub!(/Makefile:\d+: commands for target ".*?" failed\n/, '') |
| 121 | # We treat some warnings as errors. |
| 122 | expected.gsub!(/Nothing to be done for "test"\.\n/, '') |
Shinichiro Hamaji | 3498f34 | 2015-08-11 14:23:12 +0900 | [diff] [blame] | 123 | expected.gsub!(/^\/bin\/sh: line 0: /, '') |
Shinichiro Hamaji | a9bda7a | 2015-05-20 17:50:42 +0900 | [diff] [blame] | 124 | |
| 125 | expected |
| 126 | end |
| 127 | |
| 128 | def normalize_kati_log(output) |
| 129 | output = move_circular_dep(output) |
| 130 | # kati specific log messages. |
| 131 | output.gsub!(/^\*kati\*.*\n/, '') |
Fumitoshi Ukai | a43b96f | 2015-07-17 19:54:21 +0900 | [diff] [blame] | 132 | output.gsub!(/^c?kati: /, '') |
Shinichiro Hamaji | a9bda7a | 2015-05-20 17:50:42 +0900 | [diff] [blame] | 133 | output.gsub!(/[`'"]/, '"') |
Shinichiro Hamaji | 861bd64 | 2015-06-19 16:59:13 +0900 | [diff] [blame] | 134 | output.gsub!(/(: )(?:open )?(\S+): [Nn](o such file or directory)\nNOTE:.*/, |
Shinichiro Hamaji | a9bda7a | 2015-05-20 17:50:42 +0900 | [diff] [blame] | 135 | "\\1\\2: N\\3\n*** No rule to make target \"\\2\".") |
Fumitoshi Ukai | 08c1e94 | 2015-07-15 16:38:07 +0900 | [diff] [blame] | 136 | output.gsub!(/\/bin\/sh: ([^:]*): command not found/, |
| 137 | "\\1: Command not found") |
Shinichiro Hamaji | a06bee9 | 2015-08-05 17:13:05 +0900 | [diff] [blame] | 138 | output.gsub!(/.*: warning for parse error in an unevaluated line: .*\n/, '') |
Shinichiro Hamaji | 3498f34 | 2015-08-11 14:23:12 +0900 | [diff] [blame] | 139 | output.gsub!(/^FindEmulator: /, '') |
Fumitoshi Ukai | b0ede7d | 2015-07-29 10:19:05 +0900 | [diff] [blame] | 140 | output.gsub!(/ (\.\/+)+kati\.\S+/, '') # kati log files in find_command.mk |
| 141 | output.gsub!(/ (\.\/+)+test\S+.json/, '') # json files in find_command.mk |
Shinichiro Hamaji | a9bda7a | 2015-05-20 17:50:42 +0900 | [diff] [blame] | 142 | output |
| 143 | end |
| 144 | |
| 145 | run_make_test = proc do |mk| |
| 146 | c = File.read(mk) |
Shinichiro Hamaji | 6a49292 | 2015-07-27 19:37:20 +0900 | [diff] [blame] | 147 | expected_failure = false |
Fumitoshi Ukai | bfabe63 | 2015-07-28 15:26:56 +0900 | [diff] [blame] | 148 | if c =~ /\A# TODO(?:\(([-a-z|]+)\))?/ |
Shinichiro Hamaji | 6a49292 | 2015-07-27 19:37:20 +0900 | [diff] [blame] | 149 | if $1 |
| 150 | todos = $1.split('|') |
| 151 | if todos.include?('go') && !ckati |
| 152 | expected_failure = true |
| 153 | end |
| 154 | if todos.include?('c') && ckati |
| 155 | expected_failure = true |
| 156 | end |
Fumitoshi Ukai | bfabe63 | 2015-07-28 15:26:56 +0900 | [diff] [blame] | 157 | if todos.include?('go-ninja') && !ckati && via_ninja |
| 158 | expected_failure = true |
| 159 | end |
| 160 | if todos.include?('c-ninja') && ckati && via_ninja |
| 161 | expected_failure = true |
| 162 | end |
Shinichiro Hamaji | 6a49292 | 2015-07-27 19:37:20 +0900 | [diff] [blame] | 163 | if todos.include?('ninja') && via_ninja |
| 164 | expected_failure = true |
| 165 | end |
| 166 | else |
| 167 | expected_failure = true |
Shinichiro Hamaji | e919d00 | 2015-06-26 01:15:55 +0900 | [diff] [blame] | 168 | end |
| 169 | end |
Shinichiro Hamaji | a9bda7a | 2015-05-20 17:50:42 +0900 | [diff] [blame] | 170 | |
| 171 | run_in_testdir(mk) do |name| |
Shinichiro Hamaji | 776ca30 | 2015-06-06 03:52:48 +0900 | [diff] [blame] | 172 | # TODO: Fix |
| 173 | if name =~ /eval_assign/ && ckati |
| 174 | next |
| 175 | end |
| 176 | |
Fumitoshi Ukai | 119dc91 | 2015-03-30 16:52:41 +0900 | [diff] [blame] | 177 | File.open("Makefile", 'w') do |ofile| |
| 178 | ofile.print(c) |
| 179 | end |
| 180 | |
| 181 | expected = '' |
| 182 | output = '' |
| 183 | |
Shinichiro Hamaji | 491e73f | 2015-04-07 12:41:59 +0900 | [diff] [blame] | 184 | testcases = c.scan(/^test\d*/).sort.uniq |
Shinichiro Hamaji | 497754d | 2015-03-31 02:02:11 +0900 | [diff] [blame] | 185 | if testcases.empty? |
| 186 | testcases = [''] |
| 187 | end |
Shinichiro Hamaji | e5be014 | 2015-03-30 19:26:01 +0900 | [diff] [blame] | 188 | |
| 189 | cleanup |
| 190 | testcases.each do |tc| |
Shinichiro Hamaji | 8ac8171 | 2015-07-16 09:15:54 +0900 | [diff] [blame] | 191 | cmd = 'make' |
| 192 | if via_ninja |
| 193 | cmd += ' -s' |
| 194 | end |
| 195 | cmd += " #{tc} 2>&1" |
| 196 | res = `#{cmd}` |
Shinichiro Hamaji | a9bda7a | 2015-05-20 17:50:42 +0900 | [diff] [blame] | 197 | res = normalize_make_log(res) |
Shinichiro Hamaji | 74a6600 | 2015-04-27 16:42:30 +0900 | [diff] [blame] | 198 | expected += "=== #{tc} ===\n" + res |
Fumitoshi Ukai | 119dc91 | 2015-03-30 16:52:41 +0900 | [diff] [blame] | 199 | expected_files = get_output_filenames |
Fumitoshi Ukai | 119dc91 | 2015-03-30 16:52:41 +0900 | [diff] [blame] | 200 | expected += "\n=== FILES ===\n#{expected_files * "\n"}\n" |
Shinichiro Hamaji | e5be014 | 2015-03-30 19:26:01 +0900 | [diff] [blame] | 201 | end |
| 202 | |
| 203 | cleanup |
| 204 | testcases.each do |tc| |
Shinichiro Hamaji | c48d9ce | 2015-04-28 03:47:39 +0900 | [diff] [blame] | 205 | json = "#{tc.empty? ? 'test' : tc}" |
Fumitoshi Ukai | 0547db6 | 2015-07-29 16:20:59 +0900 | [diff] [blame] | 206 | cmd = "../../kati -save_json=#{json}.json -log_dir=. --use_find_emulator" |
Shinichiro Hamaji | 776ca30 | 2015-06-06 03:52:48 +0900 | [diff] [blame] | 207 | if ckati |
Shinichiro Hamaji | 8ac8171 | 2015-07-16 09:15:54 +0900 | [diff] [blame] | 208 | cmd = "../../ckati --use_find_emulator" |
Shinichiro Hamaji | 776ca30 | 2015-06-06 03:52:48 +0900 | [diff] [blame] | 209 | end |
Shinichiro Hamaji | 8ac8171 | 2015-07-16 09:15:54 +0900 | [diff] [blame] | 210 | if via_ninja |
| 211 | cmd += ' --ninja' |
| 212 | end |
| 213 | cmd += " #{tc} 2>&1" |
Shinichiro Hamaji | b674d58 | 2015-04-28 03:40:57 +0900 | [diff] [blame] | 214 | res = IO.popen(cmd, 'r:binary', &:read) |
Fumitoshi Ukai | 39837dd | 2015-07-28 12:25:56 +0900 | [diff] [blame] | 215 | if via_ninja && File.exist?('build.ninja') && File.exists?('ninja.sh') |
Shinichiro Hamaji | 6a49292 | 2015-07-27 19:37:20 +0900 | [diff] [blame] | 216 | log = IO.popen('./ninja.sh -j1 -v 2>&1', 'r:binary', &:read) |
Shinichiro Hamaji | 86e1133 | 2015-07-28 15:24:17 +0900 | [diff] [blame] | 217 | res += normalize_ninja_log(log, mk) |
Shinichiro Hamaji | 8ac8171 | 2015-07-16 09:15:54 +0900 | [diff] [blame] | 218 | end |
Shinichiro Hamaji | a9bda7a | 2015-05-20 17:50:42 +0900 | [diff] [blame] | 219 | res = normalize_kati_log(res) |
Shinichiro Hamaji | 42f42e1 | 2015-04-13 14:26:45 +0900 | [diff] [blame] | 220 | output += "=== #{tc} ===\n" + res |
Shinichiro Hamaji | e5be014 | 2015-03-30 19:26:01 +0900 | [diff] [blame] | 221 | output_files = get_output_filenames |
Fumitoshi Ukai | 119dc91 | 2015-03-30 16:52:41 +0900 | [diff] [blame] | 222 | output += "\n=== FILES ===\n#{output_files * "\n"}\n" |
| 223 | end |
| 224 | |
| 225 | File.open('out.make', 'w'){|ofile|ofile.print(expected)} |
| 226 | File.open('out.kati', 'w'){|ofile|ofile.print(output)} |
| 227 | |
Shinichiro Hamaji | 74c832f | 2015-04-09 14:54:39 +0900 | [diff] [blame] | 228 | if expected =~ /FAIL/ |
| 229 | puts %Q(#{name} has a string "FAIL" in its expectation) |
| 230 | exit 1 |
| 231 | end |
| 232 | |
Fumitoshi Ukai | 119dc91 | 2015-03-30 16:52:41 +0900 | [diff] [blame] | 233 | if expected != output |
Shinichiro Hamaji | 91b105c | 2015-03-30 18:39:05 +0900 | [diff] [blame] | 234 | if expected_failure |
| 235 | puts "#{name}: FAIL (expected)" |
Shinichiro Hamaji | c671360 | 2015-04-01 01:03:34 +0900 | [diff] [blame] | 236 | expected_failures << name |
Shinichiro Hamaji | 91b105c | 2015-03-30 18:39:05 +0900 | [diff] [blame] | 237 | else |
| 238 | puts "#{name}: FAIL" |
| 239 | puts `diff -u out.make out.kati` |
Shinichiro Hamaji | c671360 | 2015-04-01 01:03:34 +0900 | [diff] [blame] | 240 | failures << name |
Shinichiro Hamaji | 91b105c | 2015-03-30 18:39:05 +0900 | [diff] [blame] | 241 | end |
Fumitoshi Ukai | 119dc91 | 2015-03-30 16:52:41 +0900 | [diff] [blame] | 242 | else |
Shinichiro Hamaji | 91b105c | 2015-03-30 18:39:05 +0900 | [diff] [blame] | 243 | if expected_failure |
| 244 | puts "#{name}: PASS (unexpected)" |
Shinichiro Hamaji | c671360 | 2015-04-01 01:03:34 +0900 | [diff] [blame] | 245 | unexpected_passes << name |
Shinichiro Hamaji | 91b105c | 2015-03-30 18:39:05 +0900 | [diff] [blame] | 246 | else |
| 247 | puts "#{name}: PASS" |
Shinichiro Hamaji | c671360 | 2015-04-01 01:03:34 +0900 | [diff] [blame] | 248 | passes << name |
Shinichiro Hamaji | 91b105c | 2015-03-30 18:39:05 +0900 | [diff] [blame] | 249 | end |
Fumitoshi Ukai | 119dc91 | 2015-03-30 16:52:41 +0900 | [diff] [blame] | 250 | end |
Shinichiro Hamaji | c48d9ce | 2015-04-28 03:47:39 +0900 | [diff] [blame] | 251 | |
Shinichiro Hamaji | e666ac8 | 2015-04-28 04:18:13 +0900 | [diff] [blame] | 252 | if name !~ /^err_/ && test_serialization && !expected_failure |
Shinichiro Hamaji | c48d9ce | 2015-04-28 03:47:39 +0900 | [diff] [blame] | 253 | testcases.each do |tc| |
| 254 | json = "#{tc.empty? ? 'test' : tc}" |
Fumitoshi Ukai | 6450d0f | 2015-07-10 16:34:06 +0900 | [diff] [blame] | 255 | cmd = "../../kati -save_json=#{json}_2.json -load_json=#{json}.json -n -log_dir=. #{tc} 2>&1" |
Shinichiro Hamaji | c48d9ce | 2015-04-28 03:47:39 +0900 | [diff] [blame] | 256 | res = IO.popen(cmd, 'r:binary', &:read) |
| 257 | if !File.exist?("#{json}.json") || !File.exist?("#{json}_2.json") |
| 258 | puts "#{name}##{json}: Serialize failure (not exist)" |
Shinichiro Hamaji | 9f4f5d3 | 2015-04-28 03:53:49 +0900 | [diff] [blame] | 259 | puts res |
Shinichiro Hamaji | c48d9ce | 2015-04-28 03:47:39 +0900 | [diff] [blame] | 260 | else |
| 261 | json1 = File.read("#{json}.json") |
| 262 | json2 = File.read("#{json}_2.json") |
| 263 | if json1 != json2 |
| 264 | puts "#{name}##{json}: Serialize failure" |
Shinichiro Hamaji | 9f4f5d3 | 2015-04-28 03:53:49 +0900 | [diff] [blame] | 265 | puts res |
Shinichiro Hamaji | c48d9ce | 2015-04-28 03:47:39 +0900 | [diff] [blame] | 266 | end |
| 267 | end |
| 268 | end |
| 269 | end |
Fumitoshi Ukai | 119dc91 | 2015-03-30 16:52:41 +0900 | [diff] [blame] | 270 | end |
| 271 | end |
Shinichiro Hamaji | c671360 | 2015-04-01 01:03:34 +0900 | [diff] [blame] | 272 | |
Shinichiro Hamaji | a9bda7a | 2015-05-20 17:50:42 +0900 | [diff] [blame] | 273 | run_shell_test = proc do |sh| |
Shinichiro Hamaji | 09796ef | 2015-07-30 17:08:29 +0900 | [diff] [blame] | 274 | is_ninja_test = sh =~ /\/ninja_/ |
| 275 | if is_ninja_test && (!ckati || !via_ninja) |
| 276 | next |
| 277 | end |
| 278 | |
Shinichiro Hamaji | a9bda7a | 2015-05-20 17:50:42 +0900 | [diff] [blame] | 279 | run_in_testdir(sh) do |name| |
| 280 | cleanup |
| 281 | cmd = "sh ../../#{sh} make" |
Shinichiro Hamaji | 09796ef | 2015-07-30 17:08:29 +0900 | [diff] [blame] | 282 | if is_ninja_test |
| 283 | cmd += ' -s' |
| 284 | end |
Shinichiro Hamaji | a9bda7a | 2015-05-20 17:50:42 +0900 | [diff] [blame] | 285 | expected = IO.popen(cmd, 'r:binary', &:read) |
| 286 | cleanup |
Shinichiro Hamaji | 09796ef | 2015-07-30 17:08:29 +0900 | [diff] [blame] | 287 | |
| 288 | if is_ninja_test |
| 289 | if ckati |
Shinichiro Hamaji | a88c1c2 | 2015-07-31 12:29:48 +0900 | [diff] [blame] | 290 | cmd = "sh ../../#{sh} ../../ckati --ninja --regen" |
Shinichiro Hamaji | 09796ef | 2015-07-30 17:08:29 +0900 | [diff] [blame] | 291 | else |
| 292 | next |
| 293 | end |
| 294 | else |
| 295 | if ckati |
| 296 | cmd = "sh ../../#{sh} ../../ckati" |
| 297 | else |
| 298 | cmd = "sh ../../#{sh} ../../kati --use_cache -log_dir=." |
| 299 | end |
| 300 | end |
| 301 | |
Shinichiro Hamaji | a9bda7a | 2015-05-20 17:50:42 +0900 | [diff] [blame] | 302 | output = IO.popen(cmd, 'r:binary', &:read) |
| 303 | |
| 304 | expected = normalize_make_log(expected) |
| 305 | output = normalize_kati_log(output) |
Shinichiro Hamaji | 09796ef | 2015-07-30 17:08:29 +0900 | [diff] [blame] | 306 | if is_ninja_test |
| 307 | output = normalize_ninja_log(output, sh) |
Shinichiro Hamaji | 5995660 | 2015-08-11 15:35:55 +0900 | [diff] [blame^] | 308 | output.gsub!(/No need to regenerate ninja file\n/, '') |
Shinichiro Hamaji | 09796ef | 2015-07-30 17:08:29 +0900 | [diff] [blame] | 309 | end |
Shinichiro Hamaji | a9bda7a | 2015-05-20 17:50:42 +0900 | [diff] [blame] | 310 | File.open('out.make', 'w'){|ofile|ofile.print(expected)} |
| 311 | File.open('out.kati', 'w'){|ofile|ofile.print(output)} |
| 312 | |
| 313 | if expected != output |
| 314 | puts "#{name}: FAIL" |
Shinichiro Hamaji | 39e6240 | 2015-05-20 19:34:58 +0900 | [diff] [blame] | 315 | puts `diff -u out.make out.kati` |
Shinichiro Hamaji | a9bda7a | 2015-05-20 17:50:42 +0900 | [diff] [blame] | 316 | failures << name |
| 317 | else |
| 318 | puts "#{name}: PASS" |
| 319 | passes << name |
| 320 | end |
| 321 | end |
| 322 | end |
| 323 | |
| 324 | test_files.each do |test| |
| 325 | if /\.mk$/ =~ test |
| 326 | run_make_test.call(test) |
| 327 | elsif /\.sh$/ =~ test |
| 328 | run_shell_test.call(test) |
| 329 | else |
| 330 | raise "Unknown test type: #{test}" |
| 331 | end |
| 332 | end |
| 333 | |
Shinichiro Hamaji | c671360 | 2015-04-01 01:03:34 +0900 | [diff] [blame] | 334 | puts |
| 335 | |
| 336 | if !expected_failures.empty? |
| 337 | puts "=== Expected failures ===" |
| 338 | expected_failures.each do |n| |
| 339 | puts n |
| 340 | end |
| 341 | end |
| 342 | |
| 343 | if !unexpected_passes.empty? |
| 344 | puts "=== Unexpected passes ===" |
| 345 | unexpected_passes.each do |n| |
| 346 | puts n |
| 347 | end |
| 348 | end |
| 349 | |
| 350 | if !failures.empty? |
| 351 | puts "=== Failures ===" |
| 352 | failures.each do |n| |
| 353 | puts n |
| 354 | end |
| 355 | end |
| 356 | |
| 357 | puts |
| 358 | |
| 359 | if !unexpected_passes.empty? || !failures.empty? |
Shinichiro Hamaji | 776ca30 | 2015-06-06 03:52:48 +0900 | [diff] [blame] | 360 | puts "FAIL! (#{failures.size + unexpected_passes.size} fails #{passes.size} passes)" |
Shinichiro Hamaji | c671360 | 2015-04-01 01:03:34 +0900 | [diff] [blame] | 361 | else |
| 362 | puts 'PASS!' |
| 363 | end |