Module: Test::Unit::GlobOption

Includes:
Options
Included in:
Runner
Defined in:
lib/test/unit.rb

Constant Summary collapse

@@testfile_prefix =
"test"

Instance Method Summary collapse

Methods included from Options

#initialize, #option_parser, #process_args

Instance Method Details

#non_options(files, options) ⇒ Object



141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# File 'lib/test/unit.rb', line 141

def non_options(files, options)
  paths = [options.delete(:base_directory), nil].uniq
  if reject = options.delete(:reject)
    reject_pat = Regexp.union(reject.map {|r| /#{r}/ })
  end
  files.map! {|f|
    f = f.tr(File::ALT_SEPARATOR, File::SEPARATOR) if File::ALT_SEPARATOR
    ((paths if /\A\.\.?(?:\z|\/)/ !~ f) || [nil]).any? do |prefix|
      if prefix
        path = f.empty? ? prefix : "#{prefix}/#{f}"
      else
        next if f.empty?
        path = f
      end
      if !(match = Dir["#{path}/**/#{@@testfile_prefix}_*.rb"]).empty?
        if reject
          match.reject! {|n|
            n[(prefix.length+1)..-1] if prefix
            reject_pat =~ n
          }
        end
        break match
      elsif !reject or reject_pat !~ f and File.exist? path
        break path
      end
    end or
      raise ArgumentError, "file not found: #{f}"
  }
  files.flatten!
  super(files, options)
end

#setup_options(parser, options) ⇒ Object



131
132
133
134
135
136
137
138
139
# File 'lib/test/unit.rb', line 131

def setup_options(parser, options)
  super
  parser.on '-b', '--basedir=DIR', 'Base directory of test suites.' do |dir|
    options[:base_directory] = dir
  end
  parser.on '-x', '--exclude PATTERN', 'Exclude test files on pattern.' do |pattern|
    (options[:reject] ||= []) << pattern
  end
end