diff options
author | Benoit Daloze <eregontp@gmail.com> | 2019-04-27 18:53:20 +0200 |
---|---|---|
committer | Benoit Daloze <eregontp@gmail.com> | 2019-04-27 18:53:20 +0200 |
commit | 00c33d9c232ed1a79eda17acd7231ac93caa162b (patch) | |
tree | a027a2e87b5e719e3556adb8f0605e16ac6352e8 /spec/mspec/tool/remove_old_guards.rb | |
parent | 80be9e986b81d1e50433005f6b91f4cd0c1c0939 (diff) |
Update to ruby/mspec@18c5a7d
Diffstat (limited to 'spec/mspec/tool/remove_old_guards.rb')
-rw-r--r-- | spec/mspec/tool/remove_old_guards.rb | 34 |
1 files changed, 29 insertions, 5 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}/) |