simple_test_runner 0.6.0-x86-linux
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +5 -0
- data/.rvmrc +1 -0
- data/Gemfile +4 -0
- data/README.md +64 -0
- data/Rakefile +2 -0
- data/bin/simple_test_runner +10 -0
- data/lib/runner_opts.rb +123 -0
- data/lib/simple_test_runner/version.rb +3 -0
- data/lib/simple_test_runner.rb +94 -0
- data/simple_test_runner.gemspec +23 -0
- metadata +86 -0
data/.gitignore
ADDED
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm gemset use 'simple_test_runner'
|
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
# simple_test_runner is a very simple replacement for autotest.
|
2
|
+
|
3
|
+
## Using simple_test_runner
|
4
|
+
|
5
|
+
Running simple_test_runner without any options will print out this message:
|
6
|
+
|
7
|
+
Usage: simple_test_runner [options]
|
8
|
+
-c, --command COMMAND Command to run
|
9
|
+
-d, --dirs x,y,z example 'list' of arguments
|
10
|
+
-f, --fake Fake run: don't actually monitor the dirs
|
11
|
+
-h, --help Print out this message
|
12
|
+
-s, --show Show the current configuration
|
13
|
+
|
14
|
+
|
15
|
+
So, to run all specs when files in the app/ or lib/ directories are updated:
|
16
|
+
|
17
|
+
simple_test_runner -d app,lib -c "rspec spec"
|
18
|
+
|
19
|
+
|
20
|
+
## But why?
|
21
|
+
|
22
|
+
"But why?" I hear you ask.
|
23
|
+
|
24
|
+
Autotest is great. But ... it can be overkill. And it polls your files for changes. Every second. Yes, with extra helpers it can run without polling. But then there's the configuration.
|
25
|
+
|
26
|
+
And the configuration is ... touchy. Unseen things lurk in the background. Doing things for you. "Helping" you.
|
27
|
+
|
28
|
+
After hours of tracking down scattered documentation for obscure bugs, after walking through autotest's source code to identify just where the hell it was doing things and what it was doing, I snapped.
|
29
|
+
|
30
|
+
And I wrote this.
|
31
|
+
|
32
|
+
The idea is to keep it simple. You tell testRuner which directories to watch for changes, and what command to run when changes happen. And that's all.
|
33
|
+
|
34
|
+
Any time a file in the watched directory changes, the command is run.
|
35
|
+
|
36
|
+
To quit, type control-c in the terminal running the program, and wait for the next directory change to wake it up. Kinda klunky, I know. If anyone knows a better way to handle it, I'm all ears.
|
37
|
+
|
38
|
+
## Installation
|
39
|
+
|
40
|
+
* Get
|
41
|
+
|
42
|
+
git clone git://github.com/Jeff-R/simple_test_runner.git
|
43
|
+
|
44
|
+
* Build
|
45
|
+
|
46
|
+
cd simple_test_runner
|
47
|
+
rake build
|
48
|
+
|
49
|
+
* Install (with rvm)
|
50
|
+
|
51
|
+
rvm use gemset global
|
52
|
+
rake install
|
53
|
+
|
54
|
+
* Install (without rvm)
|
55
|
+
|
56
|
+
sudo gem install pkg/simple_test_runner_x.gem
|
57
|
+
|
58
|
+
|
59
|
+
|
60
|
+
## System requirements
|
61
|
+
|
62
|
+
At the moment, simple_test_runner only runs on Linux, because it uses the Linux kernel's INotify feature. I'd love to have it be extended for different platforms, but I'll need help for that.
|
63
|
+
|
64
|
+
|
data/Rakefile
ADDED
data/lib/runner_opts.rb
ADDED
@@ -0,0 +1,123 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
require 'ostruct'
|
3
|
+
require 'yaml'
|
4
|
+
|
5
|
+
module SimpleTestRunner
|
6
|
+
class RunnerOpts
|
7
|
+
def initialize(args, path="")
|
8
|
+
@parsed = OpenStruct.new
|
9
|
+
parse(args)
|
10
|
+
# if not path == ""
|
11
|
+
# @parsed.dirs_to_monitor = ""
|
12
|
+
# end
|
13
|
+
end
|
14
|
+
|
15
|
+
def load_yaml yaml_string
|
16
|
+
yaml = YAML::load(yaml_string)
|
17
|
+
|
18
|
+
@parsed.command = yaml["command"]
|
19
|
+
puts "load_yaml: yaml = #{yaml.inspect}"
|
20
|
+
end
|
21
|
+
|
22
|
+
def to_yaml
|
23
|
+
"command: echo 'hello'"
|
24
|
+
end
|
25
|
+
|
26
|
+
def config_file_name= filename
|
27
|
+
@parsed.config_file_name = filename
|
28
|
+
end
|
29
|
+
|
30
|
+
def parsed= val
|
31
|
+
@parsed = val
|
32
|
+
end
|
33
|
+
|
34
|
+
def parsed
|
35
|
+
@parsed
|
36
|
+
end
|
37
|
+
|
38
|
+
def save_to_file
|
39
|
+
File.open(@parsed.config_file_name, 'w+') do |file|
|
40
|
+
file.puts to_yaml
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def load_config_file
|
45
|
+
yaml = File.new(config_file_name).read
|
46
|
+
load_yaml yaml
|
47
|
+
end
|
48
|
+
|
49
|
+
def config_file_name
|
50
|
+
".simpletestrunnerrc"
|
51
|
+
end
|
52
|
+
|
53
|
+
def configfileok
|
54
|
+
File.exists? config_file_name
|
55
|
+
end
|
56
|
+
|
57
|
+
def print_usage
|
58
|
+
puts @optionParser
|
59
|
+
end
|
60
|
+
|
61
|
+
def show_config
|
62
|
+
puts "Configuration:"
|
63
|
+
puts "config file: \"#{config_file_name}\""
|
64
|
+
puts "dirs to monitor: #{@parsed.dirs_to_monitor.inspect}"
|
65
|
+
puts "command to run: \"#{@parsed.command_str}\""
|
66
|
+
puts "fake run: #{@parsed.fake}"
|
67
|
+
end
|
68
|
+
|
69
|
+
def parse args
|
70
|
+
@parsed.verbose ||= false
|
71
|
+
@parsed.make_config_file ||= false
|
72
|
+
@parsed.show_config ||= false
|
73
|
+
@parsed.dirs_to_monitor ||= []
|
74
|
+
@parsed.ok ||= false
|
75
|
+
@parsed.command_str ||= "echo 'Dir changed'"
|
76
|
+
@parsed.fake ||= false
|
77
|
+
|
78
|
+
@optionParser = OptionParser.new do |opts|
|
79
|
+
opts.banner = "Usage: simple_test_runner [options]"
|
80
|
+
|
81
|
+
# Command to run
|
82
|
+
opts.on("-c", "--command COMMAND", String, "Command to run") do |commandstr|
|
83
|
+
@parsed.command_str = commandstr
|
84
|
+
@parsed.ok = true
|
85
|
+
end
|
86
|
+
|
87
|
+
# Create a config file
|
88
|
+
# opts.on("-C", "--configfile", "create a config file") do
|
89
|
+
# @parsed.make_config_file = true
|
90
|
+
# @parsed.ok = true
|
91
|
+
# end
|
92
|
+
|
93
|
+
# List of dirs.
|
94
|
+
opts.on("-d", "--dirs x,y,z", Array, "example 'list' of arguments") do |list|
|
95
|
+
@parsed.dirs_to_monitor = list
|
96
|
+
@parsed.ok = true
|
97
|
+
end
|
98
|
+
|
99
|
+
# fake run
|
100
|
+
opts.on("-f", "--fake", "Fake run: don't actually monitor the dirs") do
|
101
|
+
@parsed.fake = true
|
102
|
+
end
|
103
|
+
|
104
|
+
# show help
|
105
|
+
opts.on('-h', "--help", "Print out this message") do |url|
|
106
|
+
puts opts
|
107
|
+
@parsed.ok = true
|
108
|
+
end
|
109
|
+
|
110
|
+
# Show configuration
|
111
|
+
opts.on('-s', '--show', 'Show the current configuration') do |password|
|
112
|
+
@parsed.show_config = true
|
113
|
+
@parsed.ok = true
|
114
|
+
end
|
115
|
+
|
116
|
+
end
|
117
|
+
|
118
|
+
@optionParser.parse!(args)
|
119
|
+
@parsed
|
120
|
+
end
|
121
|
+
|
122
|
+
end
|
123
|
+
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
#!/home/jeff/.rvm/rubies/ruby-1.9.2-p0/bin/ruby
|
2
|
+
require "rubygems"
|
3
|
+
require "bundler/setup"
|
4
|
+
require_relative 'runner_opts'
|
5
|
+
require 'rb-inotify'
|
6
|
+
|
7
|
+
require 'io/wait' # for io.ready?
|
8
|
+
|
9
|
+
# Bundler.require # See http://technotales.wordpress.com/2010/08/22/bundler-without-rails/
|
10
|
+
|
11
|
+
# code originally swiped shamelessly from https://github.com/ewollesen/autotest-inotify/blob/master/lib/autotest/inotify.rb
|
12
|
+
# Mostly morphed since then ...
|
13
|
+
|
14
|
+
module SimpleTestRunner
|
15
|
+
|
16
|
+
class TestRunner
|
17
|
+
|
18
|
+
def initialize args = []
|
19
|
+
@args = args
|
20
|
+
end
|
21
|
+
|
22
|
+
def make_config_file
|
23
|
+
if File.exists? @options.config_file_name
|
24
|
+
puts "Are you sure? (y for yes)"
|
25
|
+
a = gets.strip.downcase
|
26
|
+
return unless a == "y"
|
27
|
+
end
|
28
|
+
File.open(@options.config_file_name, 'w+') do |file|
|
29
|
+
file.puts @options.to_yaml
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def run
|
34
|
+
if not running_linux?
|
35
|
+
puts "Sorry. This program currently only runs in Linux."
|
36
|
+
puts "If you want other platforms to be supported, please help out!"
|
37
|
+
return
|
38
|
+
end
|
39
|
+
|
40
|
+
@options = RunnerOpts.new @args
|
41
|
+
if @options.parsed.make_config_file
|
42
|
+
make_config_file
|
43
|
+
return
|
44
|
+
end
|
45
|
+
# unless @options.configfileok
|
46
|
+
# puts "Couldn't find the configuration file."
|
47
|
+
# puts " The config file is where you place the command that"
|
48
|
+
# puts " you want the program to run."
|
49
|
+
# puts
|
50
|
+
# puts " It should be a text file called .simpletestrunnerrc."
|
51
|
+
# puts " To generate the file, run 'simpletestrunner -c'"
|
52
|
+
# puts " then edit it by hand."
|
53
|
+
# return
|
54
|
+
# end
|
55
|
+
unless @options.parsed.ok
|
56
|
+
@options.print_usage
|
57
|
+
return
|
58
|
+
end
|
59
|
+
|
60
|
+
if @options.parsed.show_config
|
61
|
+
@options.show_config
|
62
|
+
end
|
63
|
+
|
64
|
+
if not @options.parsed.fake
|
65
|
+
if @options.parsed.dirs_to_monitor.length > 0
|
66
|
+
setup_monitor
|
67
|
+
while not STDIN.ready?
|
68
|
+
@notifier.process
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def running_linux?
|
75
|
+
/linux/i === RbConfig::CONFIG["host_os"]
|
76
|
+
end
|
77
|
+
|
78
|
+
def setup_monitor
|
79
|
+
@notifier = INotify::Notifier.new
|
80
|
+
@options.parsed.dirs_to_monitor.each do |dir|
|
81
|
+
foo = @notifier.watch(dir, :modify, :recursive) { run_command }
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def event_of_interest?(flags)
|
86
|
+
flags.include?(:modify) || flags.include?(:moved_to)
|
87
|
+
end
|
88
|
+
|
89
|
+
def run_command
|
90
|
+
system "#{@options.parsed.command_str}"
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|
94
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "simple_test_runner/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "simple_test_runner"
|
7
|
+
s.version = SimpleTestRunner::VERSION
|
8
|
+
s.platform = Gem::Platform::CURRENT
|
9
|
+
s.authors = ["Jeff Roush"]
|
10
|
+
s.email = ["jeff@jeffroush.com"]
|
11
|
+
s.homepage = "https://github.com/Jeff-R/simple_test_runner"
|
12
|
+
s.summary = %q{Monitors directories; runs a command when it sees a change.}
|
13
|
+
s.description = %q{Very simple command-line program for Linux to monitor directories and run tests.}
|
14
|
+
|
15
|
+
s.rubyforge_project = "simple_test_runner"
|
16
|
+
|
17
|
+
s.add_dependency 'rb-inotify'
|
18
|
+
|
19
|
+
s.files = `git ls-files`.split("\n")
|
20
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
21
|
+
s.executables = ["simple_test_runner"]
|
22
|
+
s.require_paths = ["lib"]
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: simple_test_runner
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 6
|
8
|
+
- 0
|
9
|
+
version: 0.6.0
|
10
|
+
platform: x86-linux
|
11
|
+
authors:
|
12
|
+
- Jeff Roush
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2011-03-15 00:00:00 -07:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: rb-inotify
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
segments:
|
29
|
+
- 0
|
30
|
+
version: "0"
|
31
|
+
type: :runtime
|
32
|
+
version_requirements: *id001
|
33
|
+
description: Very simple command-line program for Linux to monitor directories and run tests.
|
34
|
+
email:
|
35
|
+
- jeff@jeffroush.com
|
36
|
+
executables:
|
37
|
+
- simple_test_runner
|
38
|
+
extensions: []
|
39
|
+
|
40
|
+
extra_rdoc_files: []
|
41
|
+
|
42
|
+
files:
|
43
|
+
- .gitignore
|
44
|
+
- .rvmrc
|
45
|
+
- Gemfile
|
46
|
+
- README.md
|
47
|
+
- Rakefile
|
48
|
+
- bin/simple_test_runner
|
49
|
+
- lib/runner_opts.rb
|
50
|
+
- lib/simple_test_runner.rb
|
51
|
+
- lib/simple_test_runner/version.rb
|
52
|
+
- simple_test_runner.gemspec
|
53
|
+
has_rdoc: true
|
54
|
+
homepage: https://github.com/Jeff-R/simple_test_runner
|
55
|
+
licenses: []
|
56
|
+
|
57
|
+
post_install_message:
|
58
|
+
rdoc_options: []
|
59
|
+
|
60
|
+
require_paths:
|
61
|
+
- lib
|
62
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
63
|
+
none: false
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
segments:
|
68
|
+
- 0
|
69
|
+
version: "0"
|
70
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
71
|
+
none: false
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
segments:
|
76
|
+
- 0
|
77
|
+
version: "0"
|
78
|
+
requirements: []
|
79
|
+
|
80
|
+
rubyforge_project: simple_test_runner
|
81
|
+
rubygems_version: 1.3.7
|
82
|
+
signing_key:
|
83
|
+
specification_version: 3
|
84
|
+
summary: Monitors directories; runs a command when it sees a change.
|
85
|
+
test_files: []
|
86
|
+
|