Class: SimpleTestRunner::TestRunner

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

Overview

Top-level class

Instance Method Summary collapse

Constructor Details

#initialize(args = []) ⇒ TestRunner

Initialized gets passed ARGv



15
16
17
# File 'lib/simple_test_runner/simple_test_runner.rb', line 15

def initialize args = []
  @args = args
end

Instance Method Details

#make_config_fileObject

Make a config file. Currently not used. I was planning on using a config file for directories to monitor and the command to run. But at the moment everything goes on the command line, and I think that’s simpler. But I’m leaving the config file functions in the code, in case I decide to pick them up again.



68
69
70
71
72
73
74
75
76
77
# File 'lib/simple_test_runner/simple_test_runner.rb', line 68

def make_config_file
  if File.exists? @options.config_file_name
    puts "Are you sure? (y for yes)"
    a = gets.strip.downcase
    return unless a == "y"
  end
  File.open(@options.config_file_name, 'w+') do |file| 
    file.puts @options.to_yaml
  end
end

#runObject

This is the function that runs everything.



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
52
53
54
55
56
57
58
59
# File 'lib/simple_test_runner/simple_test_runner.rb', line 20

def run
  if not running_linux?
    puts "Sorry. This program currently only runs in Linux."
    puts "If you want other platforms to be supported, please help out!"
    return
  end

  @options = RunnerOpts.new @args
  if @options.parsed.make_config_file
    make_config_file
    return
  end
  # unless @options.configfileok
  #   puts "Couldn't find the configuration file."
  #   puts "  The config file is where you place the command that"
  #   puts "  you want the program to run."
  #   puts
  #   puts "  It should be a text file called .simpletestrunnerrc."
  #   puts "  To generate the file, run 'simpletestrunner -c'"
  #   puts "  then edit it by hand."
  #   return
  # end
  unless @options.parsed.ok
    @options.print_usage
    return
  end

  if @options.parsed.show_config
    @options.show_config
  end

  if not @options.parsed.fake
    if @options.parsed.dirs_to_monitor.length > 0
      setup_monitor 
      while not STDIN.ready?
        @notifier.process
      end
    end
  end
end

#run_commandObject

Run the command that was specified on the command line.



96
97
98
# File 'lib/simple_test_runner/simple_test_runner.rb', line 96

def run_command
    system "#{@options.parsed.command_str}"
end

#running_linux?Boolean

Are we running on Linux? returns true or false The program currently only supports Linux.

Returns:

  • (Boolean)


82
83
84
# File 'lib/simple_test_runner/simple_test_runner.rb', line 82

def running_linux?
  /linux/i === RbConfig::CONFIG["host_os"]
end

#setup_monitorObject

Set up the INotify::Notifier object to watch for changes to the target dirs.



88
89
90
91
92
93
# File 'lib/simple_test_runner/simple_test_runner.rb', line 88

def setup_monitor
  @notifier = INotify::Notifier.new
  @options.parsed.dirs_to_monitor.each do |dir|
    foo = @notifier.watch(dir, :modify, :recursive) { run_command }
  end
end