rcomp 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,24 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ coverage
6
+ InstalledFiles
7
+ lib/bundler/man
8
+ pkg
9
+ rdoc
10
+ spec/reports
11
+ test/tmp
12
+ test/version_tmp
13
+ tmp
14
+
15
+ # YARD artifacts
16
+ .yardoc
17
+ _yardoc
18
+ doc/
19
+
20
+ # RComp files
21
+ .rcomp
22
+
23
+ # simplecov
24
+ coverage
data/.travis.yml ADDED
@@ -0,0 +1,9 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - jruby-19mode
5
+ - rbx-19mode
6
+ matrix:
7
+ allow_failures:
8
+ - rvm: jruby-19mode
9
+ - rvm: rbx-19mode
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source :rubygems
2
+
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,39 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ rcomp (0.1.0)
5
+ thor (~> 0.16.0)
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ aruba (0.5.1)
11
+ childprocess (~> 0.3.6)
12
+ cucumber (>= 1.1.1)
13
+ rspec-expectations (>= 2.7.0)
14
+ builder (3.1.4)
15
+ childprocess (0.3.6)
16
+ ffi (~> 1.0, >= 1.0.6)
17
+ cucumber (1.2.1)
18
+ builder (>= 2.1.2)
19
+ diff-lcs (>= 1.1.3)
20
+ gherkin (~> 2.11.0)
21
+ json (>= 1.4.6)
22
+ diff-lcs (1.1.3)
23
+ ffi (1.2.0)
24
+ gherkin (2.11.5)
25
+ json (>= 1.4.6)
26
+ json (1.7.5)
27
+ rake (10.0.2)
28
+ rspec-expectations (2.12.0)
29
+ diff-lcs (~> 1.1.3)
30
+ thor (0.16.0)
31
+
32
+ PLATFORMS
33
+ ruby
34
+
35
+ DEPENDENCIES
36
+ aruba (~> 0.5.0)
37
+ cucumber (~> 1.2.1)
38
+ rake
39
+ rcomp!
data/LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ Copyright (c) 2012 Chris Knadler
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,124 @@
1
+ # RComp [![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/cknadler/rcomp) [![Dependency Status](https://gemnasium.com/cknadler/rcomp.png)](https://gemnasium.com/cknadler/rcomp) [![Build Status](https://travis-ci.org/cknadler/rcomp.png)](https://travis-ci.org/cknadler/rcomp)
2
+
3
+
4
+ RComp is a simple framework for testing command line application output. It works by passing a specified command tests (files) by argument and comparing the result with expected output.
5
+
6
+ ## Installation
7
+
8
+ ```
9
+ $ gem install rcomp
10
+ ```
11
+
12
+ ## Usage
13
+
14
+ ```
15
+ $ rcomp
16
+ Tasks:
17
+ rcomp generate # Generate expected output for all tests
18
+ rcomp help [TASK] # Describe available tasks or one specific task
19
+ rcomp init # Setup rcomp test directory
20
+ rcomp set_command COMMAND # Sets the command RComp will run tests with
21
+ rcomp set_directory PATH # Set the directory RComp will store files
22
+ rcomp test # Run all tests
23
+ rcomp version # Prints RComp's version information
24
+ ```
25
+
26
+ ## Setup
27
+
28
+ In your project root directory, run:
29
+
30
+ ```
31
+ $ rcomp set-command ./some-executable
32
+ $ rcomp init
33
+ ```
34
+
35
+ Then create some tests in `rcomp/tests`
36
+
37
+ ## Structure
38
+
39
+ After running `rcomp init` the following directories are created by default:
40
+
41
+ ```
42
+ .
43
+ |--rcomp
44
+ |----tests
45
+ |----expected
46
+ |----results
47
+ ```
48
+
49
+ ### tests
50
+ Stores test files. All subdirectories will be searched for tests.
51
+
52
+ ### expected
53
+ Stores the expected output of tests. Format is `testname.out` for `stdout` and `testname.err` for `stderr`.
54
+
55
+ ### results
56
+ Managed by RComp. Stores the results of your most recent test suite run.
57
+
58
+ ---
59
+
60
+ A simple RComp suite might look something like this:
61
+
62
+ ```
63
+ .
64
+ |--rcomp
65
+ |----tests
66
+ |------test1.test
67
+ |------dir
68
+ |--------test2.test
69
+ |----expected
70
+ |------test1.out
71
+ |------dir
72
+ |--------test2.out
73
+ |--------test2.err
74
+ ```
75
+
76
+ ## Configuration
77
+
78
+ All custom configuration is stored in a `.rcomp` file as YAML
79
+
80
+ <table>
81
+ <th>Setting</th><th>Config</th><th>Default</th><th>Description</th>
82
+ <tr>
83
+ <td>command</td>
84
+ <td><code>command: [COMMAND]</code></td>
85
+ <td></td>
86
+ <td>Command RComp will run tests with</td>
87
+ </tr>
88
+ <tr>
89
+ <td>directory</td>
90
+ <td><code>directory: [DIRECTORY]</code></td>
91
+ <td><code>rcomp</code></td>
92
+ <td>Directory RComp will store tests, results and expected in</td>
93
+ </tr>
94
+ </table>
95
+
96
+ ## Aliases
97
+
98
+ <table>
99
+ <th>Task</th><th>Alias</th>
100
+ <tr>
101
+ <td><code>test</code></td>
102
+ <td><code>t</code></td>
103
+ </tr>
104
+ <tr>
105
+ <td><code>generate</code></td>
106
+ <td><code>g</code></td>
107
+ </tr>
108
+ <tr>
109
+ <td><code>set-command</code></td>
110
+ <td><code>c</code></td>
111
+ </tr>
112
+ <tr>
113
+ <td><code>set-directory</code></td>
114
+ <td><code>d</code></td>
115
+ </tr>
116
+ <tr>
117
+ <td><code>version</code></td>
118
+ <td><code>-v</code><code>--version</code></td>
119
+ </tr>
120
+ </table>
121
+
122
+ ## Copyright
123
+
124
+ Copyright (c) 2012 Chris Knadler. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require 'cucumber/rake/task'
2
+ require 'bundler/gem_tasks'
3
+
4
+ desc "Run features"
5
+ Cucumber::Rake::Task.new(:features)
6
+
7
+ task :default => :features
data/bin/rcomp ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rcomp'
4
+ require 'rcomp/cli'
5
+
6
+ RComp::CLI.start
data/contributing.md ADDED
@@ -0,0 +1,7 @@
1
+ # Contributing to RComp
2
+ * Fork the project.
3
+ * Make a topic branch.
4
+ * Make your feature addition or bug fix.
5
+ * Add tests for it. This is important so I don't break it in a future version unintentionally.
6
+ * Commit, do not mess with rakefile, version, or history. If you want to have your own version, thats fine but bump version in a commit by itself I can ignore when I pull.
7
+ * Send me a pull request.
@@ -0,0 +1,224 @@
1
+ Feature: Generate
2
+ Users should have the ability to generate expected output for tests
3
+
4
+ # faulty configuration
5
+ Scenario: Generate without command
6
+ When I run `rcomp generate`
7
+ Then the output should contain "No command present"
8
+ And the exit status should be 1
9
+
10
+ Scenario: Generate without init
11
+ Given I run `rcomp c ./exec`
12
+ When I run `rcomp generate`
13
+ Then the output should contain "No RComp directory"
14
+ And the exit status should be 1
15
+
16
+ Scenario: Generate with partial init
17
+ Given I run `rcomp c ./exec`
18
+ And a directory named "rcomp"
19
+ And a directory named "rcomp/tests"
20
+ When I run `rcomp generate`
21
+ Then the output should contain "Missing RComp directories"
22
+ And the exit status should be 1
23
+
24
+ # no tests
25
+ @basic-conf
26
+ Scenario: Generate with no tests
27
+ When I run `rcomp generate`
28
+ Then the output should contain "0 files ()"
29
+ And the exit status should be 0
30
+
31
+ # stdout single generate
32
+ @basic-conf
33
+ Scenario: Generate a single result
34
+ Given a file named "rcomp/tests/test1.test" with:
35
+ """
36
+ ABC
37
+
38
+ """
39
+ When I run `rcomp generate`
40
+ Then the output should contain "1 file (1 generated)"
41
+ And the file "rcomp/expected/test1.out" should contain "ABC"
42
+ And the exit status should be 0
43
+
44
+ @basic-conf
45
+ Scenario: Skip a single result
46
+ Given a file named "rcomp/tests/test1.test" with:
47
+ """
48
+ ABC
49
+
50
+ """
51
+ And a file named "rcomp/expected/test1.out" with:
52
+ """
53
+ DEF
54
+
55
+ """
56
+ When I run `rcomp generate`
57
+ Then the output should contain "1 file (1 skipped)"
58
+ And the file "rcomp/expected/test1.out" should contain "DEF"
59
+ And the exit status should be 0
60
+
61
+ @basic-conf
62
+ Scenario: Overwrite a single result
63
+ Given a file named "rcomp/tests/test1.test" with:
64
+ """
65
+ ABC
66
+
67
+ """
68
+ And a file named "rcomp/expected/test1.out" with:
69
+ """
70
+ DEF
71
+
72
+ """
73
+ When I run `rcomp generate -O` interactively
74
+ And I type "y"
75
+ Then the output should contain "overwrite all existing"
76
+ And the output should contain "1 file (1 generated)"
77
+ And the file "rcomp/expected/test1.out" should contain "ABC"
78
+ And the exit status should be 0
79
+
80
+ # stdout multiple generate
81
+ @basic-conf
82
+ @load-assorted-tests
83
+ Scenario: Generate multiple results
84
+ When I run `rcomp generate`
85
+ Then the output should contain "3 files (2 skipped, 1 generated)"
86
+ And the file "rcomp/expected/test_a.out" should contain "ABC"
87
+ And the file "rcomp/expected/dir/test_b.out" should contain "XYZ"
88
+ And the file "rcomp/expected/dir/foo/test_c.out" should contain "GHI"
89
+ And the exit status should be 0
90
+
91
+ @basic-conf
92
+ @load-assorted-tests
93
+ Scenario: Overwrite multiple results
94
+ When I run `rcomp generate -O` interactively
95
+ And I type "y"
96
+ Then the output should contain "overwrite all existing"
97
+ And the file "rcomp/expected/test_a.out" should contain "ABC"
98
+ And the file "rcomp/expected/dir/test_b.out" should contain "DEF"
99
+ And the file "rcomp/expected/dir/foo/test_c.out" should contain "GHI"
100
+ And the output should contain "3 files (3 generated)"
101
+ And the exit status should be 0
102
+
103
+ # stderr single generate
104
+ @err-conf
105
+ Scenario: Generate a single err result
106
+ Given a file named "rcomp/tests/test1.test" with:
107
+ """
108
+ ABC
109
+
110
+ """
111
+ When I run `rcomp generate`
112
+ Then the output should contain "1 file (1 generated)"
113
+ And the file "rcomp/expected/test1.err" should contain "ABC"
114
+ And the exit status should be 0
115
+
116
+ @err-conf
117
+ Scenario: Skip a single err result
118
+ Given a file named "rcomp/tests/test1.test" with:
119
+ """
120
+ ABC
121
+
122
+ """
123
+ And a file named "rcomp/expected/test1.err" with:
124
+ """
125
+ XYZ
126
+
127
+ """
128
+ When I run `rcomp generate`
129
+ Then the output should contain "1 file (1 skipped)"
130
+ And the file "rcomp/expected/test1.err" should contain "XYZ"
131
+ And the exit status should be 0
132
+
133
+ @err-conf
134
+ Scenario: Overwrite a single err result
135
+ Given a file named "rcomp/tests/test1.test" with:
136
+ """
137
+ ABC
138
+
139
+ """
140
+ And a file named "rcomp/expected/test1.err" with:
141
+ """
142
+ XYZ
143
+
144
+ """
145
+ When I run `rcomp generate -O` interactively
146
+ And I type "y"
147
+ Then the output should contain "1 file (1 generated)"
148
+ And the file "rcomp/expected/test1.err" should contain "ABC"
149
+ And the exit status should be 0
150
+
151
+ # stderr multiple generate
152
+ @err-conf
153
+ @load-assorted-err-tests
154
+ Scenario: Generate multiple err results
155
+ When I run `rcomp generate`
156
+ Then the output should contain "3 files (2 skipped, 1 generated)"
157
+ And the file "rcomp/expected/test_a.err" should contain "ABC"
158
+ And the file "rcomp/expected/dir/test_b.err" should contain "XYZ"
159
+ And the file "rcomp/expected/dir/foo/test_c.err" should contain "GHI"
160
+ And the exit status should be 0
161
+
162
+ @err-conf
163
+ @load-assorted-err-tests
164
+ Scenario: Overwrite multiple err results
165
+ When I run `rcomp generate -O` interactively
166
+ And I type "y"
167
+ Then the output should contain "3 files (3 generated)"
168
+ And the output should contain "overwrite all existing"
169
+ And the file "rcomp/expected/test_a.err" should contain "ABC"
170
+ And the file "rcomp/expected/dir/test_b.err" should contain "DEF"
171
+ And the file "rcomp/expected/dir/foo/test_c.err" should contain "GHI"
172
+ And the exit status should be 0
173
+
174
+ # alias
175
+ @basic-conf
176
+ @load-assorted-tests
177
+ Scenario: Generate alias g
178
+ When I run `rcomp g`
179
+ Then the output should contain "3 files (2 skipped, 1 generated)"
180
+ And the file "rcomp/expected/test_a.out" should contain "ABC"
181
+ And the file "rcomp/expected/dir/test_b.out" should contain "XYZ"
182
+ And the file "rcomp/expected/dir/foo/test_c.out" should contain "GHI"
183
+ And the exit status should be 0
184
+
185
+ # filters
186
+ @basic-conf
187
+ @load-assorted-tests
188
+ Scenario: Generate with filter: catches all
189
+ When I run `rcomp generate --grep=test`
190
+ Then the output should contain "3 files (2 skipped, 1 generated)"
191
+ And the exit status should be 0
192
+
193
+ @basic-conf
194
+ @load-assorted-tests
195
+ Scenario: Generate with filter: catches some
196
+ When I run `rcomp generate --grep=dir`
197
+ Then the output should contain "2 files (1 skipped, 1 generated)"
198
+ And the exit status should be 0
199
+
200
+ @basic-conf
201
+ @load-assorted-tests
202
+ Scenario: Generate with filter: catches none
203
+ When I run `rcomp generate --grep=xyz`
204
+ Then the output should contain "0 files ()"
205
+ And the exit status should be 0
206
+
207
+ @basic-conf
208
+ @load-assorted-tests
209
+ Scenario: Generate with filter: catches some with overwrite
210
+ When I run `rcomp generate -O --grep=dir`
211
+ Then the output should contain "2 files (2 generated)"
212
+ And the exit status should be 0
213
+
214
+ # custom generate directory
215
+ @custom-conf
216
+ Scenario: Custom conf generate
217
+ Given a file named "test/integration/rcomp/tests/test1.test" with:
218
+ """
219
+ ABC
220
+
221
+ """
222
+ When I run `rcomp generate`
223
+ Then the output should contain "1 file (1 generated)"
224
+ And the exit status should be 0
@@ -0,0 +1,44 @@
1
+ Feature: Init
2
+ A user should be able to initialize the RComp's test directories
3
+
4
+ Scenario: Blind init
5
+ When I run `rcomp init`
6
+ Then the following directories should exist:
7
+ | rcomp |
8
+ | rcomp/tests |
9
+ | rcomp/results |
10
+ | rcomp/expected |
11
+ And the exit status should be 0
12
+
13
+ Scenario: Init with directory set in project root
14
+ Given I run `rcomp d dir`
15
+ When I run `rcomp init`
16
+ Then the following directories should exist:
17
+ | dir |
18
+ | dir/tests |
19
+ | dir/results |
20
+ | dir/expected |
21
+ And the exit status should be 0
22
+
23
+ Scenario: Init with directory set in subdirectory
24
+ Given a directory named "spec/dir"
25
+ And I run `rcomp d spec/dir/rcomp`
26
+ When I run `rcomp init`
27
+ Then the following directories should exist:
28
+ | spec/dir/rcomp |
29
+ | spec/dir/rcomp/tests |
30
+ | spec/dir/rcomp/results |
31
+ | spec/dir/rcomp/expected |
32
+ And the exit status should be 0
33
+
34
+ Scenario: Init with directory set in nonexistant subdirectory
35
+ Given I run `rcomp d nonexistant/rcomp`
36
+ When I run `rcomp init`
37
+ Then the output should contain "No directory nonexistant"
38
+ And the exit status should be 1
39
+
40
+ Scenario: Already initialized
41
+ Given I run `rcomp init`
42
+ When I run `rcomp init`
43
+ Then the output should contain "already initialized"
44
+ And the exit status should be 1
@@ -0,0 +1,24 @@
1
+ Feature: Set Command
2
+ A user should be able to set the command RComp tests with from the CLI
3
+
4
+ @announce
5
+ Scenario: Set command
6
+ When I run `rcomp set-command ./test_exec`
7
+ Then a file named ".rcomp" should exist
8
+ And the file ".rcomp" should contain "command: ./test_exec"
9
+ And the exit status should be 0
10
+
11
+ @announce
12
+ Scenario: Set command alias
13
+ When I run `rcomp c ./test_exec`
14
+ Then a file named ".rcomp" should exist
15
+ And the file ".rcomp" should contain "command: ./test_exec"
16
+ And the exit status should be 0
17
+
18
+ @announce
19
+ Scenario: Overwrite command
20
+ When I run `rcomp c ./first`
21
+ And I run `rcomp c ./second`
22
+ Then a file named ".rcomp" should exist
23
+ And the file ".rcomp" should contain "command: ./second"
24
+ And the exit status should be 0
@@ -0,0 +1,22 @@
1
+ Feature: Set Directory
2
+ A user should be able to set the directory that RComp
3
+ stores tests in from the CLI
4
+
5
+ Scenario: Set directory
6
+ When I run `rcomp set-directory spec/rcomp`
7
+ Then a file named ".rcomp" should exist
8
+ And the file ".rcomp" should contain "directory: spec/rcomp"
9
+ And the exit status should be 0
10
+
11
+ Scenario: Set directory alias
12
+ When I run `rcomp d spec/rcomp`
13
+ Then a file named ".rcomp" should exist
14
+ And the file ".rcomp" should contain "directory: spec/rcomp"
15
+ And the exit status should be 0
16
+
17
+ Scenario: Overwrite directory
18
+ When I run `rcomp d first`
19
+ And I run `rcomp d second`
20
+ Then a file named ".rcomp" should exist
21
+ And the file ".rcomp" should contain "directory: second"
22
+ And the exit status should be 0
@@ -0,0 +1,66 @@
1
+ require 'rcomp'
2
+ require 'aruba/api'
3
+ require 'aruba/cucumber'
4
+ require 'test/unit/assertions'
5
+
6
+ # Helpers
7
+ def create_executable
8
+ content = "#!/usr/bin/env ruby\nputs IO.binread(ARGV[0])"
9
+ write_file("test_exec", content)
10
+ in_current_dir do
11
+ FileUtils.chmod(0755, "test_exec")
12
+ end
13
+ end
14
+
15
+ def create_err_executable
16
+ content = "#!/usr/bin/env ruby\n$stderr.puts IO.binread(ARGV[0])"
17
+ write_file("test_exec", content)
18
+ in_current_dir do
19
+ FileUtils.chmod(0755, "test_exec")
20
+ end
21
+ end
22
+
23
+ def create_assorted_tests
24
+ write_file("rcomp/tests/test_a.test", "ABC\n")
25
+ write_file("rcomp/tests/dir/test_b.test", "DEF\n")
26
+ write_file("rcomp/tests/dir/foo/test_c.test", "GHI\n")
27
+ end
28
+
29
+ # Custom Tags
30
+ Before('@basic-conf') do
31
+ create_executable
32
+ # Spin up basic RComp configuration
33
+ run_simple('rcomp c ./test_exec', false)
34
+ run_simple('rcomp init', false)
35
+ end
36
+
37
+ Before('@err-conf') do
38
+ create_err_executable
39
+ # Spin up RComp configuraton with an erroring executable
40
+ run_simple('rcomp c ./test_exec', false)
41
+ run_simple('rcomp init', false)
42
+ end
43
+
44
+ Before('@custom-conf') do
45
+ create_executable
46
+ # Spin up custom path RComp configuration
47
+ run_simple('mkdir test', false)
48
+ run_simple('mkdir test/integration', false)
49
+ run_simple('rcomp d test/integration/rcomp')
50
+ run_simple('rcomp c ./test_exec', false)
51
+ run_simple('rcomp init', false)
52
+ end
53
+
54
+ Before('@load-assorted-tests') do
55
+ create_assorted_tests
56
+ write_file("rcomp/expected/test_a.out", "ABC\n")
57
+ write_file("rcomp/expected/dir/test_b.out", "XYZ\n")
58
+ end
59
+
60
+ Before('@load-assorted-err-tests') do
61
+ create_assorted_tests
62
+ write_file("rcomp/expected/test_a.err", "ABC\n")
63
+ write_file("rcomp/expected/dir/test_b.err", "XYZ\n")
64
+ end
65
+
66
+ World(Test::Unit::Assertions)