Class: M::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/m/parser.rb

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ Parser

Returns a new instance of Parser.



5
6
7
8
# File 'lib/m/parser.rb', line 5

def initialize argv
  @argv = argv
  @testable = Testable.new
end

Instance Method Details

#parseObject



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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/m/parser.rb', line 10

def parse
  # With no arguments,
  if argv.empty?
    # Just shell out to `rake test`.
    exec "rake test"
  else
    parse_options! argv

    if argv.first.start_with? "--"
      exec "rake test #{argv.join}"
      exit 0
    else
      # Parse out ARGV, it should be coming in in a format like `test/test_file.rb:9:19`
      parsed = argv.shift.split ":"
      testable.file = parsed.shift
      testable.lines = parsed if testable.lines.none?
      # Anything else on ARGV will be passed along to the runner
      testable.passthrough_options = argv
    end

    # If this file is a directory, not a file, run the tests inside of this directory
    return testable unless Dir.exist? testable.file

    # Make a new rake test task with a hopefully unique name, and run every test looking file in it
    require "rake/testtask"
    Rake::TestTask.new :m_custom do |t|
      t.libs << "test"
      t.libs << "spec"
      t.test_files = FileList[wildcard("test"), wildcard("spec")]
      t.warning = false
    end
    # Invoke the rake task and exit, hopefully it'll work!
    begin
      Rake::Task["m_custom"].invoke
    rescue RuntimeError
      exit 1
    ensure
      exit $?.exitstatus
    end

  end
end