Skip to content

Commit 94d4b13

Browse files
committed
Add -C and -R chdir options.
1 parent 703ee02 commit 94d4b13

9 files changed

Lines changed: 262 additions & 168 deletions

File tree

.option

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ rubytest
66

77
[coverage]
88
rubytest
9-
-p task/simplecov.rb
9+
-c task/simplecov.rb
1010
test/*_case.rb
1111

HISTORY.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ work. But the whole thing simply got more complicated than it needed to
99
be and it was decided that conventional simplicity, with the option
1010
unconventional complexity, was the best approach.
1111

12-
So, to make a long story short. There is no default config file anymore.
12+
To make a long story short... There is no default config file anymore.
1313
The `-p/--profile` command line option has been removed; replaced by
14-
a `-c/--config` option which simply requires a file relative to the current
15-
project. In addition the configuration API had been changed from `Test.run`
16-
or `Test.configure`, to adopt the common convention. And it no longer takes
14+
a `-c/--config` option which requires a file relative to the working
15+
directory. In addition the configuration API had been changed from `Test.run`
16+
or `Test.configure`, to adopt the common convention, and it no longer takes
1717
a profile name for an argument. `Test.run` still has the same interface as
1818
`Test.configure` but it will now run tests immediately! So be sure to change
1919
that if you used it the past. Lastly, Ruby Test now supports DotOpts out of
@@ -24,6 +24,7 @@ Changes:
2424
* Rename `Test.run` to `Test.configure` and remove profile argument.
2525
* Add new `Test.run` to immediately run tests.
2626
* Add `-c/--config` option for requiring project file.
27+
* Add `-C` and `-R` options for changing directory.
2728
* Add built-in support for DotOpts.
2829
* Deprecate profiles, removing `-p/--profile` cli option.
2930
* Deprecate Test::Runner configuration class methods.

MANIFEST.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ lib/rubytest/reporters/tapy.rb
3131
lib/rubytest/reporters/test.rb
3232
lib/rubytest/runner.rb
3333
lib/rubytest.rb
34+
lib/rubytest.yml
3435
lib/test.rb
3536
test/basic_case.rb
3637
test/helper.rb

README.md

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ reports.
3232
Ruby Test handles assertions with [BRASS](http://rubyworks.github.com/brass)
3333
compliance. Any raised exception that responds to `#assertion?` in the
3434
affirmative is taken to be a failed assertion rather than simply an error.
35-
3635
A test framework may raise a `NotImplementedError` to have a test recorded
3736
as *todo* --a _pending_ exception to remind the developer of tests that still
3837
need to be written. The `NotImplementedError` is a standard Ruby exception
@@ -82,13 +81,23 @@ entry might be:
8281
-r rspecial
8382
spec/spec_*.rb
8483

85-
There is also a Rake task. In your Rakefile,
84+
If you are using a build tool to run your tests, such as Rake or Fire, it is
85+
best to shell out to `rubytest`. This keeps your test environent as prestine
86+
as possible.
87+
88+
desc "run tests"
89+
task :test
90+
sh "rubytest"
91+
end
92+
93+
RubyTest comes with a Rake task plugin, but its use is all but deprecated
94+
because it's basically just a glorified rendition of the above.
8695

8796
require 'rubytest/rake'
8897

89-
Test::Rake::TestTask.new do |run|
90-
require 'lemon'
91-
run.files << 'test/test_*.rb'
98+
Test::Rake::TestTask.new :test do |run|
99+
run.requires << 'lemon'
100+
run.files = 'test/test_*.rb'
92101
end
93102

94103
See the Wiki for more information on the different ways to run tests.

lib/rubytest.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,23 @@
66
#require 'brass' # TODO: Should we require BRASS ?
77
require 'ansi/core'
88

9+
module Test
10+
# Load project index on demand.
11+
def self.index
12+
@index ||= (
13+
require 'yaml'
14+
__dir__ = File.dirname(__FILE__)
15+
file = File.expand_path('rubytest.yml', __dir__)
16+
YAML.load_file(file)
17+
)
18+
end
19+
20+
# Lookup missing constant in project index.
21+
def self.const_missing(name)
22+
index[name.to_s.downcase] || super(name)
23+
end
24+
end
25+
926
if RUBY_VERSION < '1.9'
1027
require 'rubytest/core_ext'
1128
require 'rubytest/code_snippet'

lib/rubytest.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../.index

lib/rubytest/cli.rb

Lines changed: 34 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,15 @@ def self.run(*argv)
1818
# @return nothing
1919
def initialize
2020
require 'optparse'
21+
22+
@config = Test.configuration(true)
2123
end
2224

2325
# Test run configuration.
2426
#
2527
# @return [Config]
2628
def config
27-
@config ||= Test.configuration
29+
@config
2830
end
2931

3032
# Run tests.
@@ -55,6 +57,10 @@ def run(argv=nil)
5557
end
5658
end
5759

60+
def preparse_options(argv)
61+
62+
end
63+
5864
# Setup OptionsParser instance.
5965
#
6066
# @return [OptionParser]
@@ -84,52 +90,58 @@ def options
8490
end
8591

8692
opt.on '-t', '--tag TAG', 'select tests by tag' do |tag|
87-
config.tags.concat enlist(tag)
93+
config.tags.concat makelist(tag)
8894
end
8995
opt.on '-u', '--unit TAG', 'select tests by software unit' do |unit|
90-
config.units.concat enlist(unit)
96+
config.units.concat makelist(unit)
9197
end
9298
opt.on '-m', '--match TEXT', 'select tests by description' do |text|
93-
config.match.concat enlist(text)
99+
config.match.concat makelist(text)
94100
end
95101

96102
opt.on '-A', '--autopath', 'automatically add paths to $LOAD_PATH' do |paths|
97103
config.autopath = true
98104
end
99105
opt.on '-I', '--loadpath PATH', 'add given path to $LOAD_PATH' do |paths|
100-
#enlist(paths).reverse_each do |path|
106+
#makelist(paths).reverse_each do |path|
101107
# $LOAD_PATH.unshift path
102108
#end
103-
config.loadpath.concat enlist(paths)
109+
config.loadpath.concat makelist(paths)
110+
end
111+
opt.on '-C', '--chdir DIR', 'change directory before running tests' do |dir|
112+
config.chdir = dir
113+
end
114+
opt.on '-R', '--chroot', 'change to project root directory before running tests' do
115+
config.chdir = Config.root
104116
end
105-
#opt.on '-C', '--chdir DIR', 'change directory before running tests' do |dir|
106-
# config.chdir = dir
107-
#end
108-
#opt.on '-R', '--chroot', 'change to project root directory before running tests' do |bool|
109-
# config.chroot = bool
110-
#end
111117
opt.on '-r', '--require FILE', 'require file' do |file|
112118
#require file
113-
config.requires.concat pathlist(file)
119+
config.requires.concat makelist(file)
114120
end
115121
opt.on '-c', '--config FILE', "require local config file (immediately)" do |file|
116-
Config.require_config(file)
122+
config.load_config(file)
117123
end
118124
opt.on '-V' , '--verbose', 'provide extra detail in reports' do
119125
config.verbose = true
120126
end
121-
#opt.on('--log DIRECTORY', 'log directory'){ |dir|
122-
# options[:log] = dir
127+
#opt.on('--log PATH', 'log test output to path'){ |path|
128+
# config.log = path
123129
#}
124130
opt.on("--[no-]ansi" , 'turn on/off ANSI colors'){ |v| $ansi = v }
125131
opt.on("--debug" , 'turn on debugging mode'){ $DEBUG = true }
126132

127133
#opt.separator "COMMAND OPTIONS:"
128-
#opt.on("--about" , 'display information about rubytest'){
129-
# puts "Ruby Test v#{VERSION}"
130-
# puts "#{COPYRIGHT}"
131-
# exit
132-
#}
134+
opt.on('--about' , 'display information about rubytest') do
135+
puts "Ruby Test v%s" % [Test.index['version']]
136+
Test.index['copyrights'].each do |c|
137+
puts "(c) %s %s (%s)" % c.values_at('year', 'holder', 'license')
138+
end
139+
exit
140+
end
141+
opt.on('--version' , 'display rubytest version') do
142+
puts Test::VERSION
143+
exit
144+
end
133145
opt.on('-h', '--help', 'display this help message'){
134146
puts opt
135147
exit
@@ -142,7 +154,7 @@ def options
142154
# all strings and not empty.
143155
#
144156
# @return [Array<String>]
145-
def enlist(list)
157+
def makelist(list)
146158
case list
147159
when String
148160
list = list.split(/[:;]/)

0 commit comments

Comments
 (0)