-
Notifications
You must be signed in to change notification settings - Fork 32
/
kst-adoption-report
executable file
·108 lines (100 loc) · 3.41 KB
/
kst-adoption-report
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#!/usr/bin/env ruby
require 'fileutils'
require_relative 'builder/shellconfig'
# Common helper method: converts `lower_under_score` to `UpperCamelCase`
def underscore_to_ucamelcase(s)
s.split(/_/).map { |x| x.capitalize }.join
end
def glob_spec_files(lang)
case lang
when 'cpp_stl_98', 'cpp_stl_11'
Dir.glob("spec/#{lang}/test_*.cpp")
when 'csharp'
Dir.glob('spec/csharp/kaitai_struct_csharp_tests/tests/Spec*.cs')
when 'go'
Dir.glob('spec/go/*_test.go')
when 'java'
Dir.glob('spec/java/src/**/Test*.java')
when 'javascript'
Dir.glob('spec/javascript/test_*.js')
when 'lua'
Dir.glob('spec/lua/test_*.lua')
when 'nim'
Dir.glob('spec/nim/t*.nim')
when 'perl'
Dir.glob('spec/perl/Test*.t')
when 'php'
Dir.glob('spec/php/*Test.php')
when 'python'
Dir.glob('spec/python/**/test_*.py')
when 'construct'
Dir.glob('spec/construct/**/test_*.py')
when 'ruby'
Dir.glob('spec/ruby/**/*_spec.rb')
when 'rust'
Dir.glob('spec/rust/tests/test_*.rs')
when 'julia'
Dir.glob('spec/julia/test_*.jl')
else
raise "Unable to handle language #{@lang.inspect}"
end
end
def spec_file_to_test_name(lang, fn)
case lang
when 'cpp_stl_98', 'cpp_stl_11'
raise "Unable to extract test name from #{fn.inspect}" unless fn =~ /^test_(.*?)\.cpp$/
underscore_to_ucamelcase($1)
when 'csharp'
raise "Unable to extract test name from #{fn.inspect}" unless fn =~ /^Spec(.*?)\.cs$/
$1
when 'go'
raise "Unable to extract test name from #{fn.inspect}" unless fn =~ /^(.*?)_test\.go$/
underscore_to_ucamelcase($1)
when 'java'
raise "Unable to extract test name from #{fn.inspect}" unless fn =~ /^Test(.*?)\.java$/
$1
when 'javascript'
raise "Unable to extract test name from #{fn.inspect}" unless fn =~ /^test_(.*?)\.js$/
underscore_to_ucamelcase($1)
when 'lua'
raise "Unable to extract test name from #{fn.inspect}" unless fn =~ /^test_(.*?)\.lua$/
underscore_to_ucamelcase($1)
when 'nim'
raise "Unable to extract test name from #{fn.inspect}" unless fn =~ /^t(.*?)\.nim$/
underscore_to_ucamelcase($1)
when 'perl'
raise "Unable to extract test name from #{fn.inspect}" unless fn =~ /^Test(.*?)\.t$/
$1
when 'php'
raise "Unable to extract test name from #{fn.inspect}" unless fn =~ /^(.*?)Test\.php$/
$1
when 'python', 'construct'
raise "Unable to extract test name from #{fn.inspect}" unless fn =~ /^test_(.*?)\.py$/
underscore_to_ucamelcase($1)
when 'ruby'
raise "Unable to extract test name from #{fn.inspect}" unless fn =~ /^(.*?)_spec\.rb$/
underscore_to_ucamelcase($1)
when 'rust'
raise "Unable to extract test name from #{fn.inspect}" unless fn =~ /^test_(.*?)\.rs$/
underscore_to_ucamelcase($1)
when 'julia'
raise "Unable to extract test name from #{fn.inspect}" unless fn =~ /^test_(.*?)\.jl$/
underscore_to_ucamelcase($1)
else
raise "Unable to handle language #{lang.inspect}"
end
end
@config = ShellConfig.new
if ARGV.count != 1
puts "Usage: #{$PROGRAM_NAME} $LANGUAGE"
exit 1
end
@lang = ARGV[0]
files = glob_spec_files(@lang).reject { |fn|
not (File.binread(fn) =~ /Autogenerated from KST: please remove this line/)
}
testcases = files.map { |fn| spec_file_to_test_name(@lang, File.basename(fn)) }
FileUtils::mkdir_p("#{@config['TEST_OUT_DIR']}/#{@lang}")
File.open("#{@config['TEST_OUT_DIR']}/#{@lang}/kst_adoption.log", 'w') { |f|
testcases.sort.each { |tc| f.puts tc }
}