Skip to content

Commit b2adaaa

Browse files
committed
1 parent 3b887a1 commit b2adaaa

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

spec/mspec/tool/tag_from_output.rb

100644100755
Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#!/usr/bin/env ruby
2+
13
# Adds tags based on error and failures output (e.g., from a CI log),
24
# without running any spec code.
35

@@ -8,14 +10,12 @@
810
abort 'Could not find tags directory' unless tags_dir
911

1012
output = ARGF.readlines
11-
# Remove leading "[exec] " from JRuby logs
12-
output = output.map { |line| line.sub(/^\[exec\] /, '') }
1313

1414
NUMBER = /^\d+\)$/
1515
ERROR_OR_FAILED = / (ERROR|FAILED)$/
1616
SPEC_FILE = /^(\/.+_spec\.rb)\:\d+/
1717

18-
failures = output.slice_before(NUMBER).select { |number, error_line, *rest|
18+
output.slice_before(NUMBER).select { |number, error_line, *rest|
1919
number =~ NUMBER and error_line =~ ERROR_OR_FAILED
2020
}.each { |number, error_line, *rest|
2121
description = error_line.match(ERROR_OR_FAILED).pre_match
@@ -31,9 +31,8 @@
3131
Dir.mkdir(dir) unless Dir.exist?(dir)
3232

3333
tag_line = "fails:#{description}"
34-
unless File.exist?(tags_file) and File.readlines(tags_file, chomp: true).include?(tag_line)
35-
File.open(tags_file, 'a') do |f|
36-
f.puts tag_line
37-
end
34+
lines = File.exist?(tags_file) ? File.readlines(tags_file, chomp: true) : []
35+
unless lines.include?(tag_line)
36+
File.write(tags_file, (lines + [tag_line]).join("\n") + "\n")
3837
end
3938
}

0 commit comments

Comments
 (0)