Fumitoshi Ukai | 119dc91 | 2015-03-30 16:52:41 +0900 | [diff] [blame] | 1 | #!/usr/bin/env ruby |
| 2 | |
| 3 | require 'fileutils' |
| 4 | |
| 5 | def get_output_filenames |
| 6 | files = Dir.glob('*') |
| 7 | files.delete('Makefile') |
| 8 | files |
| 9 | end |
| 10 | |
| 11 | def cleanup |
| 12 | get_output_filenames.each do |fname| |
| 13 | FileUtils.rm fname |
| 14 | end |
| 15 | end |
| 16 | |
| 17 | Dir.glob('test/*.mk').sort.each do |mk| |
| 18 | c = File.read(mk) |
| 19 | |
Shinichiro Hamaji | 91b105c | 2015-03-30 18:39:05 +0900 | [diff] [blame] | 20 | expected_failure = c =~ /\A# TODO/ |
| 21 | |
Fumitoshi Ukai | 119dc91 | 2015-03-30 16:52:41 +0900 | [diff] [blame] | 22 | 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 Hamaji | e5be014 | 2015-03-30 19:26:01 +0900 | [diff] [blame] | 35 | testcases = c.scan(/^test\d*/).sort |
| 36 | |
| 37 | cleanup |
| 38 | testcases.each do |tc| |
| 39 | expected += "=== #{tc} ===\n" + `make #{tc} 2>&1` |
Fumitoshi Ukai | 119dc91 | 2015-03-30 16:52:41 +0900 | [diff] [blame] | 40 | expected_files = get_output_filenames |
Fumitoshi Ukai | 119dc91 | 2015-03-30 16:52:41 +0900 | [diff] [blame] | 41 | expected += "\n=== FILES ===\n#{expected_files * "\n"}\n" |
Shinichiro Hamaji | e5be014 | 2015-03-30 19:26:01 +0900 | [diff] [blame] | 42 | end |
| 43 | |
| 44 | cleanup |
| 45 | testcases.each do |tc| |
| 46 | output += "=== #{tc} ===\n" + `../../kati #{tc} 2>&1` |
| 47 | output_files = get_output_filenames |
Fumitoshi Ukai | 119dc91 | 2015-03-30 16:52:41 +0900 | [diff] [blame] | 48 | output += "\n=== FILES ===\n#{output_files * "\n"}\n" |
| 49 | end |
| 50 | |
Shinichiro Hamaji | e5be014 | 2015-03-30 19:26:01 +0900 | [diff] [blame] | 51 | expected.gsub!(/^make\[.*\n/, '') |
Shinichiro Hamaji | 5971b4b | 2015-03-31 00:37:11 +0900 | [diff] [blame^] | 52 | # Normalizations for old/new GNU make. |
| 53 | expected.gsub!(/[`'"]/, '"') |
| 54 | expected.gsub!(/ (?:commands|recipe) for target /, |
| 55 | ' commands for target ') |
Shinichiro Hamaji | e5be014 | 2015-03-30 19:26:01 +0900 | [diff] [blame] | 56 | output.gsub!(/^\*kati\*.*\n/, '') |
| 57 | |
Fumitoshi Ukai | 119dc91 | 2015-03-30 16:52:41 +0900 | [diff] [blame] | 58 | 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 Hamaji | 91b105c | 2015-03-30 18:39:05 +0900 | [diff] [blame] | 62 | 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 Ukai | 119dc91 | 2015-03-30 16:52:41 +0900 | [diff] [blame] | 68 | else |
Shinichiro Hamaji | 91b105c | 2015-03-30 18:39:05 +0900 | [diff] [blame] | 69 | if expected_failure |
| 70 | puts "#{name}: PASS (unexpected)" |
| 71 | else |
| 72 | puts "#{name}: PASS" |
| 73 | end |
Fumitoshi Ukai | 119dc91 | 2015-03-30 16:52:41 +0900 | [diff] [blame] | 74 | end |
| 75 | end |
| 76 | end |