blob: 7b86120e02e9111d340e245f1669b072551e5b6d [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|
13 FileUtils.rm fname
14 end
15end
16
17Dir.glob('test/*.mk').sort.each do |mk|
18 c = File.read(mk)
19
Shinichiro Hamaji91b105c2015-03-30 18:39:05 +090020 expected_failure = c =~ /\A# TODO/
21
Fumitoshi Ukai119dc912015-03-30 16:52:41 +090022 name = mk[/([^\/]+)\.mk$/, 1]
23 dir = "out/#{name}"
24 FileUtils.rm_rf(dir)
25 FileUtils.mkdir_p(dir)
26
27 Dir.chdir(dir) do
28 File.open("Makefile", 'w') do |ofile|
29 ofile.print(c)
30 end
31
32 expected = ''
33 output = ''
34
Shinichiro Hamajie5be0142015-03-30 19:26:01 +090035 testcases = c.scan(/^test\d*/).sort
36
37 cleanup
38 testcases.each do |tc|
39 expected += "=== #{tc} ===\n" + `make #{tc} 2>&1`
Fumitoshi Ukai119dc912015-03-30 16:52:41 +090040 expected_files = get_output_filenames
Fumitoshi Ukai119dc912015-03-30 16:52:41 +090041 expected += "\n=== FILES ===\n#{expected_files * "\n"}\n"
Shinichiro Hamajie5be0142015-03-30 19:26:01 +090042 end
43
44 cleanup
45 testcases.each do |tc|
46 output += "=== #{tc} ===\n" + `../../kati #{tc} 2>&1`
47 output_files = get_output_filenames
Fumitoshi Ukai119dc912015-03-30 16:52:41 +090048 output += "\n=== FILES ===\n#{output_files * "\n"}\n"
49 end
50
Shinichiro Hamajie5be0142015-03-30 19:26:01 +090051 expected.gsub!(/^make\[.*\n/, '')
Shinichiro Hamaji5971b4b2015-03-31 00:37:11 +090052 # Normalizations for old/new GNU make.
53 expected.gsub!(/[`'"]/, '"')
54 expected.gsub!(/ (?:commands|recipe) for target /,
55 ' commands for target ')
Shinichiro Hamajie5be0142015-03-30 19:26:01 +090056 output.gsub!(/^\*kati\*.*\n/, '')
57
Fumitoshi Ukai119dc912015-03-30 16:52:41 +090058 File.open('out.make', 'w'){|ofile|ofile.print(expected)}
59 File.open('out.kati', 'w'){|ofile|ofile.print(output)}
60
61 if expected != output
Shinichiro Hamaji91b105c2015-03-30 18:39:05 +090062 if expected_failure
63 puts "#{name}: FAIL (expected)"
64 else
65 puts "#{name}: FAIL"
66 puts `diff -u out.make out.kati`
67 end
Fumitoshi Ukai119dc912015-03-30 16:52:41 +090068 else
Shinichiro Hamaji91b105c2015-03-30 18:39:05 +090069 if expected_failure
70 puts "#{name}: PASS (unexpected)"
71 else
72 puts "#{name}: PASS"
73 end
Fumitoshi Ukai119dc912015-03-30 16:52:41 +090074 end
75 end
76end