File: check_require_spec_helper.rb

package info (click to toggle)
ruby3.3 3.3.8-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 153,620 kB
  • sloc: ruby: 1,244,308; ansic: 836,474; yacc: 28,074; pascal: 6,748; sh: 3,913; python: 1,719; cpp: 1,158; makefile: 742; asm: 712; javascript: 394; lisp: 97; perl: 62; awk: 36; sed: 23; xml: 4
file content (34 lines) | stat: -rwxr-xr-x 967 bytes parent folder | download | duplicates (4)
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