rcomp 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/{CHANGELOG.rdoc → CHANGELOG.md} +10 -3
- data/Gemfile.lock +1 -1
- data/README.md +1 -1
- data/features/generate.feature +5 -3
- data/features/test.feature +32 -5
- data/lib/rcomp.rb +1 -1
- data/lib/rcomp/actions.rb +1 -3
- data/lib/rcomp/cli.rb +9 -12
- data/lib/rcomp/conf.rb +2 -3
- data/lib/rcomp/{initializer.rb → env.rb} +7 -6
- data/lib/rcomp/path.rb +1 -16
- data/lib/rcomp/process.rb +5 -3
- data/lib/rcomp/reporter.rb +134 -29
- data/lib/rcomp/runner.rb +56 -29
- data/lib/rcomp/suite.rb +6 -3
- data/lib/rcomp/test.rb +39 -6
- data/lib/rcomp/version.rb +1 -1
- data/rcomp.gemspec +2 -2
- metadata +6 -7
@@ -1,4 +1,11 @@
|
|
1
|
-
|
1
|
+
# 0.2.1, released 2012-11-28
|
2
|
+
|
3
|
+
* Overhaul default output
|
4
|
+
* Add output highlighting
|
5
|
+
* More descriptive output for test failure
|
6
|
+
* Explanations: why tests were skipped by test or generate
|
7
|
+
|
8
|
+
# 0.2.0, released 2012-11-25
|
2
9
|
|
3
10
|
* Add "ignore" configuration option
|
4
11
|
* Add "timeout" configuration option
|
@@ -6,11 +13,11 @@
|
|
6
13
|
* Remove "set-directory"
|
7
14
|
* Upgrade "init" to handle command setting when neccessary
|
8
15
|
|
9
|
-
|
16
|
+
# 0.1.1, released 2012-11-20
|
10
17
|
|
11
18
|
* Ignore dotfiles in tests directory
|
12
19
|
* Clean up generate output, remove remnant debugging output
|
13
20
|
|
14
|
-
|
21
|
+
# 0.1.0, released 2012-11-20
|
15
22
|
|
16
23
|
* Initial release
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
data/features/generate.feature
CHANGED
@@ -62,7 +62,9 @@ Feature: Generate
|
|
62
62
|
|
63
63
|
"""
|
64
64
|
When I run `rcomp generate`
|
65
|
-
Then the output should contain "1 file
|
65
|
+
Then the output should contain "Skipped 1 file"
|
66
|
+
And the output should contain "Run rcomp generate -O"
|
67
|
+
And the output should contain "1 file (1 skipped)"
|
66
68
|
And the file "rcomp/expected/test1.out" should contain "DEF"
|
67
69
|
And the exit status should be 0
|
68
70
|
|
@@ -324,7 +326,7 @@ Feature: Generate
|
|
324
326
|
"""
|
325
327
|
When I run `rcomp generate` for up to 6 seconds
|
326
328
|
Then the output should contain "1 file (1 failed)"
|
327
|
-
And the output should contain "timeout :
|
329
|
+
And the output should contain "timeout : test1.test"
|
328
330
|
And the exit status should be 1
|
329
331
|
|
330
332
|
@loop-conf
|
@@ -341,5 +343,5 @@ Feature: Generate
|
|
341
343
|
"""
|
342
344
|
When I run `rcomp generate` for up to 2 seconds
|
343
345
|
Then the output should contain "1 file (1 failed)"
|
344
|
-
And the output should contain "timeout :
|
346
|
+
And the output should contain "timeout : test1.test"
|
345
347
|
And the exit status should be 1
|
data/features/test.feature
CHANGED
@@ -61,7 +61,9 @@ Feature: Test
|
|
61
61
|
|
62
62
|
"""
|
63
63
|
When I run `rcomp test`
|
64
|
-
Then the output should contain "1 test
|
64
|
+
Then the output should contain "Skipped 1 test"
|
65
|
+
And the output should contain "Run rcomp generate"
|
66
|
+
And the output should contain "1 test (1 skipped)"
|
65
67
|
And the exit status should be 0
|
66
68
|
|
67
69
|
@basic-conf
|
@@ -77,7 +79,8 @@ Feature: Test
|
|
77
79
|
|
78
80
|
"""
|
79
81
|
When I run `rcomp test`
|
80
|
-
Then the output should contain "
|
82
|
+
Then the output should contain "failed : test1.test (out)"
|
83
|
+
And the output should contain "1 test (1 failed)"
|
81
84
|
And the exit status should be 1
|
82
85
|
|
83
86
|
# stdout multiple tests
|
@@ -118,7 +121,8 @@ Feature: Test
|
|
118
121
|
|
119
122
|
"""
|
120
123
|
When I run `rcomp test`
|
121
|
-
Then the output should contain "
|
124
|
+
Then the output should contain "failed : test1.test (err)"
|
125
|
+
And the output should contain "1 test (1 failed)"
|
122
126
|
And the exit status should be 1
|
123
127
|
|
124
128
|
# stderr multiple tests
|
@@ -129,6 +133,29 @@ Feature: Test
|
|
129
133
|
Then the output should contain "3 tests (1 failed, 1 skipped, 1 passed)"
|
130
134
|
And the exit status should be 1
|
131
135
|
|
136
|
+
# stderr + stdout tests
|
137
|
+
@basic-conf
|
138
|
+
Scenario: Single test, failing both err and out
|
139
|
+
Given a file named "rcomp/tests/test1.test" with:
|
140
|
+
"""
|
141
|
+
ABC
|
142
|
+
|
143
|
+
"""
|
144
|
+
And a file named "rcomp/expected/test1.out" with:
|
145
|
+
"""
|
146
|
+
XYZ
|
147
|
+
|
148
|
+
"""
|
149
|
+
And a file named "rcomp/expected/test1.err" with:
|
150
|
+
"""
|
151
|
+
XYZ
|
152
|
+
|
153
|
+
"""
|
154
|
+
When I run `rcomp test`
|
155
|
+
Then the output should contain "failed : test1.test (out, err)"
|
156
|
+
And the output should contain "1 test (1 failed)"
|
157
|
+
And the exit status should be 1
|
158
|
+
|
132
159
|
# alias
|
133
160
|
@basic-conf
|
134
161
|
@load-assorted-tests
|
@@ -274,7 +301,7 @@ Feature: Test
|
|
274
301
|
"""
|
275
302
|
When I run `rcomp test` for up to 6 seconds
|
276
303
|
Then the output should contain "1 test (1 failed)"
|
277
|
-
And the output should contain "timeout :
|
304
|
+
And the output should contain "timeout : test1.test"
|
278
305
|
And the exit status should be 1
|
279
306
|
|
280
307
|
@loop-conf
|
@@ -296,5 +323,5 @@ Feature: Test
|
|
296
323
|
"""
|
297
324
|
When I run `rcomp test` for up to 2 seconds
|
298
325
|
Then the output should contain "1 test (1 failed)"
|
299
|
-
And the output should contain "timeout :
|
326
|
+
And the output should contain "timeout : test1.test"
|
300
327
|
And the exit status should be 1
|
data/lib/rcomp.rb
CHANGED
data/lib/rcomp/actions.rb
CHANGED
data/lib/rcomp/cli.rb
CHANGED
@@ -4,9 +4,6 @@ module RComp
|
|
4
4
|
class CLI < Thor
|
5
5
|
|
6
6
|
include Thor::Actions
|
7
|
-
include RComp::Runner
|
8
|
-
include RComp::Suite
|
9
|
-
include RComp::Initializer
|
10
7
|
|
11
8
|
def initialize(args=[], options={}, config={})
|
12
9
|
super
|
@@ -20,13 +17,13 @@ module RComp
|
|
20
17
|
|
21
18
|
desc "init", "Setup rcomp test directory"
|
22
19
|
def init
|
23
|
-
guard_initialized
|
20
|
+
Env.guard_initialized
|
24
21
|
|
25
|
-
unless command_exists?
|
22
|
+
unless Env.command_exists?
|
26
23
|
@conf.set_command(ask("Enter the command you want to test:"))
|
27
24
|
end
|
28
25
|
|
29
|
-
initialize_directories
|
26
|
+
Env.initialize_directories
|
30
27
|
puts "RComp successfully initialized"
|
31
28
|
end
|
32
29
|
|
@@ -44,11 +41,11 @@ module RComp
|
|
44
41
|
:type => :string,
|
45
42
|
:desc => "Only test files that match pattern"
|
46
43
|
def test
|
47
|
-
guard_uninitialized
|
44
|
+
Env.guard_uninitialized
|
48
45
|
if @options[:grep]
|
49
|
-
|
46
|
+
Runner.run(Suite.load(@options[:grep]), :test)
|
50
47
|
else
|
51
|
-
|
48
|
+
Runner.run(Suite.load, :test)
|
52
49
|
end
|
53
50
|
end
|
54
51
|
|
@@ -65,7 +62,7 @@ module RComp
|
|
65
62
|
:aliases => "-O",
|
66
63
|
:desc => "Overwrite expected output file for test if present"
|
67
64
|
def generate
|
68
|
-
guard_uninitialized
|
65
|
+
Env.guard_uninitialized
|
69
66
|
|
70
67
|
# Display confirmation dialouge when -O is passed without filter
|
71
68
|
if !@options[:grep] && options.overwrite
|
@@ -76,9 +73,9 @@ module RComp
|
|
76
73
|
end
|
77
74
|
|
78
75
|
if @options[:grep]
|
79
|
-
|
76
|
+
Runner.run(Suite.load(@options[:grep]), :generate, @options)
|
80
77
|
else
|
81
|
-
|
78
|
+
Runner.run(Suite.load, :generate, @options)
|
82
79
|
end
|
83
80
|
end
|
84
81
|
|
data/lib/rcomp/conf.rb
CHANGED
@@ -34,8 +34,7 @@ module RComp
|
|
34
34
|
|
35
35
|
# Load configuration values into attributes
|
36
36
|
@command = @conf['command']
|
37
|
-
@ignore = @conf['ignore']
|
38
|
-
@ignore ||= []
|
37
|
+
@ignore = @conf['ignore'] || []
|
39
38
|
@timeout = @conf['timeout']
|
40
39
|
@root = @conf['directory']
|
41
40
|
@test_root = @root + '/tests'
|
@@ -58,7 +57,7 @@ module RComp
|
|
58
57
|
#
|
59
58
|
# Returns nothing
|
60
59
|
def write_conf_file
|
61
|
-
touch CONF_PATH
|
60
|
+
touch CONF_PATH
|
62
61
|
conf_file = File.open(CONF_PATH, 'w')
|
63
62
|
conf_file.puts YAML.dump @custom
|
64
63
|
end
|
@@ -1,7 +1,8 @@
|
|
1
1
|
module RComp
|
2
|
-
module
|
2
|
+
module Env
|
3
3
|
|
4
|
-
|
4
|
+
extend self
|
5
|
+
extend Actions
|
5
6
|
|
6
7
|
@@conf = Conf.instance
|
7
8
|
|
@@ -33,9 +34,7 @@ module RComp
|
|
33
34
|
mkdir @@conf.expected_root
|
34
35
|
mkdir @@conf.result_root
|
35
36
|
end
|
36
|
-
|
37
|
-
private
|
38
|
-
|
37
|
+
|
39
38
|
# Checks for the existance of a command to test with
|
40
39
|
#
|
41
40
|
# Returns a boolean
|
@@ -43,6 +42,8 @@ module RComp
|
|
43
42
|
@@conf.command
|
44
43
|
end
|
45
44
|
|
45
|
+
private
|
46
|
+
|
46
47
|
# Checks for the existance of RComp's root directory
|
47
48
|
#
|
48
49
|
# Returns a boolean
|
@@ -57,7 +58,7 @@ module RComp
|
|
57
58
|
def root_subdirs_exist?
|
58
59
|
File.exists?(@@conf.test_root) &&
|
59
60
|
File.exists?(@@conf.result_root) &&
|
60
|
-
File.exists?(
|
61
|
+
File.exists?(@@conf.expected_root)
|
61
62
|
end
|
62
63
|
|
63
64
|
# Checks to see if RComp is fully initialized
|
data/lib/rcomp/path.rb
CHANGED
@@ -1,23 +1,8 @@
|
|
1
1
|
module RComp
|
2
2
|
module Path
|
3
|
+
|
3
4
|
def rel_path(test_path)
|
4
5
|
test_path.gsub(Conf.instance.test_root, '')
|
5
6
|
end
|
6
|
-
|
7
|
-
def result_path(test_path, type)
|
8
|
-
cmpnts = []
|
9
|
-
cmpnts << Conf.instance.result_root
|
10
|
-
cmpnts << rel_path(File.dirname(test_path))
|
11
|
-
cmpnts << File.basename(test_path, ".*") + (type == :out ? '.out' : '.err')
|
12
|
-
File.join(cmpnts)
|
13
|
-
end
|
14
|
-
|
15
|
-
def expected_path(test_path, type)
|
16
|
-
cmpnts = []
|
17
|
-
cmpnts << Conf.instance.expected_root
|
18
|
-
cmpnts << rel_path(File.dirname(test_path))
|
19
|
-
cmpnts << File.basename(test_path, ".*") + (type == :out ? '.out' : '.err')
|
20
|
-
File.join(cmpnts)
|
21
|
-
end
|
22
7
|
end
|
23
8
|
end
|
data/lib/rcomp/process.rb
CHANGED
@@ -22,15 +22,17 @@ module RComp
|
|
22
22
|
#
|
23
23
|
# Returns nothing
|
24
24
|
def run
|
25
|
-
begin
|
25
|
+
begin
|
26
|
+
@process.start
|
26
27
|
rescue ChildProcess::LaunchError => e
|
27
28
|
raise StandardError.new(e.message)
|
28
29
|
end
|
29
30
|
|
30
|
-
begin
|
31
|
+
begin
|
32
|
+
@process.poll_for_exit(@timeout)
|
31
33
|
rescue ChildProcess::TimeoutError
|
32
34
|
@timedout = true
|
33
|
-
@process.stop
|
35
|
+
@process.stop(@timeout)
|
34
36
|
end
|
35
37
|
end
|
36
38
|
|
data/lib/rcomp/reporter.rb
CHANGED
@@ -1,8 +1,15 @@
|
|
1
|
+
require 'thor'
|
2
|
+
|
1
3
|
module RComp
|
2
4
|
class Reporter
|
3
5
|
|
6
|
+
include Thor::Shell
|
4
7
|
include RComp::Helper
|
5
8
|
|
9
|
+
PADDING = 4
|
10
|
+
GEN_JUSTIFY = 12 + PADDING
|
11
|
+
TEST_JUSTIFY = 10 + PADDING
|
12
|
+
|
6
13
|
# Initialize a new Reporter
|
7
14
|
#
|
8
15
|
# type - The type (Symbol) of the suite
|
@@ -15,64 +22,162 @@ module RComp
|
|
15
22
|
@failed = 0
|
16
23
|
end
|
17
24
|
|
25
|
+
# Main interface for reporting
|
26
|
+
# Reports the result of a single test or generation
|
27
|
+
#
|
28
|
+
# test - A test object that has been run
|
29
|
+
#
|
30
|
+
# Returns nothing
|
18
31
|
def report(test)
|
19
32
|
case test.result
|
20
|
-
# success
|
21
33
|
when :success
|
22
34
|
if @type == :test
|
23
|
-
|
35
|
+
print_test_success(test)
|
24
36
|
else
|
25
|
-
|
37
|
+
print_generate_success(test)
|
26
38
|
end
|
27
39
|
@success += 1
|
28
40
|
|
29
|
-
# skipped
|
30
41
|
when :skipped
|
31
|
-
|
42
|
+
if @type == :test
|
43
|
+
print_test_skipped(test)
|
44
|
+
else
|
45
|
+
print_generate_skipped(test)
|
46
|
+
end
|
32
47
|
@skipped += 1
|
33
48
|
|
34
|
-
#
|
49
|
+
# Generate can't fail directly
|
35
50
|
when :failed
|
36
|
-
|
51
|
+
print_test_failed(test)
|
37
52
|
@failed += 1
|
38
53
|
|
39
|
-
# timedout
|
40
54
|
when :timedout
|
41
|
-
|
55
|
+
if @type == :test
|
56
|
+
print_test_timeout(test)
|
57
|
+
else
|
58
|
+
print_generate_timeout(test)
|
59
|
+
end
|
42
60
|
@failed += 1
|
43
61
|
end
|
44
62
|
end
|
45
63
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
64
|
+
# Prints header for test suite report
|
65
|
+
#
|
66
|
+
# Returns nothing
|
67
|
+
def header
|
68
|
+
# The suite is a test suite
|
69
|
+
if @type == :test
|
70
|
+
puts "RComp: running test suite..."
|
71
|
+
|
72
|
+
# The suite is a generation suite
|
73
|
+
else
|
74
|
+
puts "RComp: generating expected output..."
|
52
75
|
end
|
76
|
+
puts
|
77
|
+
end
|
78
|
+
|
79
|
+
# Prints summary of test suite report
|
80
|
+
#
|
81
|
+
# Returns nothing
|
82
|
+
def summary
|
83
|
+
print_summary
|
53
84
|
exit 1 if @failed > 0
|
54
85
|
end
|
55
86
|
|
56
87
|
private
|
57
88
|
|
58
|
-
def
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
89
|
+
def print_test_success(test)
|
90
|
+
say "passed : ".rjust(TEST_JUSTIFY) + test.formatted_path, :green
|
91
|
+
end
|
92
|
+
|
93
|
+
def print_generate_success(test)
|
94
|
+
say "generated : ".rjust(GEN_JUSTIFY) + test.formatted_path, :green
|
95
|
+
end
|
96
|
+
|
97
|
+
def print_test_skipped(test)
|
98
|
+
say "skipped : ".rjust(TEST_JUSTIFY) + test.formatted_path, :yellow
|
99
|
+
end
|
100
|
+
|
101
|
+
def print_generate_skipped(test)
|
102
|
+
say "skipped : ".rjust(GEN_JUSTIFY) + test.formatted_path, :yellow
|
103
|
+
end
|
104
|
+
|
105
|
+
def print_test_failed(test)
|
106
|
+
msg = "failed : ".rjust(TEST_JUSTIFY) + test.formatted_path
|
107
|
+
|
108
|
+
# both out and err present
|
109
|
+
if test.expected_out_exists? && test.expected_err_exists?
|
110
|
+
# failed both out and err cmp
|
111
|
+
if !test.out_result && !test.err_result
|
112
|
+
msg += " (out, err)"
|
113
|
+
|
114
|
+
# failed out cmp
|
115
|
+
elsif !test.out_result
|
116
|
+
msg += " (out)"
|
117
|
+
|
118
|
+
# failed err cmp
|
119
|
+
else
|
120
|
+
msg += " (err)"
|
121
|
+
end
|
122
|
+
|
123
|
+
# out present
|
124
|
+
elsif test.expected_out_exists?
|
125
|
+
msg += " (out)"
|
126
|
+
|
127
|
+
# err present
|
128
|
+
else
|
129
|
+
msg += " (err)"
|
130
|
+
end
|
131
|
+
|
132
|
+
say msg, :red
|
133
|
+
end
|
134
|
+
|
135
|
+
def print_test_timeout(test)
|
136
|
+
say "timeout : ".rjust(TEST_JUSTIFY) + test.formatted_path, :red
|
66
137
|
end
|
67
138
|
|
68
|
-
def
|
139
|
+
def print_generate_timeout(test)
|
140
|
+
say "timeout : ".rjust(GEN_JUSTIFY) + test.formatted_path, :red
|
141
|
+
end
|
142
|
+
|
143
|
+
def print_summary
|
144
|
+
# print skipped explanation if anything was skipped
|
145
|
+
if @skipped > 0
|
146
|
+
if @type == :test
|
147
|
+
print_skipped_test_explanation
|
148
|
+
else
|
149
|
+
print_skipped_generate_explanation
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
# construct and print output summary
|
69
154
|
desc = []
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
155
|
+
tests = @failed + @skipped + @success
|
156
|
+
|
157
|
+
summary = "#{plural(tests, @type == :test ? 'test' : 'file')} ("
|
158
|
+
|
159
|
+
desc << set_color("#{@failed} failed", :red) unless @failed == 0
|
160
|
+
desc << set_color("#{@skipped} skipped", :yellow) unless @skipped == 0
|
161
|
+
unless @success == 0
|
162
|
+
if @type == :test
|
163
|
+
desc << set_color("#{@success} passed", :green)
|
164
|
+
else
|
165
|
+
desc << set_color("#{@success} generated", :green)
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
74
169
|
summary += desc.join(", ") + ")"
|
75
|
-
puts summary
|
170
|
+
puts "\n" + summary
|
171
|
+
end
|
172
|
+
|
173
|
+
def print_skipped_test_explanation
|
174
|
+
say "\nSkipped #{plural(@skipped, 'test')} due to missing expected output"
|
175
|
+
say "Run rcomp generate or manually create expected output"
|
176
|
+
end
|
177
|
+
|
178
|
+
def print_skipped_generate_explanation
|
179
|
+
say "\nSkipped #{plural(@skipped, 'file')} due to existing expected output"
|
180
|
+
say "Run rcomp generate -O to overwrite"
|
76
181
|
end
|
77
182
|
end
|
78
183
|
end
|
data/lib/rcomp/runner.rb
CHANGED
@@ -3,7 +3,8 @@ require 'fileutils'
|
|
3
3
|
module RComp
|
4
4
|
module Runner
|
5
5
|
|
6
|
-
|
6
|
+
extend self
|
7
|
+
extend Actions
|
7
8
|
|
8
9
|
# Run a suite of tests
|
9
10
|
#
|
@@ -12,20 +13,22 @@ module RComp
|
|
12
13
|
# options - A Hash of runner options
|
13
14
|
#
|
14
15
|
# Returns nothing
|
15
|
-
def
|
16
|
+
def run(suite, type, options={})
|
16
17
|
@conf = Conf.instance
|
17
18
|
reporter = Reporter.new(type)
|
18
19
|
|
20
|
+
reporter.header
|
21
|
+
|
19
22
|
suite.each do |test|
|
20
23
|
case type
|
21
24
|
when :test
|
22
|
-
|
25
|
+
run_test(test) if expected_exists?(test)
|
23
26
|
|
24
27
|
when :generate
|
25
28
|
if expected_exists?(test)
|
26
|
-
|
29
|
+
run_test(test, true) if options[:overwrite]
|
27
30
|
else
|
28
|
-
|
31
|
+
run_test(test, true)
|
29
32
|
end
|
30
33
|
end
|
31
34
|
|
@@ -44,8 +47,7 @@ module RComp
|
|
44
47
|
#
|
45
48
|
# Returns a boolean
|
46
49
|
def expected_exists?(test)
|
47
|
-
|
48
|
-
File.exists?(test.expected_err_path)
|
50
|
+
test.expected_out_exists? || test.expected_err_exists?
|
49
51
|
end
|
50
52
|
|
51
53
|
# Test or generate output for a specified test
|
@@ -54,11 +56,13 @@ module RComp
|
|
54
56
|
# generate - Flag for running generate. Runs test otherwise.
|
55
57
|
#
|
56
58
|
# Returns nothing
|
57
|
-
def
|
59
|
+
def run_test(test, generate=false)
|
60
|
+
# Create output path if it doens't exist
|
58
61
|
generate ? mkpath_to(test.expected_out_path) :
|
59
62
|
mkpath_to(test.result_out_path)
|
60
63
|
|
61
64
|
# Create process and run
|
65
|
+
# Handle the difference in path between a test and generate process
|
62
66
|
cmd = [@conf.command, test.test_path]
|
63
67
|
out = generate ? test.expected_out_path : test.result_out_path
|
64
68
|
err = generate ? test.expected_err_path : test.result_err_path
|
@@ -67,36 +71,59 @@ module RComp
|
|
67
71
|
|
68
72
|
if process.timedout?
|
69
73
|
test.result = :timedout
|
70
|
-
|
71
|
-
test.result = generate ? :success : compare_output(test)
|
74
|
+
return
|
72
75
|
end
|
76
|
+
|
77
|
+
test.result = generate ? :success : cmp_output(test)
|
73
78
|
end
|
74
79
|
|
75
80
|
# Compare the result and expected output of a test that has been run
|
76
81
|
#
|
77
82
|
# test - A Test object that has been run
|
78
|
-
# precondition
|
83
|
+
# precondition :: expected_exists?(test) is true
|
79
84
|
#
|
80
|
-
# Returns
|
81
|
-
def
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
if
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
if
|
92
|
-
|
93
|
-
|
94
|
-
else
|
95
|
-
|
96
|
-
|
97
|
-
end
|
85
|
+
# Returns success or failure as a symbol
|
86
|
+
def cmp_output(test)
|
87
|
+
# test out and err
|
88
|
+
if test.expected_out_exists? && test.expected_err_exists?
|
89
|
+
cmp_out(test)
|
90
|
+
cmp_err(test)
|
91
|
+
return :success if (test.out_result && test.err_result)
|
92
|
+
|
93
|
+
# test only out
|
94
|
+
elsif test.expected_out_exists?
|
95
|
+
cmp_out(test)
|
96
|
+
return :success if test.out_result
|
97
|
+
|
98
|
+
# test only err
|
99
|
+
else
|
100
|
+
cmp_err(test)
|
101
|
+
return :success if test.err_result
|
98
102
|
end
|
103
|
+
|
99
104
|
return :failed
|
100
105
|
end
|
106
|
+
|
107
|
+
# Compare a tests expected and result stdout
|
108
|
+
# Sets the result of the comparison to out_result in the test
|
109
|
+
#
|
110
|
+
# test - A test object that has been run
|
111
|
+
#
|
112
|
+
# Returns nothing
|
113
|
+
def cmp_out(test)
|
114
|
+
test.out_result = FileUtils.cmp(test.expected_out_path,
|
115
|
+
test.result_out_path)
|
116
|
+
end
|
117
|
+
|
118
|
+
# Compare a tests expected and result stderr
|
119
|
+
# Sets the result of the comparison to err_result in the test
|
120
|
+
#
|
121
|
+
# test - A test object that has been run
|
122
|
+
#
|
123
|
+
# Returns nothing
|
124
|
+
def cmp_err(test)
|
125
|
+
test.err_result = FileUtils.cmp(test.expected_err_path,
|
126
|
+
test.result_err_path)
|
127
|
+
end
|
101
128
|
end
|
102
129
|
end
|
data/lib/rcomp/suite.rb
CHANGED
@@ -3,7 +3,8 @@ require 'find'
|
|
3
3
|
module RComp
|
4
4
|
module Suite
|
5
5
|
|
6
|
-
|
6
|
+
extend self
|
7
|
+
extend Path
|
7
8
|
|
8
9
|
@@conf = Conf.instance
|
9
10
|
|
@@ -12,7 +13,7 @@ module RComp
|
|
12
13
|
# pattern - A pattern to filter the tests that are added to the suite
|
13
14
|
#
|
14
15
|
# Returns an Array of Test objects
|
15
|
-
def
|
16
|
+
def load(pattern=nil)
|
16
17
|
tests = []
|
17
18
|
|
18
19
|
# Find all tests in the tests directory
|
@@ -21,7 +22,7 @@ module RComp
|
|
21
22
|
next if File.directory? path
|
22
23
|
|
23
24
|
# filter tests by pattern if present
|
24
|
-
|
25
|
+
if pattern
|
25
26
|
next unless rel_path(path).match(pattern)
|
26
27
|
end
|
27
28
|
|
@@ -37,6 +38,8 @@ module RComp
|
|
37
38
|
return tests
|
38
39
|
end
|
39
40
|
|
41
|
+
private
|
42
|
+
|
40
43
|
# Checks all ignore patterns against a given relative path
|
41
44
|
#
|
42
45
|
# path - A relative path of a test
|
data/lib/rcomp/test.rb
CHANGED
@@ -4,9 +4,10 @@ module RComp
|
|
4
4
|
include RComp::Path
|
5
5
|
|
6
6
|
attr_reader :test_path, :result_out_path, :result_err_path,
|
7
|
-
:expected_out_path, :expected_err_path, :relative_path
|
7
|
+
:expected_out_path, :expected_err_path, :relative_path,
|
8
|
+
:formatted_path
|
8
9
|
|
9
|
-
attr_accessor :result
|
10
|
+
attr_accessor :result, :out_result, :err_result
|
10
11
|
|
11
12
|
# Initialize a new Test
|
12
13
|
#
|
@@ -18,10 +19,42 @@ module RComp
|
|
18
19
|
@result = :skipped
|
19
20
|
@relative_path = rel_path(path)
|
20
21
|
@test_path = path
|
21
|
-
@result_out_path =
|
22
|
-
@result_err_path =
|
23
|
-
@expected_out_path =
|
24
|
-
@expected_err_path =
|
22
|
+
@result_out_path = get_path(:result, path, '.out')
|
23
|
+
@result_err_path = get_path(:result, path, '.err')
|
24
|
+
@expected_out_path = get_path(:expected, path, '.out')
|
25
|
+
@expected_err_path = get_path(:expected, path, '.err')
|
26
|
+
@formatted_path = format_path(@relative_path)
|
27
|
+
end
|
28
|
+
|
29
|
+
def expected_out_exists?
|
30
|
+
@expected_out_exists ||= File.exists?(@expected_out_path)
|
31
|
+
end
|
32
|
+
|
33
|
+
def expected_err_exists?
|
34
|
+
@expected_err_exists ||= File.exists?(@expected_err_path)
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def get_path(type, test_path, extension)
|
40
|
+
cmpnts = []
|
41
|
+
if type == :result
|
42
|
+
cmpnts << Conf.instance.result_root
|
43
|
+
else
|
44
|
+
cmpnts << Conf.instance.expected_root
|
45
|
+
end
|
46
|
+
cmpnts << rel_path(File.dirname(test_path))
|
47
|
+
cmpnts << File.basename(test_path, ".*") + extension
|
48
|
+
File.join(cmpnts)
|
49
|
+
end
|
50
|
+
|
51
|
+
# Formats relative path for user output
|
52
|
+
#
|
53
|
+
# path - A relative test path
|
54
|
+
#
|
55
|
+
# Returns formatted path
|
56
|
+
def format_path(path)
|
57
|
+
path[1..-1]
|
25
58
|
end
|
26
59
|
end
|
27
60
|
end
|
data/lib/rcomp/version.rb
CHANGED
data/rcomp.gemspec
CHANGED
@@ -9,8 +9,8 @@ Gem::Specification.new do |s|
|
|
9
9
|
s.authors = ["Chris Knadler"]
|
10
10
|
s.email = ["takeshi91k@gmail.com"]
|
11
11
|
s.homepage = "https://github.com/cknadler/rcomp"
|
12
|
-
s.summary = "A simple framework for testing command line application output
|
13
|
-
s.description = "
|
12
|
+
s.summary = "A simple framework for testing command line application output"
|
13
|
+
s.description = "Command line output testing framework with dead simple tests"
|
14
14
|
|
15
15
|
s.required_ruby_version = ">= 1.9.3"
|
16
16
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rcomp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-11-
|
12
|
+
date: 2012-11-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: thor
|
@@ -91,8 +91,7 @@ dependencies:
|
|
91
91
|
- - ~>
|
92
92
|
- !ruby/object:Gem::Version
|
93
93
|
version: 0.5.0
|
94
|
-
description:
|
95
|
-
and comparing the result with expected output.
|
94
|
+
description: Command line output testing framework with dead simple tests
|
96
95
|
email:
|
97
96
|
- takeshi91k@gmail.com
|
98
97
|
executables:
|
@@ -102,7 +101,7 @@ extra_rdoc_files: []
|
|
102
101
|
files:
|
103
102
|
- .gitignore
|
104
103
|
- .travis.yml
|
105
|
-
- CHANGELOG.
|
104
|
+
- CHANGELOG.md
|
106
105
|
- Gemfile
|
107
106
|
- Gemfile.lock
|
108
107
|
- LICENSE
|
@@ -121,8 +120,8 @@ files:
|
|
121
120
|
- lib/rcomp/actions.rb
|
122
121
|
- lib/rcomp/cli.rb
|
123
122
|
- lib/rcomp/conf.rb
|
123
|
+
- lib/rcomp/env.rb
|
124
124
|
- lib/rcomp/helper.rb
|
125
|
-
- lib/rcomp/initializer.rb
|
126
125
|
- lib/rcomp/path.rb
|
127
126
|
- lib/rcomp/process.rb
|
128
127
|
- lib/rcomp/reporter.rb
|
@@ -155,7 +154,7 @@ rubyforge_project: rcomp
|
|
155
154
|
rubygems_version: 1.8.24
|
156
155
|
signing_key:
|
157
156
|
specification_version: 3
|
158
|
-
summary: A simple framework for testing command line application output
|
157
|
+
summary: A simple framework for testing command line application output
|
159
158
|
test_files:
|
160
159
|
- features/generate.feature
|
161
160
|
- features/init.feature
|