blob: 7bc552da0054017ad4a3601b9f0eab176dbe2e9b [file] [log] [blame]
Fumitoshi Ukai119dc912015-03-30 16:52:41 +09001#!/usr/bin/env ruby
Shinichiro Hamaji913eb742016-04-28 17:31:24 +09002# coding: binary
Shinichiro Hamajib69bf8a2015-06-10 14:52:06 +09003#
4# Copyright 2015 Google Inc. All rights reserved
5#
6# Licensed under the Apache License, Version 2.0 (the "License");
7# you may not use this file except in compliance with the License.
8# You may obtain a copy of the License at
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS,
14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15# See the License for the specific language governing permissions and
16# limitations under the License.
Fumitoshi Ukai119dc912015-03-30 16:52:41 +090017
18require 'fileutils'
19
Stefan Beckere4e56f32016-04-27 11:16:39 +030020# suppress GNU make jobserver magic when calling "make"
21ENV.delete('MAKEFLAGS')
22ENV.delete('MAKELEVEL')
23
Shinichiro Hamaji8ac81712015-07-16 09:15:54 +090024while true
25 if ARGV[0] == '-s'
26 test_serialization = true
27 ARGV.shift
28 elsif ARGV[0] == '-c'
29 ckati = true
30 ARGV.shift
31 ENV['KATI_VARIANT'] = 'c'
32 elsif ARGV[0] == '-n'
33 via_ninja = true
34 ARGV.shift
Colin Crossdf110442015-10-02 11:06:49 -070035 ENV['NINJA_STATUS'] = 'NINJACMD: '
Shinichiro Hamaji85620572015-10-03 11:25:15 +090036 elsif ARGV[0] == '-a'
37 gen_all_targets = true
38 ARGV.shift
Shinichiro Hamaji221a16b2015-09-10 12:40:14 +090039 elsif ARGV[0] == '-v'
40 show_failing = true
41 ARGV.shift
Shinichiro Hamaji8ac81712015-07-16 09:15:54 +090042 else
43 break
44 end
Shinichiro Hamaji9f4f5d32015-04-28 03:53:49 +090045end
46
Fumitoshi Ukai119dc912015-03-30 16:52:41 +090047def get_output_filenames
48 files = Dir.glob('*')
49 files.delete('Makefile')
Shinichiro Hamaji8ac81712015-07-16 09:15:54 +090050 files.delete('build.ninja')
Colin Cross27df5312015-11-09 13:39:14 -080051 files.delete('env.sh')
Shinichiro Hamaji8ac81712015-07-16 09:15:54 +090052 files.delete('ninja.sh')
Shinichiro Hamaji65489db2015-06-29 20:44:26 +090053 files.delete('gmon.out')
Shinichiro Hamaji91571ac2015-09-07 18:24:00 +090054 files.delete('submake')
Shinichiro Hamajib674d582015-04-28 03:40:57 +090055 files.reject!{|f|f =~ /\.json$/}
Fumitoshi Ukai6450d0f2015-07-10 16:34:06 +090056 files.reject!{|f|f =~ /^kati\.*/}
Fumitoshi Ukai119dc912015-03-30 16:52:41 +090057 files
58end
59
60def cleanup
Shinichiro Hamajia9bda7a2015-05-20 17:50:42 +090061 (get_output_filenames + Dir.glob('.*')).each do |fname|
62 next if fname == '.' || fname == '..'
Shinichiro Hamajic6713602015-04-01 01:03:34 +090063 FileUtils.rm_rf fname
Fumitoshi Ukai119dc912015-03-30 16:52:41 +090064 end
65end
66
Shinichiro Hamaji74a66002015-04-27 16:42:30 +090067def move_circular_dep(l)
68 # We don't care when circular dependency detection happens.
69 circ = ''
70 while l.sub!(/Circular .* dropped\.\n/, '') do
71 circ += $&
72 end
73 circ + l
74end
75
Shinichiro Hamajic6713602015-04-01 01:03:34 +090076expected_failures = []
77unexpected_passes = []
78failures = []
79passes = []
80
Shinichiro Hamajiec42b4e2015-05-14 16:20:03 +090081if !ARGV.empty?
Shinichiro Hamajia9bda7a2015-05-20 17:50:42 +090082 test_files = ARGV.map do |test|
83 "testcase/#{File.basename(test)}"
Shinichiro Hamajiec42b4e2015-05-14 16:20:03 +090084 end
85else
Shinichiro Hamajia9bda7a2015-05-20 17:50:42 +090086 test_files = Dir.glob('testcase/*.mk').sort
87 test_files += Dir.glob('testcase/*.sh').sort
Shinichiro Hamajiec42b4e2015-05-14 16:20:03 +090088end
89
Shinichiro Hamajia9bda7a2015-05-20 17:50:42 +090090def run_in_testdir(test_filename)
91 c = File.read(test_filename)
92 name = File.basename(test_filename)
Fumitoshi Ukai119dc912015-03-30 16:52:41 +090093 dir = "out/#{name}"
Shinichiro Hamaji52e42032015-03-31 23:20:13 +090094
Fumitoshi Ukai119dc912015-03-30 16:52:41 +090095 FileUtils.mkdir_p(dir)
Shinichiro Hamaji52e42032015-03-31 23:20:13 +090096 Dir.glob("#{dir}/*").each do |fname|
97 FileUtils.rm_rf(fname)
98 end
Fumitoshi Ukai119dc912015-03-30 16:52:41 +090099
100 Dir.chdir(dir) do
Shinichiro Hamajia9bda7a2015-05-20 17:50:42 +0900101 yield name
102 end
103end
104
Shinichiro Hamaji86e11332015-07-28 15:24:17 +0900105def normalize_ninja_log(log, mk)
Colin Crossdf110442015-10-02 11:06:49 -0700106 log.gsub!(/^NINJACMD: .*\n/, '')
Shinichiro Hamajicecc3582015-07-28 15:56:59 +0900107 log.gsub!(/^ninja: no work to do\.\n/, '')
Fumitoshi Ukai786846d2015-07-28 18:08:47 +0900108 log.gsub!(/^ninja: error: (.*, needed by .*),.*/,
109 '*** No rule to make target \\1.')
Dan Willemsenf3a4ced2015-08-25 14:22:35 -0700110 log.gsub!(/^ninja: warning: multiple rules generate (.*)\. builds involving this target will not be correct.*$/,
Shinichiro Hamaji3c60c122015-10-05 16:26:38 +0900111 'ninja: warning: multiple rules generate \\1.')
Shinichiro Hamaji38892d82016-05-09 18:51:35 +0900112
Shinichiro Hamaji86e11332015-07-28 15:24:17 +0900113 if mk =~ /err_error_in_recipe.mk/
114 # This test expects ninja fails. Strip ninja specific error logs.
Shinichiro Hamaji38892d82016-05-09 18:51:35 +0900115 ninja_failed_subst = ''
Shinichiro Hamajic3a48342016-03-15 08:27:43 +0900116 elsif mk =~ /\/fail_/
117 # Recipes in these tests fail.
Shinichiro Hamaji38892d82016-05-09 18:51:35 +0900118 ninja_failed_subst = "*** [test] Error 1\n"
119 end
120 if ninja_failed_subst
121 log.gsub!(/^FAILED: (.*\n\/bin\/bash)?.*\n/, ninja_failed_subst)
Shinichiro Hamajic3a48342016-03-15 08:27:43 +0900122 log.gsub!(/^ninja: .*\n/, '')
Shinichiro Hamaji86e11332015-07-28 15:24:17 +0900123 end
Shinichiro Hamaji8ac81712015-07-16 09:15:54 +0900124 log
125end
126
Shinichiro Hamaji913eb742016-04-28 17:31:24 +0900127def normalize_quotes(log)
128 log.gsub!(/[`'"]/, '"')
129 # For recent GNU find, which uses Unicode characters.
130 log.gsub!(/(\xe2\x80\x98|\xe2\x80\x99)/, '"')
131 log
132end
133
Dan Willemsenf3a4ced2015-08-25 14:22:35 -0700134def normalize_make_log(expected, mk, via_ninja)
Shinichiro Hamaji913eb742016-04-28 17:31:24 +0900135 expected = normalize_quotes(expected)
Shinichiro Hamajia9bda7a2015-05-20 17:50:42 +0900136 expected.gsub!(/^make(?:\[\d+\])?: (Entering|Leaving) directory.*\n/, '')
137 expected.gsub!(/^make(?:\[\d+\])?: /, '')
138 expected = move_circular_dep(expected)
139
140 # Normalizations for old/new GNU make.
Shinichiro Hamajidc258cb2016-04-27 18:35:57 +0900141 expected.gsub!(' recipe for target ', ' commands for target ')
142 expected.gsub!(' recipe commences ', ' commands commence ')
143 expected.gsub!('missing rule before recipe.', 'missing rule before commands.')
Shinichiro Hamajia9bda7a2015-05-20 17:50:42 +0900144 expected.gsub!(' (did you mean TAB instead of 8 spaces?)', '')
145 expected.gsub!('Extraneous text after', 'extraneous text after')
146 # Not sure if this is useful.
147 expected.gsub!(/\s+Stop\.$/, '')
148 # GNU make 4.0 has this output.
149 expected.gsub!(/Makefile:\d+: commands for target ".*?" failed\n/, '')
150 # We treat some warnings as errors.
Shinichiro Hamaji2d2ed952016-04-28 16:50:46 +0900151 expected.gsub!(/^\/bin\/(ba)?sh: line 0: /, '')
Dan Willemsenf3a4ced2015-08-25 14:22:35 -0700152 # We print out some ninja warnings in some tests to match what we expect
153 # ninja to produce. Remove them if we're not testing ninja.
154 if !via_ninja
155 expected.gsub!(/^ninja: warning: .*\n/, '')
156 end
Shinichiro Hamajib7be8f12015-10-05 16:29:58 +0900157 # Normalization for "include foo" with C++ kati.
158 expected.gsub!(/(: )(\S+): (No such file or directory)\n\*\*\* No rule to make target "\2"./, '\1\2: \3')
Shinichiro Hamajia9bda7a2015-05-20 17:50:42 +0900159
160 expected
161end
162
163def normalize_kati_log(output)
Shinichiro Hamaji913eb742016-04-28 17:31:24 +0900164 output = normalize_quotes(output)
Shinichiro Hamajia9bda7a2015-05-20 17:50:42 +0900165 output = move_circular_dep(output)
Shinichiro Hamaji913eb742016-04-28 17:31:24 +0900166
Shinichiro Hamajia9bda7a2015-05-20 17:50:42 +0900167 # kati specific log messages.
168 output.gsub!(/^\*kati\*.*\n/, '')
Fumitoshi Ukaia43b96f2015-07-17 19:54:21 +0900169 output.gsub!(/^c?kati: /, '')
Fumitoshi Ukai08c1e942015-07-15 16:38:07 +0900170 output.gsub!(/\/bin\/sh: ([^:]*): command not found/,
171 "\\1: Command not found")
Shinichiro Hamajia06bee92015-08-05 17:13:05 +0900172 output.gsub!(/.*: warning for parse error in an unevaluated line: .*\n/, '')
Dan Willemsene41c7552017-02-22 14:31:16 -0800173 output.gsub!(/^([^ ]+: )?FindEmulator: /, '')
Fumitoshi Ukai2c6eff62015-08-11 17:50:56 +0900174 output.gsub!(/^\/bin\/sh: line 0: /, '')
Fumitoshi Ukaib0ede7d2015-07-29 10:19:05 +0900175 output.gsub!(/ (\.\/+)+kati\.\S+/, '') # kati log files in find_command.mk
176 output.gsub!(/ (\.\/+)+test\S+.json/, '') # json files in find_command.mk
Shinichiro Hamajib7be8f12015-10-05 16:29:58 +0900177 # Normalization for "include foo" with Go kati.
178 output.gsub!(/(: )open (\S+): n(o such file or directory)\nNOTE:.*/,
179 "\\1\\2: N\\3")
Dan Willemsene6ede252017-09-29 16:49:02 -0700180 # Bionic libc has different error messages than glibc
181 output.gsub!(/Too many symbolic links encountered/, 'Too many levels of symbolic links')
Shinichiro Hamajia9bda7a2015-05-20 17:50:42 +0900182 output
183end
184
Shinichiro Hamaji2d2ed952016-04-28 16:50:46 +0900185bash_var = ' SHELL=/bin/bash'
186
Shinichiro Hamajia9bda7a2015-05-20 17:50:42 +0900187run_make_test = proc do |mk|
188 c = File.read(mk)
Shinichiro Hamaji6a492922015-07-27 19:37:20 +0900189 expected_failure = false
Fumitoshi Ukaibfabe632015-07-28 15:26:56 +0900190 if c =~ /\A# TODO(?:\(([-a-z|]+)\))?/
Shinichiro Hamaji6a492922015-07-27 19:37:20 +0900191 if $1
192 todos = $1.split('|')
193 if todos.include?('go') && !ckati
194 expected_failure = true
195 end
196 if todos.include?('c') && ckati
197 expected_failure = true
198 end
Fumitoshi Ukaibfabe632015-07-28 15:26:56 +0900199 if todos.include?('go-ninja') && !ckati && via_ninja
200 expected_failure = true
201 end
202 if todos.include?('c-ninja') && ckati && via_ninja
203 expected_failure = true
204 end
Shinichiro Hamaji03fa3452016-04-27 17:08:32 +0900205 if todos.include?('c-exec') && ckati && !via_ninja
206 expected_failure = true
207 end
Shinichiro Hamaji6a492922015-07-27 19:37:20 +0900208 if todos.include?('ninja') && via_ninja
209 expected_failure = true
210 end
211 else
212 expected_failure = true
Shinichiro Hamajie919d002015-06-26 01:15:55 +0900213 end
214 end
Shinichiro Hamajia9bda7a2015-05-20 17:50:42 +0900215
216 run_in_testdir(mk) do |name|
Fumitoshi Ukai119dc912015-03-30 16:52:41 +0900217 File.open("Makefile", 'w') do |ofile|
218 ofile.print(c)
219 end
Shinichiro Hamaji91571ac2015-09-07 18:24:00 +0900220 File.symlink('../../testcase/submake', 'submake')
Fumitoshi Ukai119dc912015-03-30 16:52:41 +0900221
222 expected = ''
223 output = ''
224
Shinichiro Hamaji491e73f2015-04-07 12:41:59 +0900225 testcases = c.scan(/^test\d*/).sort.uniq
Shinichiro Hamaji497754d2015-03-31 02:02:11 +0900226 if testcases.empty?
227 testcases = ['']
228 end
Shinichiro Hamajie5be0142015-03-30 19:26:01 +0900229
Shinichiro Hamajib6a04542015-09-09 17:37:41 +0900230 is_silent_test = mk =~ /\/submake_/
231
Shinichiro Hamajie5be0142015-03-30 19:26:01 +0900232 cleanup
233 testcases.each do |tc|
Shinichiro Hamaji8ac81712015-07-16 09:15:54 +0900234 cmd = 'make'
Shinichiro Hamajib6a04542015-09-09 17:37:41 +0900235 if via_ninja || is_silent_test
Shinichiro Hamaji8ac81712015-07-16 09:15:54 +0900236 cmd += ' -s'
237 end
Shinichiro Hamaji2d2ed952016-04-28 16:50:46 +0900238 cmd += bash_var
Shinichiro Hamaji8ac81712015-07-16 09:15:54 +0900239 cmd += " #{tc} 2>&1"
Shinichiro Hamaji913eb742016-04-28 17:31:24 +0900240 res = IO.popen(cmd, 'r:binary', &:read)
Dan Willemsenf3a4ced2015-08-25 14:22:35 -0700241 res = normalize_make_log(res, mk, via_ninja)
Shinichiro Hamaji74a66002015-04-27 16:42:30 +0900242 expected += "=== #{tc} ===\n" + res
Fumitoshi Ukai119dc912015-03-30 16:52:41 +0900243 expected_files = get_output_filenames
Fumitoshi Ukai119dc912015-03-30 16:52:41 +0900244 expected += "\n=== FILES ===\n#{expected_files * "\n"}\n"
Shinichiro Hamajie5be0142015-03-30 19:26:01 +0900245 end
246
247 cleanup
248 testcases.each do |tc|
Shinichiro Hamajic48d9ce2015-04-28 03:47:39 +0900249 json = "#{tc.empty? ? 'test' : tc}"
Fumitoshi Ukai0547db62015-07-29 16:20:59 +0900250 cmd = "../../kati -save_json=#{json}.json -log_dir=. --use_find_emulator"
Shinichiro Hamaji776ca302015-06-06 03:52:48 +0900251 if ckati
Shinichiro Hamaji8ac81712015-07-16 09:15:54 +0900252 cmd = "../../ckati --use_find_emulator"
Shinichiro Hamaji776ca302015-06-06 03:52:48 +0900253 end
Shinichiro Hamaji8ac81712015-07-16 09:15:54 +0900254 if via_ninja
255 cmd += ' --ninja'
256 end
Shinichiro Hamaji85620572015-10-03 11:25:15 +0900257 if gen_all_targets
258 if !ckati || !via_ninja
259 raise "-a should be used with -c -n"
260 end
261 cmd += ' --gen_all_targets'
262 end
Shinichiro Hamajib6a04542015-09-09 17:37:41 +0900263 if is_silent_test
264 cmd += ' -s'
265 end
Shinichiro Hamaji2d2ed952016-04-28 16:50:46 +0900266 cmd += bash_var
Shinichiro Hamaji6ff74ce2015-10-03 11:58:35 +0900267 if !gen_all_targets || mk =~ /makecmdgoals/
268 cmd += " #{tc}"
269 end
270 cmd += " 2>&1"
Shinichiro Hamajib674d582015-04-28 03:40:57 +0900271 res = IO.popen(cmd, 'r:binary', &:read)
Fumitoshi Ukai39837dd2015-07-28 12:25:56 +0900272 if via_ninja && File.exist?('build.ninja') && File.exists?('ninja.sh')
Shinichiro Hamaji85620572015-10-03 11:25:15 +0900273 cmd = './ninja.sh -j1 -v'
274 if gen_all_targets
275 cmd += " #{tc}"
276 end
277 cmd += ' 2>&1'
278 log = IO.popen(cmd, 'r:binary', &:read)
Shinichiro Hamaji86e11332015-07-28 15:24:17 +0900279 res += normalize_ninja_log(log, mk)
Shinichiro Hamaji8ac81712015-07-16 09:15:54 +0900280 end
Shinichiro Hamajia9bda7a2015-05-20 17:50:42 +0900281 res = normalize_kati_log(res)
Shinichiro Hamaji42f42e12015-04-13 14:26:45 +0900282 output += "=== #{tc} ===\n" + res
Shinichiro Hamajie5be0142015-03-30 19:26:01 +0900283 output_files = get_output_filenames
Fumitoshi Ukai119dc912015-03-30 16:52:41 +0900284 output += "\n=== FILES ===\n#{output_files * "\n"}\n"
285 end
286
287 File.open('out.make', 'w'){|ofile|ofile.print(expected)}
288 File.open('out.kati', 'w'){|ofile|ofile.print(output)}
289
Shinichiro Hamaji74c832f2015-04-09 14:54:39 +0900290 if expected =~ /FAIL/
291 puts %Q(#{name} has a string "FAIL" in its expectation)
292 exit 1
293 end
294
Fumitoshi Ukai119dc912015-03-30 16:52:41 +0900295 if expected != output
Shinichiro Hamaji91b105c2015-03-30 18:39:05 +0900296 if expected_failure
297 puts "#{name}: FAIL (expected)"
Shinichiro Hamajic6713602015-04-01 01:03:34 +0900298 expected_failures << name
Shinichiro Hamaji91b105c2015-03-30 18:39:05 +0900299 else
300 puts "#{name}: FAIL"
Shinichiro Hamajic6713602015-04-01 01:03:34 +0900301 failures << name
Shinichiro Hamaji91b105c2015-03-30 18:39:05 +0900302 end
Shinichiro Hamaji7f3a8702015-09-11 15:37:02 +0900303 if !expected_failure || show_failing
Shinichiro Hamaji221a16b2015-09-10 12:40:14 +0900304 puts `diff -u out.make out.kati`
305 end
Fumitoshi Ukai119dc912015-03-30 16:52:41 +0900306 else
Shinichiro Hamaji91b105c2015-03-30 18:39:05 +0900307 if expected_failure
308 puts "#{name}: PASS (unexpected)"
Shinichiro Hamajic6713602015-04-01 01:03:34 +0900309 unexpected_passes << name
Shinichiro Hamaji91b105c2015-03-30 18:39:05 +0900310 else
311 puts "#{name}: PASS"
Shinichiro Hamajic6713602015-04-01 01:03:34 +0900312 passes << name
Shinichiro Hamaji91b105c2015-03-30 18:39:05 +0900313 end
Fumitoshi Ukai119dc912015-03-30 16:52:41 +0900314 end
Shinichiro Hamajic48d9ce2015-04-28 03:47:39 +0900315
Shinichiro Hamajie666ac82015-04-28 04:18:13 +0900316 if name !~ /^err_/ && test_serialization && !expected_failure
Shinichiro Hamajic48d9ce2015-04-28 03:47:39 +0900317 testcases.each do |tc|
318 json = "#{tc.empty? ? 'test' : tc}"
Fumitoshi Ukai6450d0f2015-07-10 16:34:06 +0900319 cmd = "../../kati -save_json=#{json}_2.json -load_json=#{json}.json -n -log_dir=. #{tc} 2>&1"
Shinichiro Hamajic48d9ce2015-04-28 03:47:39 +0900320 res = IO.popen(cmd, 'r:binary', &:read)
321 if !File.exist?("#{json}.json") || !File.exist?("#{json}_2.json")
322 puts "#{name}##{json}: Serialize failure (not exist)"
Shinichiro Hamaji9f4f5d32015-04-28 03:53:49 +0900323 puts res
Shinichiro Hamajic48d9ce2015-04-28 03:47:39 +0900324 else
325 json1 = File.read("#{json}.json")
326 json2 = File.read("#{json}_2.json")
327 if json1 != json2
328 puts "#{name}##{json}: Serialize failure"
Shinichiro Hamaji9f4f5d32015-04-28 03:53:49 +0900329 puts res
Shinichiro Hamajic48d9ce2015-04-28 03:47:39 +0900330 end
331 end
332 end
333 end
Fumitoshi Ukai119dc912015-03-30 16:52:41 +0900334 end
335end
Shinichiro Hamajic6713602015-04-01 01:03:34 +0900336
Shinichiro Hamajia9bda7a2015-05-20 17:50:42 +0900337run_shell_test = proc do |sh|
Shinichiro Hamaji09796ef2015-07-30 17:08:29 +0900338 is_ninja_test = sh =~ /\/ninja_/
339 if is_ninja_test && (!ckati || !via_ninja)
340 next
341 end
342
Shinichiro Hamajia9bda7a2015-05-20 17:50:42 +0900343 run_in_testdir(sh) do |name|
344 cleanup
345 cmd = "sh ../../#{sh} make"
Shinichiro Hamaji09796ef2015-07-30 17:08:29 +0900346 if is_ninja_test
347 cmd += ' -s'
348 end
Shinichiro Hamaji2d2ed952016-04-28 16:50:46 +0900349 cmd += bash_var
Shinichiro Hamajia9bda7a2015-05-20 17:50:42 +0900350 expected = IO.popen(cmd, 'r:binary', &:read)
351 cleanup
Shinichiro Hamaji09796ef2015-07-30 17:08:29 +0900352
353 if is_ninja_test
354 if ckati
Shinichiro Hamajia88c1c22015-07-31 12:29:48 +0900355 cmd = "sh ../../#{sh} ../../ckati --ninja --regen"
Shinichiro Hamaji09796ef2015-07-30 17:08:29 +0900356 else
357 next
358 end
359 else
360 if ckati
361 cmd = "sh ../../#{sh} ../../ckati"
362 else
363 cmd = "sh ../../#{sh} ../../kati --use_cache -log_dir=."
364 end
365 end
Shinichiro Hamaji2d2ed952016-04-28 16:50:46 +0900366 cmd += bash_var
Shinichiro Hamaji09796ef2015-07-30 17:08:29 +0900367
Shinichiro Hamajia9bda7a2015-05-20 17:50:42 +0900368 output = IO.popen(cmd, 'r:binary', &:read)
369
Dan Willemsenf3a4ced2015-08-25 14:22:35 -0700370 expected = normalize_make_log(expected, sh, is_ninja_test)
Shinichiro Hamajia9bda7a2015-05-20 17:50:42 +0900371 output = normalize_kati_log(output)
Shinichiro Hamaji09796ef2015-07-30 17:08:29 +0900372 if is_ninja_test
373 output = normalize_ninja_log(output, sh)
374 end
Shinichiro Hamajia9bda7a2015-05-20 17:50:42 +0900375 File.open('out.make', 'w'){|ofile|ofile.print(expected)}
376 File.open('out.kati', 'w'){|ofile|ofile.print(output)}
377
378 if expected != output
379 puts "#{name}: FAIL"
Shinichiro Hamaji39e62402015-05-20 19:34:58 +0900380 puts `diff -u out.make out.kati`
Shinichiro Hamajia9bda7a2015-05-20 17:50:42 +0900381 failures << name
382 else
383 puts "#{name}: PASS"
384 passes << name
385 end
386 end
387end
388
389test_files.each do |test|
390 if /\.mk$/ =~ test
391 run_make_test.call(test)
392 elsif /\.sh$/ =~ test
393 run_shell_test.call(test)
394 else
395 raise "Unknown test type: #{test}"
396 end
397end
398
Shinichiro Hamajic6713602015-04-01 01:03:34 +0900399puts
400
401if !expected_failures.empty?
402 puts "=== Expected failures ==="
403 expected_failures.each do |n|
404 puts n
405 end
406end
407
408if !unexpected_passes.empty?
409 puts "=== Unexpected passes ==="
410 unexpected_passes.each do |n|
411 puts n
412 end
413end
414
415if !failures.empty?
416 puts "=== Failures ==="
417 failures.each do |n|
418 puts n
419 end
420end
421
422puts
423
424if !unexpected_passes.empty? || !failures.empty?
Shinichiro Hamaji776ca302015-06-06 03:52:48 +0900425 puts "FAIL! (#{failures.size + unexpected_passes.size} fails #{passes.size} passes)"
Shinichiro Hamaji680e98b2015-10-05 17:30:43 +0900426 exit 1
Shinichiro Hamajic6713602015-04-01 01:03:34 +0900427else
428 puts 'PASS!'
429end