File: check_require_spec_helper.rb

package info (click to toggle)
ruby3.4 3.4.9-1~exp1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 152,040 kB
  • sloc: ruby: 1,262,509; ansic: 831,188; yacc: 28,233; pascal: 7,359; sh: 3,910; python: 1,799; cpp: 1,158; makefile: 827; asm: 808; javascript: 414; lisp: 109; perl: 62; awk: 36; xml: 4; sed: 4
file content (34 lines) | stat: -rwxr-xr-x 967 bytes parent folder | download | duplicates (5)
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
#!/usr/bin/env ruby

# This script is used to check that each *_spec.rb file has
# a relative_require for spec_helper which should live higher
# up in the ruby/spec repo directory tree.
#
# Prints errors to $stderr and returns a non-zero exit code when
# errors are found.
#
# Related to https://github.com/ruby/spec/pull/992

def check_file(fn)
  File.foreach(fn) do |line|
    return $1 if line =~ /^\s*require_relative\s*['"](.*spec_helper)['"]/
  end
  nil
end

rootdir = ARGV[0] || "."
fglob = File.join(rootdir, "**", "*_spec.rb")
specfiles = Dir.glob(fglob)
raise "No spec files found in #{fglob.inspect}. Give an argument to specify the root-directory of ruby/spec" if specfiles.empty?

errors = 0
specfiles.sort.each do |fn|
  result = check_file(fn)
  if result.nil?
    warn "Missing require_relative for *spec_helper for file: #{fn}"
    errors += 1
  end
end

puts "# Found #{errors} files with require_relative spec_helper issues."
exit 1 if errors > 0