blob: 190c11f50214ff62cdf9210ec9ee59edac091595 [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")
Shinichiro Hamajia9bda7a2015-05-20 17:50:42 +0900180 output
181end
182
Shinichiro Hamaji2d2ed952016-04-28 16:50:46 +0900183bash_var = ' SHELL=/bin/bash'
184
Shinichiro Hamajia9bda7a2015-05-20 17:50:42 +0900185run_make_test = proc do |mk|
186 c = File.read(mk)
Shinichiro Hamaji6a492922015-07-27 19:37:20 +0900187 expected_failure = false
Fumitoshi Ukaibfabe632015-07-28 15:26:56 +0900188 if c =~ /\A# TODO(?:\(([-a-z|]+)\))?/
Shinichiro Hamaji6a492922015-07-27 19:37:20 +0900189 if $1
190 todos = $1.split('|')
191 if todos.include?('go') && !ckati
192 expected_failure = true
193 end
194 if todos.include?('c') && ckati
195 expected_failure = true
196 end
Fumitoshi Ukaibfabe632015-07-28 15:26:56 +0900197 if todos.include?('go-ninja') && !ckati && via_ninja
198 expected_failure = true
199 end
200 if todos.include?('c-ninja') && ckati && via_ninja
201 expected_failure = true
202 end
Shinichiro Hamaji03fa3452016-04-27 17:08:32 +0900203 if todos.include?('c-exec') && ckati && !via_ninja
204 expected_failure = true
205 end
Shinichiro Hamaji6a492922015-07-27 19:37:20 +0900206 if todos.include?('ninja') && via_ninja
207 expected_failure = true
208 end
209 else
210 expected_failure = true
Shinichiro Hamajie919d002015-06-26 01:15:55 +0900211 end
212 end
Shinichiro Hamajia9bda7a2015-05-20 17:50:42 +0900213
214 run_in_testdir(mk) do |name|
Fumitoshi Ukai119dc912015-03-30 16:52:41 +0900215 File.open("Makefile", 'w') do |ofile|
216 ofile.print(c)
217 end
Shinichiro Hamaji91571ac2015-09-07 18:24:00 +0900218 File.symlink('../../testcase/submake', 'submake')
Fumitoshi Ukai119dc912015-03-30 16:52:41 +0900219
220 expected = ''
221 output = ''
222
Shinichiro Hamaji491e73f2015-04-07 12:41:59 +0900223 testcases = c.scan(/^test\d*/).sort.uniq
Shinichiro Hamaji497754d2015-03-31 02:02:11 +0900224 if testcases.empty?
225 testcases = ['']
226 end
Shinichiro Hamajie5be0142015-03-30 19:26:01 +0900227
Shinichiro Hamajib6a04542015-09-09 17:37:41 +0900228 is_silent_test = mk =~ /\/submake_/
229
Shinichiro Hamajie5be0142015-03-30 19:26:01 +0900230 cleanup
231 testcases.each do |tc|
Shinichiro Hamaji8ac81712015-07-16 09:15:54 +0900232 cmd = 'make'
Shinichiro Hamajib6a04542015-09-09 17:37:41 +0900233 if via_ninja || is_silent_test
Shinichiro Hamaji8ac81712015-07-16 09:15:54 +0900234 cmd += ' -s'
235 end
Shinichiro Hamaji2d2ed952016-04-28 16:50:46 +0900236 cmd += bash_var
Shinichiro Hamaji8ac81712015-07-16 09:15:54 +0900237 cmd += " #{tc} 2>&1"
Shinichiro Hamaji913eb742016-04-28 17:31:24 +0900238 res = IO.popen(cmd, 'r:binary', &:read)
Dan Willemsenf3a4ced2015-08-25 14:22:35 -0700239 res = normalize_make_log(res, mk, via_ninja)
Shinichiro Hamaji74a66002015-04-27 16:42:30 +0900240 expected += "=== #{tc} ===\n" + res
Fumitoshi Ukai119dc912015-03-30 16:52:41 +0900241 expected_files = get_output_filenames
Fumitoshi Ukai119dc912015-03-30 16:52:41 +0900242 expected += "\n=== FILES ===\n#{expected_files * "\n"}\n"
Shinichiro Hamajie5be0142015-03-30 19:26:01 +0900243 end
244
245 cleanup
246 testcases.each do |tc|
Shinichiro Hamajic48d9ce2015-04-28 03:47:39 +0900247 json = "#{tc.empty? ? 'test' : tc}"
Fumitoshi Ukai0547db62015-07-29 16:20:59 +0900248 cmd = "../../kati -save_json=#{json}.json -log_dir=. --use_find_emulator"
Shinichiro Hamaji776ca302015-06-06 03:52:48 +0900249 if ckati
Shinichiro Hamaji8ac81712015-07-16 09:15:54 +0900250 cmd = "../../ckati --use_find_emulator"
Shinichiro Hamaji776ca302015-06-06 03:52:48 +0900251 end
Shinichiro Hamaji8ac81712015-07-16 09:15:54 +0900252 if via_ninja
253 cmd += ' --ninja'
254 end
Shinichiro Hamaji85620572015-10-03 11:25:15 +0900255 if gen_all_targets
256 if !ckati || !via_ninja
257 raise "-a should be used with -c -n"
258 end
259 cmd += ' --gen_all_targets'
260 end
Shinichiro Hamajib6a04542015-09-09 17:37:41 +0900261 if is_silent_test
262 cmd += ' -s'
263 end
Shinichiro Hamaji2d2ed952016-04-28 16:50:46 +0900264 cmd += bash_var
Shinichiro Hamaji6ff74ce2015-10-03 11:58:35 +0900265 if !gen_all_targets || mk =~ /makecmdgoals/
266 cmd += " #{tc}"
267 end
268 cmd += " 2>&1"
Shinichiro Hamajib674d582015-04-28 03:40:57 +0900269 res = IO.popen(cmd, 'r:binary', &:read)
Fumitoshi Ukai39837dd2015-07-28 12:25:56 +0900270 if via_ninja && File.exist?('build.ninja') && File.exists?('ninja.sh')
Shinichiro Hamaji85620572015-10-03 11:25:15 +0900271 cmd = './ninja.sh -j1 -v'
272 if gen_all_targets
273 cmd += " #{tc}"
274 end
275 cmd += ' 2>&1'
276 log = IO.popen(cmd, 'r:binary', &:read)
Shinichiro Hamaji86e11332015-07-28 15:24:17 +0900277 res += normalize_ninja_log(log, mk)
Shinichiro Hamaji8ac81712015-07-16 09:15:54 +0900278 end
Shinichiro Hamajia9bda7a2015-05-20 17:50:42 +0900279 res = normalize_kati_log(res)
Shinichiro Hamaji42f42e12015-04-13 14:26:45 +0900280 output += "=== #{tc} ===\n" + res
Shinichiro Hamajie5be0142015-03-30 19:26:01 +0900281 output_files = get_output_filenames
Fumitoshi Ukai119dc912015-03-30 16:52:41 +0900282 output += "\n=== FILES ===\n#{output_files * "\n"}\n"
283 end
284
285 File.open('out.make', 'w'){|ofile|ofile.print(expected)}
286 File.open('out.kati', 'w'){|ofile|ofile.print(output)}
287
Shinichiro Hamaji74c832f2015-04-09 14:54:39 +0900288 if expected =~ /FAIL/
289 puts %Q(#{name} has a string "FAIL" in its expectation)
290 exit 1
291 end
292
Fumitoshi Ukai119dc912015-03-30 16:52:41 +0900293 if expected != output
Shinichiro Hamaji91b105c2015-03-30 18:39:05 +0900294 if expected_failure
295 puts "#{name}: FAIL (expected)"
Shinichiro Hamajic6713602015-04-01 01:03:34 +0900296 expected_failures << name
Shinichiro Hamaji91b105c2015-03-30 18:39:05 +0900297 else
298 puts "#{name}: FAIL"
Shinichiro Hamajic6713602015-04-01 01:03:34 +0900299 failures << name
Shinichiro Hamaji91b105c2015-03-30 18:39:05 +0900300 end
Shinichiro Hamaji7f3a8702015-09-11 15:37:02 +0900301 if !expected_failure || show_failing
Shinichiro Hamaji221a16b2015-09-10 12:40:14 +0900302 puts `diff -u out.make out.kati`
303 end
Fumitoshi Ukai119dc912015-03-30 16:52:41 +0900304 else
Shinichiro Hamaji91b105c2015-03-30 18:39:05 +0900305 if expected_failure
306 puts "#{name}: PASS (unexpected)"
Shinichiro Hamajic6713602015-04-01 01:03:34 +0900307 unexpected_passes << name
Shinichiro Hamaji91b105c2015-03-30 18:39:05 +0900308 else
309 puts "#{name}: PASS"
Shinichiro Hamajic6713602015-04-01 01:03:34 +0900310 passes << name
Shinichiro Hamaji91b105c2015-03-30 18:39:05 +0900311 end
Fumitoshi Ukai119dc912015-03-30 16:52:41 +0900312 end
Shinichiro Hamajic48d9ce2015-04-28 03:47:39 +0900313
Shinichiro Hamajie666ac82015-04-28 04:18:13 +0900314 if name !~ /^err_/ && test_serialization && !expected_failure
Shinichiro Hamajic48d9ce2015-04-28 03:47:39 +0900315 testcases.each do |tc|
316 json = "#{tc.empty? ? 'test' : tc}"
Fumitoshi Ukai6450d0f2015-07-10 16:34:06 +0900317 cmd = "../../kati -save_json=#{json}_2.json -load_json=#{json}.json -n -log_dir=. #{tc} 2>&1"
Shinichiro Hamajic48d9ce2015-04-28 03:47:39 +0900318 res = IO.popen(cmd, 'r:binary', &:read)
319 if !File.exist?("#{json}.json") || !File.exist?("#{json}_2.json")
320 puts "#{name}##{json}: Serialize failure (not exist)"
Shinichiro Hamaji9f4f5d32015-04-28 03:53:49 +0900321 puts res
Shinichiro Hamajic48d9ce2015-04-28 03:47:39 +0900322 else
323 json1 = File.read("#{json}.json")
324 json2 = File.read("#{json}_2.json")
325 if json1 != json2
326 puts "#{name}##{json}: Serialize failure"
Shinichiro Hamaji9f4f5d32015-04-28 03:53:49 +0900327 puts res
Shinichiro Hamajic48d9ce2015-04-28 03:47:39 +0900328 end
329 end
330 end
331 end
Fumitoshi Ukai119dc912015-03-30 16:52:41 +0900332 end
333end
Shinichiro Hamajic6713602015-04-01 01:03:34 +0900334
Shinichiro Hamajia9bda7a2015-05-20 17:50:42 +0900335run_shell_test = proc do |sh|
Shinichiro Hamaji09796ef2015-07-30 17:08:29 +0900336 is_ninja_test = sh =~ /\/ninja_/
337 if is_ninja_test && (!ckati || !via_ninja)
338 next
339 end
340
Shinichiro Hamajia9bda7a2015-05-20 17:50:42 +0900341 run_in_testdir(sh) do |name|
342 cleanup
343 cmd = "sh ../../#{sh} make"
Shinichiro Hamaji09796ef2015-07-30 17:08:29 +0900344 if is_ninja_test
345 cmd += ' -s'
346 end
Shinichiro Hamaji2d2ed952016-04-28 16:50:46 +0900347 cmd += bash_var
Shinichiro Hamajia9bda7a2015-05-20 17:50:42 +0900348 expected = IO.popen(cmd, 'r:binary', &:read)
349 cleanup
Shinichiro Hamaji09796ef2015-07-30 17:08:29 +0900350
351 if is_ninja_test
352 if ckati
Shinichiro Hamajia88c1c22015-07-31 12:29:48 +0900353 cmd = "sh ../../#{sh} ../../ckati --ninja --regen"
Shinichiro Hamaji09796ef2015-07-30 17:08:29 +0900354 else
355 next
356 end
357 else
358 if ckati
359 cmd = "sh ../../#{sh} ../../ckati"
360 else
361 cmd = "sh ../../#{sh} ../../kati --use_cache -log_dir=."
362 end
363 end
Shinichiro Hamaji2d2ed952016-04-28 16:50:46 +0900364 cmd += bash_var
Shinichiro Hamaji09796ef2015-07-30 17:08:29 +0900365
Shinichiro Hamajia9bda7a2015-05-20 17:50:42 +0900366 output = IO.popen(cmd, 'r:binary', &:read)
367
Dan Willemsenf3a4ced2015-08-25 14:22:35 -0700368 expected = normalize_make_log(expected, sh, is_ninja_test)
Shinichiro Hamajia9bda7a2015-05-20 17:50:42 +0900369 output = normalize_kati_log(output)
Shinichiro Hamaji09796ef2015-07-30 17:08:29 +0900370 if is_ninja_test
371 output = normalize_ninja_log(output, sh)
372 end
Shinichiro Hamajia9bda7a2015-05-20 17:50:42 +0900373 File.open('out.make', 'w'){|ofile|ofile.print(expected)}
374 File.open('out.kati', 'w'){|ofile|ofile.print(output)}
375
376 if expected != output
377 puts "#{name}: FAIL"
Shinichiro Hamaji39e62402015-05-20 19:34:58 +0900378 puts `diff -u out.make out.kati`
Shinichiro Hamajia9bda7a2015-05-20 17:50:42 +0900379 failures << name
380 else
381 puts "#{name}: PASS"
382 passes << name
383 end
384 end
385end
386
387test_files.each do |test|
388 if /\.mk$/ =~ test
389 run_make_test.call(test)
390 elsif /\.sh$/ =~ test
391 run_shell_test.call(test)
392 else
393 raise "Unknown test type: #{test}"
394 end
395end
396
Shinichiro Hamajic6713602015-04-01 01:03:34 +0900397puts
398
399if !expected_failures.empty?
400 puts "=== Expected failures ==="
401 expected_failures.each do |n|
402 puts n
403 end
404end
405
406if !unexpected_passes.empty?
407 puts "=== Unexpected passes ==="
408 unexpected_passes.each do |n|
409 puts n
410 end
411end
412
413if !failures.empty?
414 puts "=== Failures ==="
415 failures.each do |n|
416 puts n
417 end
418end
419
420puts
421
422if !unexpected_passes.empty? || !failures.empty?
Shinichiro Hamaji776ca302015-06-06 03:52:48 +0900423 puts "FAIL! (#{failures.size + unexpected_passes.size} fails #{passes.size} passes)"
Shinichiro Hamaji680e98b2015-10-05 17:30:43 +0900424 exit 1
Shinichiro Hamajic6713602015-04-01 01:03:34 +0900425else
426 puts 'PASS!'
427end