blob: 3e0f1ae7de3ba0a982786f78eaab80b9f2a39fc2 [file] [log] [blame]
Fumitoshi Ukai119dc912015-03-30 16:52:41 +09001#!/usr/bin/env ruby
2
3require 'fileutils'
4
5def get_output_filenames
6 files = Dir.glob('*')
7 files.delete('Makefile')
8 files
9end
10
11def cleanup
12 get_output_filenames.each do |fname|
Shinichiro Hamajic6713602015-04-01 01:03:34 +090013 FileUtils.rm_rf fname
Fumitoshi Ukai119dc912015-03-30 16:52:41 +090014 end
15end
16
Shinichiro Hamajic6713602015-04-01 01:03:34 +090017expected_failures = []
18unexpected_passes = []
19failures = []
20passes = []
21
Fumitoshi Ukai119dc912015-03-30 16:52:41 +090022Dir.glob('test/*.mk').sort.each do |mk|
23 c = File.read(mk)
24
Shinichiro Hamaji91b105c2015-03-30 18:39:05 +090025 expected_failure = c =~ /\A# TODO/
26
Fumitoshi Ukai119dc912015-03-30 16:52:41 +090027 name = mk[/([^\/]+)\.mk$/, 1]
28 dir = "out/#{name}"
Shinichiro Hamaji52e42032015-03-31 23:20:13 +090029
Fumitoshi Ukai119dc912015-03-30 16:52:41 +090030 FileUtils.mkdir_p(dir)
Shinichiro Hamaji52e42032015-03-31 23:20:13 +090031 Dir.glob("#{dir}/*").each do |fname|
32 FileUtils.rm_rf(fname)
33 end
Fumitoshi Ukai119dc912015-03-30 16:52:41 +090034
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 Hamajie5be0142015-03-30 19:26:01 +090043 testcases = c.scan(/^test\d*/).sort
Shinichiro Hamaji497754d2015-03-31 02:02:11 +090044 if testcases.empty?
45 testcases = ['']
46 end
Shinichiro Hamajie5be0142015-03-30 19:26:01 +090047
48 cleanup
49 testcases.each do |tc|
50 expected += "=== #{tc} ===\n" + `make #{tc} 2>&1`
Fumitoshi Ukai119dc912015-03-30 16:52:41 +090051 expected_files = get_output_filenames
Fumitoshi Ukai119dc912015-03-30 16:52:41 +090052 expected += "\n=== FILES ===\n#{expected_files * "\n"}\n"
Shinichiro Hamajie5be0142015-03-30 19:26:01 +090053 end
54
55 cleanup
56 testcases.each do |tc|
57 output += "=== #{tc} ===\n" + `../../kati #{tc} 2>&1`
58 output_files = get_output_filenames
Fumitoshi Ukai119dc912015-03-30 16:52:41 +090059 output += "\n=== FILES ===\n#{output_files * "\n"}\n"
60 end
61
Shinichiro Hamajie5be0142015-03-30 19:26:01 +090062 expected.gsub!(/^make\[.*\n/, '')
Shinichiro Hamaji5971b4b2015-03-31 00:37:11 +090063 # Normalizations for old/new GNU make.
64 expected.gsub!(/[`'"]/, '"')
65 expected.gsub!(/ (?:commands|recipe) for target /,
66 ' commands for target ')
Shinichiro Hamajifed074e2015-03-31 21:51:43 +090067 expected.gsub!(/ (?:commands|recipe) commences /,
68 ' commands commence ')
Shinichiro Hamaji0ec07702015-03-31 00:50:32 +090069 expected.gsub!(' (did you mean TAB instead of 8 spaces?)', '')
70 expected.gsub!(/\s+Stop\.$/, '')
Shinichiro Hamajie5be0142015-03-30 19:26:01 +090071 output.gsub!(/^\*kati\*.*\n/, '')
72
Fumitoshi Ukai119dc912015-03-30 16:52:41 +090073 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 Hamaji91b105c2015-03-30 18:39:05 +090077 if expected_failure
78 puts "#{name}: FAIL (expected)"
Shinichiro Hamajic6713602015-04-01 01:03:34 +090079 expected_failures << name
Shinichiro Hamaji91b105c2015-03-30 18:39:05 +090080 else
81 puts "#{name}: FAIL"
82 puts `diff -u out.make out.kati`
Shinichiro Hamajic6713602015-04-01 01:03:34 +090083 failures << name
Shinichiro Hamaji91b105c2015-03-30 18:39:05 +090084 end
Fumitoshi Ukai119dc912015-03-30 16:52:41 +090085 else
Shinichiro Hamaji91b105c2015-03-30 18:39:05 +090086 if expected_failure
87 puts "#{name}: PASS (unexpected)"
Shinichiro Hamajic6713602015-04-01 01:03:34 +090088 unexpected_passes << name
Shinichiro Hamaji91b105c2015-03-30 18:39:05 +090089 else
90 puts "#{name}: PASS"
Shinichiro Hamajic6713602015-04-01 01:03:34 +090091 passes << name
Shinichiro Hamaji91b105c2015-03-30 18:39:05 +090092 end
Fumitoshi Ukai119dc912015-03-30 16:52:41 +090093 end
94 end
95end
Shinichiro Hamajic6713602015-04-01 01:03:34 +090096
97puts
98
99if !expected_failures.empty?
100 puts "=== Expected failures ==="
101 expected_failures.each do |n|
102 puts n
103 end
104end
105
106if !unexpected_passes.empty?
107 puts "=== Unexpected passes ==="
108 unexpected_passes.each do |n|
109 puts n
110 end
111end
112
113if !failures.empty?
114 puts "=== Failures ==="
115 failures.each do |n|
116 puts n
117 end
118end
119
120puts
121
122if !unexpected_passes.empty? || !failures.empty?
123 puts 'FAIL!'
124else
125 puts 'PASS!'
126end