|
10 | 10 |
|
11 | 11 | # Recommended: function jt { ruby tool/jt.rb $@; }
|
12 | 12 |
|
13 |
| -def sh(*args) |
14 |
| - system args.join(' ') |
15 |
| - raise "failed" unless $? == 0 |
16 |
| -end |
17 |
| - |
18 |
| -def mvn(*args) |
19 |
| - sh 'mvn', *args |
20 |
| -end |
| 13 | +module ShellUtils |
| 14 | + private |
21 | 15 |
|
22 |
| -def mspec(command, *args) |
23 |
| - sh 'ruby', 'spec/mspec/bin/mspec', command, '--config', 'spec/truffle/truffle.mspec', *args |
24 |
| -end |
| 16 | + def sh(*args) |
| 17 | + system args.join(' ') |
| 18 | + raise "failed" unless $? == 0 |
| 19 | + end |
25 | 20 |
|
26 |
| -def help |
27 |
| - puts 'jt build build' |
28 |
| - puts 'jt clean clean' |
29 |
| - puts 'jt rebuild clean and build' |
30 |
| - puts 'jt test run all specs' |
31 |
| - puts 'jt test spec/ruby/language run specs in this directory' |
32 |
| - puts 'jt test spec/ruby/language/while_spec.rb run specs in this file' |
33 |
| - puts 'jt tag spec/ruby/language tag failing specs in this directory' |
34 |
| - puts 'jt tag spec/ruby/language/while_spec.rb tag failing specs in this file' |
35 |
| - puts 'jt untag spec/ruby/language untag passing specs in this directory' |
36 |
| - puts 'jt untag spec/ruby/language/while_spec.rb untag passing specs in this file' |
37 |
| - puts 'jt findbugs run findbugs' |
38 |
| - puts 'jt findbugs report run findbugs and generate an HTML report' |
39 |
| - puts |
40 |
| - puts 'you can also put build or redbuild in front of any command' |
41 |
| -end |
| 21 | + def mvn(*args) |
| 22 | + sh 'mvn', *args |
| 23 | + end |
42 | 24 |
|
43 |
| -def build |
44 |
| - mvn 'package' |
| 25 | + def mspec(command, *args) |
| 26 | + sh 'ruby', 'spec/mspec/bin/mspec', command, '--config', 'spec/truffle/truffle.mspec', *args |
| 27 | + end |
45 | 28 | end
|
46 | 29 |
|
47 |
| -def clean |
48 |
| - mvn 'clean' |
49 |
| -end |
| 30 | +module Commands |
| 31 | + include ShellUtils |
| 32 | + |
| 33 | + def help |
| 34 | + puts 'jt build build' |
| 35 | + puts 'jt clean clean' |
| 36 | + puts 'jt rebuild clean and build' |
| 37 | + puts 'jt test run all specs' |
| 38 | + puts 'jt test spec/ruby/language run specs in this directory' |
| 39 | + puts 'jt test spec/ruby/language/while_spec.rb run specs in this file' |
| 40 | + puts 'jt tag spec/ruby/language tag failing specs in this directory' |
| 41 | + puts 'jt tag spec/ruby/language/while_spec.rb tag failing specs in this file' |
| 42 | + puts 'jt untag spec/ruby/language untag passing specs in this directory' |
| 43 | + puts 'jt untag spec/ruby/language/while_spec.rb untag passing specs in this file' |
| 44 | + puts 'jt findbugs run findbugs' |
| 45 | + puts 'jt findbugs report run findbugs and generate an HTML report' |
| 46 | + puts |
| 47 | + puts 'you can also put build or redbuild in front of any command' |
| 48 | + end |
50 | 49 |
|
51 |
| -def rebuild |
52 |
| - clean |
53 |
| - build |
54 |
| -end |
| 50 | + def build |
| 51 | + mvn 'package' |
| 52 | + end |
55 | 53 |
|
56 |
| -def test(path=nil) |
57 |
| - if path.nil? |
58 |
| - mspec 'run', '--excl-tag', 'fails', ':language', ':core' |
59 |
| - elsif path.start_with? 'spec/ruby' |
60 |
| - mspec 'run', '--excl-tag', 'fails', path |
61 |
| - else |
62 |
| - raise "don't know how to test #{path}" |
| 54 | + def clean |
| 55 | + mvn 'clean' |
63 | 56 | end
|
64 |
| -end |
65 | 57 |
|
66 |
| -def tag(path) |
67 |
| - mspec 'tag', '--add', 'fails', '--fail', path |
68 |
| -end |
| 58 | + def rebuild |
| 59 | + clean |
| 60 | + build |
| 61 | + end |
69 | 62 |
|
70 |
| -def untag(path) |
71 |
| - puts |
72 |
| - puts "WARNING: untag is currently not very reliable - run test #{path} after and manually annotate any new failures" |
73 |
| - puts |
74 |
| - mspec 'tag', '--del', 'fails', '--pass', path |
75 |
| -end |
| 63 | + def test(path=nil) |
| 64 | + if path == nil |
| 65 | + mspec 'run', '--excl-tag', 'fails', ':language', ':core' |
| 66 | + elsif path.start_with? 'spec/ruby' |
| 67 | + mspec 'run', '--excl-tag', 'fails', path |
| 68 | + else |
| 69 | + raise ArgumentError, "don't know how to test #{path}" |
| 70 | + end |
| 71 | + end |
76 | 72 |
|
77 |
| -def findbugs |
78 |
| - sh 'tool/truffle-findbugs.sh' |
79 |
| -end |
| 73 | + def tag(path) |
| 74 | + mspec 'tag', '--add', 'fails', '--fail', path |
| 75 | + end |
80 | 76 |
|
81 |
| -def findbugs_report |
82 |
| - sh 'tool/truffle-findbugs.sh --report' rescue nil |
83 |
| - sh 'open truffle-findbugs-report.html' rescue nil |
84 |
| -end |
| 77 | + def untag(path) |
| 78 | + puts |
| 79 | + puts "WARNING: untag is currently not very reliable - run test #{path} after and manually annotate any new failures" |
| 80 | + puts |
| 81 | + mspec 'tag', '--del', 'fails', '--pass', path |
| 82 | + end |
85 | 83 |
|
86 |
| -COMMANDS = [ |
87 |
| - ['help'], |
88 |
| - ['build'], |
89 |
| - ['clean'], |
90 |
| - ['rebuild'], |
91 |
| - ['test'], |
92 |
| - ['test', :path], |
93 |
| - ['tag', :path], |
94 |
| - ['untag', :path], |
95 |
| - ['findbugs'], |
96 |
| - ['findbugs', 'report'] |
97 |
| -] |
98 |
| - |
99 |
| -if [[], ['-h'], ['-help'], ['--help']].include? ARGV |
100 |
| - help |
101 |
| - exit |
| 84 | + def findbugs(report=nil) |
| 85 | + case report |
| 86 | + when "report" |
| 87 | + sh 'tool/truffle-findbugs.sh --report' rescue nil |
| 88 | + sh 'open truffle-findbugs-report.html' rescue nil |
| 89 | + when nil |
| 90 | + sh 'tool/truffle-findbugs.sh' |
| 91 | + else |
| 92 | + raise ArgumentError, report |
| 93 | + end |
| 94 | + end |
102 | 95 | end
|
103 | 96 |
|
104 |
| -def match(args, command) |
105 |
| - return false if ARGV.size != command.size |
| 97 | +class JT |
| 98 | + include Commands |
106 | 99 |
|
107 |
| - command_name = [] |
108 |
| - impl_args = [] |
| 100 | + def run(args) |
| 101 | + args = args.dup |
109 | 102 |
|
110 |
| - command.zip(ARGV).each do |expected, actual| |
111 |
| - if expected.is_a? String |
112 |
| - return false if expected != actual |
113 |
| - command_name.push expected |
114 |
| - elsif expected.is_a? Symbol |
115 |
| - impl_args.push actual |
| 103 | + if args.empty? or !(args & %w[-h -help --help]).empty? |
| 104 | + help |
| 105 | + exit |
116 | 106 | end
|
117 |
| - end |
118 | 107 |
|
119 |
| - send command_name.join('_'), *impl_args |
| 108 | + send args.shift if %w[build rebuild].include? args.first |
120 | 109 |
|
121 |
| - exit |
122 |
| -end |
| 110 | + return if args.empty? |
123 | 111 |
|
124 |
| -if ARGV[0] == 'build' |
125 |
| - build |
126 |
| - ARGV.shift |
127 |
| -elsif ARGV[0] == 'rebuild' |
128 |
| - rebuild |
129 |
| - ARGV.shift |
130 |
| -end |
| 112 | + commands = Commands.public_instance_methods.map(&:to_s) |
131 | 113 |
|
132 |
| -if ARGV.empty? |
133 |
| - exit |
134 |
| -end |
| 114 | + abort "no command matched" unless commands.include?(args.first) |
135 | 115 |
|
136 |
| -COMMANDS.each do |command| |
137 |
| - match(ARGV, command) |
| 116 | + begin |
| 117 | + send(*args) |
| 118 | + rescue |
| 119 | + puts "Error during command: #{args*' '}" |
| 120 | + raise $! |
| 121 | + end |
| 122 | + end |
138 | 123 | end
|
139 | 124 |
|
140 |
| -raise "no command matched" |
| 125 | +JT.new.run(ARGV) |
0 commit comments