summaryrefslogtreecommitdiff
path: root/spec/mspec/tool
diff options
context:
space:
mode:
authorBenoit Daloze <eregontp@gmail.com>2019-04-27 18:53:20 +0200
committerBenoit Daloze <eregontp@gmail.com>2019-04-27 18:53:20 +0200
commit00c33d9c232ed1a79eda17acd7231ac93caa162b (patch)
treea027a2e87b5e719e3556adb8f0605e16ac6352e8 /spec/mspec/tool
parent80be9e986b81d1e50433005f6b91f4cd0c1c0939 (diff)
Update to ruby/mspec@18c5a7d
Diffstat (limited to 'spec/mspec/tool')
-rw-r--r--spec/mspec/tool/remove_old_guards.rb34
-rw-r--r--spec/mspec/tool/sync/sync-rubyspec.rb7
-rw-r--r--spec/mspec/tool/tag_from_output.rb39
3 files changed, 73 insertions, 7 deletions
diff --git a/spec/mspec/tool/remove_old_guards.rb b/spec/mspec/tool/remove_old_guards.rb
index 8b036d07f5..d6ed619d98 100644
--- a/spec/mspec/tool/remove_old_guards.rb
+++ b/spec/mspec/tool/remove_old_guards.rb
@@ -1,4 +1,6 @@
-# Remove old version guards in ruby/spec
+# Removes old version guards in ruby/spec.
+# Run it from the ruby/spec repository root.
+# The argument is the new minimum supported version.
def dedent(line)
if line.start_with?(" ")
@@ -8,9 +10,13 @@ def dedent(line)
end
end
+def each_spec_file(&block)
+ Dir["*/**/*.rb"].each(&block)
+end
+
def remove_guards(guard, keep)
- Dir["*/**/*.rb"].each do |file|
- contents = File.read(file)
+ each_spec_file do |file|
+ contents = File.binread(file)
if contents =~ guard
puts file
lines = contents.lines.to_a
@@ -31,11 +37,29 @@ def remove_guards(guard, keep)
lines[first..last] = []
end
end
- File.write file, lines.join
+ File.binwrite file, lines.join
+ end
+ end
+end
+
+def search(regexp)
+ each_spec_file do |file|
+ contents = File.binread(file)
+ if contents =~ regexp
+ puts file
+ contents.each_line do |line|
+ if line =~ regexp
+ puts line
+ end
+ end
end
end
end
-version = (ARGV[0] || "2.3")
+version = Regexp.escape(ARGV.fetch(0))
remove_guards(/ruby_version_is ["']#{version}["'] do/, true)
remove_guards(/ruby_version_is ["'][0-9.]*["']...["']#{version}["'] do/, false)
+remove_guards(/ruby_bug "#\d+", ["'][0-9.]*["']...["']#{version}["'] do/, true)
+
+search(/["']#{version}["']/)
+search(/^\s*#.+#{version}/)
diff --git a/spec/mspec/tool/sync/sync-rubyspec.rb b/spec/mspec/tool/sync/sync-rubyspec.rb
index e978ea17ec..0a6203e357 100644
--- a/spec/mspec/tool/sync/sync-rubyspec.rb
+++ b/spec/mspec/tool/sync/sync-rubyspec.rb
@@ -18,6 +18,9 @@ IMPLS = {
MSPEC = ARGV.delete('--mspec')
+CHECK_LAST_MERGE = ENV['CHECK_LAST_MERGE'] != 'false'
+TEST_TRUNK = ENV['TEST_TRUNK'] != 'false'
+
MSPEC_REPO = File.expand_path("../../..", __FILE__)
raise MSPEC_REPO if !Dir.exist?(MSPEC_REPO) or !Dir.exist?("#{MSPEC_REPO}/.git")
@@ -144,7 +147,7 @@ def rebase_commits(impl)
commit_date = Time.at(Integer(commit_timestamp))
days_since_last_merge = (NOW-commit_date) / 86400
- if days_since_last_merge > 60
+ if CHECK_LAST_MERGE and days_since_last_merge > 60
raise "#{days_since_last_merge.floor} days since last merge, probably wrong commit"
end
@@ -177,7 +180,7 @@ def test_new_specs
run_test[min_version]
run_test[max_version]
- run_test["trunk"]
+ run_test["trunk"] if TEST_TRUNK
end
end
diff --git a/spec/mspec/tool/tag_from_output.rb b/spec/mspec/tool/tag_from_output.rb
new file mode 100644
index 0000000000..62764c3ff5
--- /dev/null
+++ b/spec/mspec/tool/tag_from_output.rb
@@ -0,0 +1,39 @@
+# Adds tags based on error and failures output (e.g., from a CI log),
+# without running any spec code.
+
+tags_dir = %w[
+ spec/tags
+ spec/tags/ruby
+].find { |dir| Dir.exist?("#{dir}/language") }
+abort 'Could not find tags directory' unless tags_dir
+
+output = ARGF.readlines
+# Remove leading "[exec] " from JRuby logs
+output = output.map { |line| line.sub(/^\[exec\] /, '') }
+
+NUMBER = /^\d+\)$/
+ERROR_OR_FAILED = / (ERROR|FAILED)$/
+SPEC_FILE = /^(\/.+_spec\.rb)\:\d+/
+
+failures = output.slice_before(NUMBER).select { |number, error_line, *rest|
+ number =~ NUMBER and error_line =~ ERROR_OR_FAILED
+}.each { |number, error_line, *rest|
+ description = error_line.match(ERROR_OR_FAILED).pre_match
+
+ spec_file = rest.find { |line| line =~ SPEC_FILE }
+ spec_file = spec_file[SPEC_FILE, 1]
+ prefix = spec_file.index('spec/ruby')
+ spec_file = spec_file[prefix..-1]
+
+ tags_file = spec_file.sub('spec/ruby/', "#{tags_dir}/").sub(/_spec\.rb$/, '_tags.txt')
+
+ dir = File.dirname(tags_file)
+ Dir.mkdir(dir) unless Dir.exist?(dir)
+
+ tag_line = "fails:#{description}"
+ unless File.exist?(tags_file) and File.readlines(tags_file, chomp: true).include?(tag_line)
+ File.open(tags_file, 'a') do |f|
+ f.puts tag_line
+ end
+ end
+}