guard-cunit 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.travis.yml ADDED
@@ -0,0 +1,11 @@
1
+ language: ruby
2
+ rvm:
3
+ - "1.8.7"
4
+ - "1.9.2"
5
+ - "1.9.3"
6
+ - jruby-18mode # JRuby in 1.8 mode
7
+ - jruby-19mode # JRuby in 1.9 mode
8
+ - rbx-18mode
9
+ - rbx-19mode
10
+ # uncomment this line if your project needs to run something other than `rake`:
11
+ script: bundle exec rspec spec
data/CHANGELOG.md ADDED
@@ -0,0 +1,241 @@
1
+ # Chagelog
2
+
3
+ ### Bug fix
4
+ commit fd83634f375f76fb7ef5af72516f6afe6f07946c
5
+ Date: Tue Nov 27 13:24:24 2012 +0200
6
+
7
+ fixed travis build 13 (removed unneded gem used only for debugging)
8
+
9
+
10
+ ### Bug fix
11
+ commit c021cdfc0e59b8160b684363d4c1a2bcf29472dc
12
+ Date: Tue Nov 27 13:03:50 2012 +0200
13
+
14
+ Fixed using of Notifier class and added some smoother handling of test exe outputs
15
+
16
+ ### Bug fix
17
+ commit 5e3a8ae87abdff852b6e1917728ea792b4d11274
18
+ Date: Sun Nov 25 17:24:59 2012 +0200
19
+
20
+ rework parsing for cunit
21
+
22
+ ### Bug fix
23
+ commit c93acec12fad9698b2a134bb316c92aa38a74c8f
24
+ Date: Sun Nov 25 11:20:01 2012 +0200
25
+
26
+ fixed test for parsing output from test
27
+
28
+ ### Bug fix
29
+ commit 1a09331f89b5b0e3e72cd1b4b15551f7ed8c4b1b
30
+ Date: Sun Nov 25 09:13:23 2012 +0200
31
+
32
+ fixed guard reload calls and added test cases for passing cunit test output to parser
33
+
34
+
35
+ ### Bug fix
36
+ commit 901dee0b5f8b14311885b4264bbb5fa1951161eb
37
+ Date: Wed Nov 21 14:01:07 2012 +0200
38
+
39
+ fixed rspec test running under windows platform
40
+
41
+
42
+ ### Bug fix
43
+ commit 40da4a4c79c6ec5a7abefb09813ff953ce94e7e4
44
+ Date: Tue Nov 20 13:39:11 2012 +0200
45
+
46
+ test&fix for stopping guard's tasks and exiting, when one of them(tasks) fails
47
+
48
+ ### Bug fix
49
+ commit 622488393175bb396a82a2f235bab9241fbe922a
50
+ Date: Sun Nov 18 17:06:41 2012 +0200
51
+
52
+ merged stdout and stderr outputs when spawning/piping tasks
53
+
54
+ ### Improvement
55
+ commit b305b860e6e0dbed2006ab8a8775f1c352ce8139
56
+ Date: Sun Nov 18 11:37:28 2012 +0200
57
+
58
+ removed doc folder, since it is generated automatically with 'rake doc'
59
+
60
+ ### Improvement
61
+ commit ad4dd6a13f290c31fb149ccd1ae9a0b65f8c5774
62
+ Date: Fri Nov 16 00:42:51 2012 -0500
63
+
64
+ skip interactions for guard run within rspec
65
+
66
+ ## version 0.0.1
67
+
68
+ ### Improvement
69
+ commit f246fc98f17959c59ef1525e56ebb70472ced89f
70
+ Date: Tue Nov 6 20:06:33 2012 +0200
71
+
72
+ added specific platform to gemspec since not yet tested on other platforms
73
+
74
+ ### Improvement
75
+ commit a7fda4f1d8f7b0fb937aa0e20f5b37cac55323a0
76
+ Date: Tue Nov 6 20:04:59 2012 +0200
77
+
78
+ added specific platform to gem sinc still not tested on other platforms
79
+
80
+ ### Improvement
81
+ commit 0ef39baec6dbcfe7da55286417420811baf194e3
82
+ Date: Tue Nov 6 19:45:44 2012 +0200
83
+
84
+ leave with class variable access but make it portable
85
+
86
+ ### Improvement
87
+ commit c62e832c478b5690bd02a68399b22d3177df35b3
88
+ Date: Tue Nov 6 19:34:14 2012 +0200
89
+
90
+ reworked the tests
91
+
92
+ ### Bugfix
93
+ commit decab60a968b1a1fc926e5edd00acecc8f2c2d80
94
+ Date: Tue Nov 6 19:12:59 2012 +0200
95
+
96
+ fixed rspec tests
97
+
98
+ ### Improvement
99
+ commit 6dc936e6dc829353ee8433c1136333de07ae9781
100
+ Date: Fri Nov 2 07:59:40 2012 +0200
101
+
102
+ Some fixes to improve rake
103
+
104
+ ### Improvement
105
+ commit 548da4659f9b982151c354533fac1104131e779c
106
+ Date: Mon Oct 15 19:39:32 2012 +0300
107
+
108
+ update gem
109
+
110
+ ### Bug fix
111
+ commit 34978668aa7b26441a9a79c0eac38134cbd43fa4
112
+ Date: Mon Oct 15 19:29:30 2012 +0300
113
+
114
+ Fix cunit parser tests
115
+
116
+ ### Bugfix
117
+ commit 62a192b47082cd00154fe7a6e3663430453bde47
118
+ Date: Fri Oct 12 18:52:35 2012 +0300
119
+
120
+ more test pass
121
+
122
+ ### Improvement
123
+ commit b1bdec45bf9ce9dde9e9ef1a067e3fec4461960d
124
+ Date: Fri Oct 12 07:55:37 2012 +0300
125
+
126
+ add parser tests
127
+
128
+ ### Bugfix
129
+ commit 1f6e251023c15b5092e16873afe552b1ea2eabcb
130
+ Date: Sat Oct 6 21:59:29 2012 +0300
131
+
132
+ fix run on change
133
+
134
+ ### Bugfix
135
+ commit 06b4cd83ac895713a78754783b37c5e0f74e06a9
136
+ Date: Sat Oct 6 21:58:26 2012 +0300
137
+
138
+ fix the test
139
+
140
+ commit e62d28d6031cbc4664cf2fb8fd4a8ad172f8224e
141
+ Date: Sat Oct 6 21:52:08 2012 +0300
142
+
143
+ fix the test
144
+
145
+ ### Improvement
146
+ commit aadbd9ad9ce9ae841f678718c931af9707fa2601
147
+ Date: Sat Oct 6 21:50:37 2012 +0300
148
+
149
+ enhance the test expect some info
150
+
151
+ ### Improvement
152
+ commit 0e85a5b2cd2596c11826dec04f4da81d0723ae95
153
+ Date: Sat Oct 6 21:45:04 2012 +0300
154
+
155
+ add test for run_on_change
156
+
157
+ ### Bugfix
158
+ commit 5f076ef6362a8f66508bae263c57b23c75566b73
159
+ Date: Thu Oct 4 21:34:49 2012 +0300
160
+
161
+ fix build - only pending tests should remain not covered
162
+ changed puts method with GUI.info
163
+
164
+ ### Improvement
165
+ commit e5d0783f8d49b4b39934dde0ab867cd8032c4d5d
166
+ Date: Wed Oct 3 08:43:49 2012 +0300
167
+
168
+ add tests for the Cunit output parser
169
+
170
+ ### Improvement
171
+ commit b5b5fb18245618c4e0d2969c51f16890969c5cac
172
+ Date: Sun Sep 23 08:53:05 2012 -0400
173
+
174
+ travis_build_status_to_readme
175
+
176
+ ### Improvement
177
+ commit d9c74c868184f3d0a76f36d295c4be8be5b51e89
178
+ Date: Sun Sep 23 08:44:37 2012 -0400
179
+
180
+ use expand_path instead of absolute_path
181
+
182
+ ### Bugfix
183
+ commit da363416aeceac84ce463a48b18b5434e145ae47
184
+ Date: Sun Sep 23 08:32:57 2012 -0400
185
+
186
+ fixed init of runner object
187
+
188
+ commit b7a8e79a9ac8533792c5c75c47d9165d1e95a3a6
189
+ Date: Sat Sep 22 19:22:31 2012 +0300
190
+
191
+ just test the travis
192
+
193
+ commit 782ffc3050fded2e516ce3587363b5f830c65e01
194
+ Date: Sat Sep 22 19:18:48 2012 +0300
195
+
196
+ fix rake and travis
197
+
198
+ ### Improvement
199
+ commit 01f2967fc970a234f43c5899bcd90d919337996d
200
+ Date: Sat Sep 22 17:52:06 2012 +0300
201
+
202
+ added some more documentation and cleanup of dead code
203
+
204
+ ### Improvement
205
+ commit 3746ac25267b63a0c1f93e9d0bfc699d0da89b63
206
+ Date: Fri Sep 21 18:32:43 2012 +0300
207
+
208
+ Moved runner behaviour in a separate class and fixed Guardfile format
209
+
210
+ commit e690c19158d6a511ba4e07bd4a48bf765609f0cf
211
+ Date: Fri Sep 21 18:30:23 2012 +0300
212
+
213
+ Moved runner behaviour in a separate class and fixed Guardfile format
214
+
215
+ commit 4372dfab33a65fba622685d3e8ca09eff09948ba
216
+ Date: Fri Sep 21 18:29:49 2012 +0300
217
+
218
+ Moved runner behaviour in a separate class and fixed Guardfile format
219
+
220
+ #### Bugfix
221
+ commit e1713aa0e01e7777a966beca23da83e07135f8a3
222
+ Date: Fri Sep 21 18:28:56 2012 +0300
223
+
224
+ fixed gemspec not to include gemfiles
225
+
226
+ ### Improvement
227
+ commit 1c054c79f1068c633b059118f9854fc0344bde0f
228
+ Date: Fri Sep 21 18:25:11 2012 +0300
229
+
230
+ Added rdoc output :) - will improve
231
+
232
+ ### Improvement
233
+ commit 667c9fc5e6a16059f9f493c95b0f00880c0a6006
234
+ Date: Fri Sep 21 18:15:56 2012 +0300
235
+
236
+ Fixed dependancy to guard and added meaningful README
237
+
238
+ commit 30678f36d96ed1337f27186f0daf5e4e1340198f
239
+ Date: Fri Sep 21 18:12:06 2012 +0300
240
+
241
+ Moved runner behaviour in a separate class and fixed Guardfile format
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in guard-cunit.gemspec
4
+ gemspec
5
+ if RUBY_VERSION.match("1.8")
6
+ gem 'rake', :require=>true
7
+ end
8
+ gem 'guard', :require=>true
9
+ gem 'rspec-core', :require=> true
data/Guardfile ADDED
@@ -0,0 +1,11 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard 'rspec', :version => 2 do
5
+ watch(%r{^spec/.+_spec\.rb$})
6
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
7
+
8
+
9
+
10
+ end
11
+
data/README.md ADDED
@@ -0,0 +1,70 @@
1
+ # Guard CUnit [![Build Status](https://secure.travis-ci.org/teacup-on-rockingchair/guard-cunit.png?branch=master)](http://travis-ci.org/teacup-on-rockingchair/guard-cunit)
2
+
3
+ CUnit Guard allows you to run/watch Unit test for C modules, or anything other that works with Makefile
4
+
5
+ Soon will add parser for CUnit tests, and probably other UT libs
6
+
7
+ ## Install
8
+
9
+ Need to have guard and also some of the notifiers that guard uses
10
+
11
+ otherwise, get the gemfile and install it:
12
+ ```
13
+ $ gem install ./guard-cunit-*.gem
14
+ ```
15
+
16
+ will put that in rubygems soon
17
+
18
+ # Guardfile
19
+
20
+ Generating the Guardfile is like all the other
21
+
22
+ ```
23
+ $ guard init cunit
24
+ ```
25
+
26
+ The file by default looks like this:
27
+
28
+ ```
29
+ # A sample Guardfile
30
+ # More info at https://github.com/guard/guard#readme
31
+
32
+ #
33
+ # Cunit Guardfile - keep dflt builders after guard watcher's block
34
+ #
35
+ guard 'cunit' do
36
+ watch(%r{((.+)\.c$)|((.+)\.h$)|((M|m)akefile$)} )
37
+ end
38
+
39
+ set_builder "make 2>&1"
40
+ set_cleaner "make clean"
41
+ cunit_runner "#{File.basename(Dir.getwd)}_unit"
42
+ libdir "#{Dir.getwd}"
43
+
44
+ ```
45
+
46
+ After the guard block are the new methods from Guardfile DSL, which are used for the tasks needed to be performed on running the build/tests
47
+
48
+
49
+
50
+ ## Usage
51
+
52
+ For all other stuff related to guard's usage please read [Guard usage doc](https://github.com/guard/guard#readme)
53
+
54
+ Testing
55
+ -----------
56
+
57
+ Run rspec in top directory of the project or guard-rspec
58
+
59
+
60
+ Todo
61
+ -----------
62
+ - fix all bugs :)
63
+ - add parser for CUNIT tests
64
+ - add hook for coverage
65
+ - ... whatever wind blows ...
66
+
67
+ Author
68
+ ----------
69
+ [A tea cup on a rocking chair](https://github.com/strandjata)
70
+
data/Rakefile ADDED
@@ -0,0 +1,24 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ Bundler::GemHelper.install_tasks
5
+
6
+ task :default => [ :spec, :doc, :gem]
7
+
8
+
9
+ desc "Run RSpec"
10
+ RSpec::Core::RakeTask.new do |t|
11
+ t.rcov = ENV['RCOV']
12
+ t.rcov_opts = %w{--exclude osx\/objc,gems\/,spec\/}
13
+ t.verbose = true
14
+ end
15
+
16
+
17
+ task :doc do
18
+ system 'rdoc -a -U'
19
+ end
20
+
21
+ task :gem do
22
+ system 'rm guard-cunit*.gem'
23
+ system 'gem build guard-cunit.gemspec'
24
+ end
@@ -0,0 +1,29 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib/",__FILE__)
3
+
4
+ require "guard/cunit/version"
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "guard-cunit"
8
+ s.version = Guard::CunitGuard::VERSION
9
+ s.authors = ["Tea Cup On Rocking Chair"]
10
+ s.email = ["strandjata@gmail.com"]
11
+ s.platform = Gem::Platform::RUBY
12
+ s.homepage = "http://teacup-on-rockingchair.github.com/guard-cunit/"
13
+ s.summary = %q{Guard gem for CUnit-driven projects}
14
+ s.description = %q{Guard Cunit should automatically build your C project and run CUnit based tests}
15
+
16
+ s.rubyforge_project = "guard-cunit"
17
+
18
+ # specify any dependencies here; for example:
19
+ s.add_dependency 'guard', '>= 1.1'
20
+ s.add_development_dependency 'bundler'
21
+ s.add_development_dependency 'rspec'
22
+
23
+ s.files = `git ls-files`.split("\n").delete_if {|x| x.match(/(.).gem\b/)}
24
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
25
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
26
+ s.require_paths = ["lib"]
27
+
28
+
29
+ end
@@ -0,0 +1,79 @@
1
+ class TestOutput < String
2
+ # limit the output to given nr rows
3
+ def limit_to_rows(number_of_rows)
4
+ output = TestOutput.new("")
5
+ raws_count = 1;
6
+ self.lines.each do |current_line|
7
+ output += current_line
8
+ break if(raws_count == number_of_rows)
9
+ raws_count+=1
10
+ end
11
+ output=output+"..." if ( number_of_rows < self.lines.count )
12
+ output
13
+ end
14
+
15
+ # bang version
16
+ def limit_to_rows!(number_of_rows)
17
+ self.replace(limit_to_rows(number_of_rows))
18
+ end
19
+
20
+ end
21
+
22
+
23
+ module Guard
24
+ class Cunit
25
+ class CunitParser
26
+ @output
27
+ @summary_output
28
+ @failures
29
+
30
+ #constructor
31
+ def initialize (task_output = nil)
32
+ parse_output( task_output ) unless task_output == nil
33
+ end
34
+
35
+ #get cunit output
36
+ def parse_output( task_output )
37
+ task_output = "" unless task_output != nil
38
+ @output = TestOutput.new(task_output.dup)
39
+ get_summary
40
+ get_failures
41
+ end
42
+
43
+ # find summary of the cunit test reprot
44
+ def get_summary
45
+ begin
46
+ @summary_output = TestOutput.new(@output[/Run Summary:[\w\W]*/])
47
+ rescue
48
+ @summary_output = TestOutput.new("")
49
+ end
50
+ end
51
+
52
+ #find failures from Cunit test report
53
+ def get_failures
54
+ begin
55
+ @failures = TestOutput.new(@output[/[\r\n]*[ \t\f]*1. [\w\W]*:[\d]* [\w\W]*/].sub(@summary_output,"").strip)
56
+ rescue
57
+ @failures = TestOutput.new("Failed")
58
+ end
59
+ @failures.limit_to_rows!(3)
60
+ end
61
+
62
+ #display summary of the suites/tests/asserts
63
+ def cunit_output
64
+ @summary_output
65
+ end
66
+
67
+ #copy of the cunit output
68
+ def full_output
69
+ @output
70
+ end
71
+
72
+ #display failures output
73
+ def failures_output
74
+ @failures
75
+ end
76
+
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,128 @@
1
+ require 'guard/cunit/cunit_parser'
2
+
3
+
4
+ module Guard
5
+ class Cunit
6
+ #
7
+ # the class implements running and handling of results of the tasks that made up the cunit guard
8
+ #
9
+ class Runner
10
+ @@cunit_runner=''
11
+ @@project_builder=''
12
+ @@project_cleaner=''
13
+ @@project_libdir=''
14
+
15
+
16
+ def initialize
17
+ @parser = CunitParser.new()
18
+ @current_output = String.new("")
19
+ end
20
+ # set the executable file name to run CUNIT tests
21
+ def self.set_runner(name)
22
+ @@cunit_runner=name
23
+ end
24
+
25
+ # set command to run to prepare build
26
+ def self.set_builder(name)
27
+ @@project_builder=name
28
+ end
29
+
30
+ # set cleaner script/exe/command
31
+ def self.set_cleaner(name)
32
+ @@project_cleaner=name
33
+ end
34
+
35
+
36
+ # set directory where library under test is generated
37
+ def self.set_libdir(name)
38
+ @@project_libdir=name
39
+ end
40
+
41
+ #
42
+ # make wrapper for piping so we can use different approaches on win and *nix
43
+ #
44
+ def piper(exe)
45
+ if( RUBY_PLATFORM.match(/mingw/)||RUBY_PLATFORM.match(/mswin/)||RUBY_VERSION.match("1.8"))
46
+ IO.popen(exe) {|io|
47
+ yield io
48
+ }
49
+ else
50
+ IO.popen(exe.split << {:err=>[:child, :out]}) {|io|
51
+ yield io
52
+ }
53
+ end
54
+
55
+ end
56
+ #
57
+ # run one phase of the guard via a system command/executable
58
+ #
59
+ def run_task(task_executable)
60
+ success = true
61
+ piper(task_executable) {|myio|
62
+ @current_output = myio.read
63
+ }
64
+ success = false unless $?.exitstatus == 0
65
+ UI.info @current_output
66
+ success
67
+ end
68
+
69
+ # run clean before each run all start with clean
70
+ def run_clean
71
+ raise "Clean failed" unless run_task(@@project_cleaner) == true
72
+ end
73
+ def export_libdir(libdir)
74
+ case RUBY_PLATFORM
75
+ when /mingw/,/mswin/
76
+ ENV["PATH"]="#{ENV["PATH"]};#{libdir}"
77
+ when /darwin/
78
+ ENV["DYLD_LIBRARY_PATH"]="#{ENV["DYLD_LIBRARY_PATH"]}:#{libdir}"
79
+ else
80
+ ENV["LD_LIBRARY_PATH"]="#{ENV["LD_LIBRARY_PATH"]}:#{libdir}"
81
+ end
82
+ end
83
+ # run unit tests via cunit executable
84
+ def run_tests
85
+ # setup environment so it should include lib dir for ld path
86
+ export_libdir(@@project_libdir)
87
+
88
+ if( !File.exists? (@@cunit_runner) )
89
+ Notifier.notify("Pending", :title => "Test Not Defined", :image => :pending, :priority => 2)
90
+ success = false
91
+ else
92
+ success = run_task(@@cunit_runner)
93
+ @parser.parse_output(@current_output)
94
+ if success == true
95
+ Notifier.notify("Success", :title => "Test Passed", :image => :passed, :priority => 2)
96
+ else
97
+ Notifier.notify(@parser.failures_output, :title => "Test Failed", :image => :failed, :priority => 2 )
98
+ end
99
+ end
100
+ raise "Test failed" unless success == true
101
+ end
102
+
103
+
104
+ # run make command to build the project
105
+ def run_make
106
+ success = run_task(@@project_builder)
107
+ Notifier.notify("Failed", :title => "Build Failed", :image => :failed, :priority => 2) unless success == true
108
+ raise "Build failed" unless success == true
109
+ end
110
+ # run them all
111
+ def run
112
+ UI.info "Test runner: #{@@cunit_runner}"
113
+ UI.info "Builder: #{@@project_builder}"
114
+ UI.info "Cleaner: #{@@project_cleaner}"
115
+ UI.info "Libdir: #{@@project_libdir}"
116
+ begin
117
+ run_clean
118
+ run_make
119
+ run_tests
120
+ rescue
121
+ return false
122
+ end
123
+ true
124
+ end
125
+
126
+ end
127
+ end
128
+ end
@@ -0,0 +1,12 @@
1
+ #
2
+ # Cunit Guardfile - keep dflt builders after guard watcher's block
3
+ #
4
+ guard 'cunit' do
5
+ watch(%r{((.+)\.c$)|((.+)\.h$)|((M|m)akefile$)} )
6
+ end
7
+
8
+ set_builder "make 2>&1"
9
+ set_cleaner "make clean"
10
+ cunit_runner "#{File.basename(Dir.getwd)}_unit"
11
+ libdir "#{Dir.getwd}"
12
+
@@ -0,0 +1,7 @@
1
+ #version
2
+ module Guard
3
+ module CunitGuard
4
+ # version of the gem
5
+ VERSION="0.0.2"
6
+ end
7
+ end
@@ -0,0 +1,69 @@
1
+ require 'guard'
2
+ require 'guard/guard'
3
+
4
+
5
+ module Guard
6
+ # main child class of Guard to nherit guard's behaviour
7
+ class Cunit < Guard
8
+ autoload :Runner, 'guard/cunit/runner'
9
+ # new method that also creates the runner class
10
+ def initialize(watchers = [], options = {})
11
+ super
12
+ @options = {
13
+ :all_on_start => true,
14
+ }.update(options)
15
+ @runner = Runner.new()
16
+ end
17
+ # Called when just `enter` is pressed
18
+ # This method should be principally used for long action like running all specs/tests/...
19
+ # @raise [:task_has_failed] when run_all has failed
20
+ def run_all
21
+ passed = @runner.run
22
+ throw :task_has_failed unless passed
23
+ end
24
+ def run_on_change(paths)
25
+ UI.info("Process changes in #{paths}")
26
+ passed = run_all
27
+ end
28
+ end
29
+
30
+ #
31
+ # add more behaviour to Guard's DSL to be able to configure executors
32
+ # of all the CUnit's Guard tasks
33
+ #
34
+ class Dsl
35
+ #
36
+ # put default values to task executors
37
+ #
38
+ def initialize
39
+ super
40
+ set_cleaner("make clean")
41
+ cunit_runner("./#{File.basename(Dir.getwd)}_unit")
42
+ set_builder("make 2>&1")
43
+ libdir("#{Dir.getwd}")
44
+ @runner = Cunit::Runner.new
45
+ end
46
+
47
+ # dsl call to set cunit test executable
48
+ def cunit_runner (name)
49
+ Cunit::Runner.set_runner(name)
50
+ end
51
+
52
+ # dsl call to set cunit build command/script, by default make
53
+ def set_builder (name)
54
+ Cunit::Runner.set_builder(name)
55
+ end
56
+
57
+ #dsl call to set cunit clean command/script, by default 'make clean'
58
+ def set_cleaner (name)
59
+ Cunit::Runner.set_cleaner(name)
60
+ end
61
+
62
+ # dsl call to set dir, where library under test is generated, by default current dir
63
+ def libdir(name)
64
+ Cunit::Runner.set_libdir(File.expand_path(name))
65
+ end
66
+
67
+ end
68
+
69
+ end
@@ -0,0 +1,83 @@
1
+ require "spec_helper.rb"
2
+
3
+
4
+ describe Guard::Cunit::CunitParser do
5
+ before(:each) do
6
+
7
+ @long_fake_output = String.new(" CUnit - A unit testing framework for C - Version 2.1-2
8
+ http://cunit.sourceforge.net/
9
+
10
+ Suite Simple calc CUNIT suite, Test Addition test had failures:
11
+ 1. simplecalc_test.c:7 - CU_FAIL(\"TODO\")
12
+ 2. simplecalc_test.c:17 - CU_FAIL(\"TODO\")
13
+ 3. simplecalc_test.c:27 - CU_FAIL(\"TODO\")
14
+ 4. simplecalc_test.c:37 - CU_FAIL(\"TODO\")
15
+ 5. simplecalc_test.c:47 - CU_FAIL(\"TODO\")
16
+ 6. simplecalc_test.c:57 - CU_FAIL(\"TODO\")
17
+ 7. simplecalc_test.c:67 - CU_FAIL(\"TODO\")
18
+ 8. simplecalc_test.c:77 - CU_FAIL(\"TODO\")
19
+ 9. simplecalc_test.c:87 - CU_FAIL(\"TODO\")
20
+ 10. simplecalc_test.c:97 - CU_FAIL(\"TODO\")
21
+
22
+
23
+ Run Summary: Type Total Ran Passed Failed Inactive
24
+ suites 1 1 n/a 0 0
25
+ tests 10 10 0 10 0
26
+ asserts 10 10 0 10 n/a
27
+
28
+ Elapsed time = 0.000 seconds")
29
+
30
+
31
+ @fake_output = String.new(" CUnit - A unit testing framework for C - Version 2.1-2
32
+ http://cunit.sourceforge.net/
33
+
34
+ Suite Simple calc CUNIT suite, Test Addition test had failures:
35
+ 1. simplecalc_test.c:7 - CU_FAIL(\"TODO\")
36
+
37
+ Run Summary: Type Total Ran Passed Failed Inactive
38
+ suites 1 1 n/a 0 0
39
+ tests 1 1 0 1 0
40
+ asserts 1 1 0 1 n/a
41
+
42
+ Elapsed time = 0.000 seconds")
43
+
44
+ @fake_fail_summary = String.new("1. simplecalc_test.c:7 - CU_FAIL(\"TODO\")")
45
+
46
+ @fake_summary = String.new("Run Summary: Type Total Ran Passed Failed Inactive
47
+ suites 1 1 n/a 0 0
48
+ tests 1 1 0 1 0
49
+ asserts 1 1 0 1 n/a
50
+
51
+ Elapsed time = 0.000 seconds")
52
+
53
+ @shortened_fail_summary = String.new("1. simplecalc_test.c:7 - CU_FAIL(\"TODO\")
54
+ 2. simplecalc_test.c:17 - CU_FAIL(\"TODO\")
55
+ 3. simplecalc_test.c:27 - CU_FAIL(\"TODO\")
56
+ ...")
57
+
58
+ end
59
+
60
+
61
+ it "should generate a UI summary and full output from given text input" do
62
+ parser = Guard::Cunit::CunitParser.new(@fake_output)
63
+ parser.full_output.should == @fake_output
64
+ parser.cunit_output.should == (@fake_summary)
65
+ parser.failures_output.should == (@fake_fail_summary)
66
+ end
67
+
68
+ it "failure summary should be maximum a 3 row output" do
69
+ parser = Guard::Cunit::CunitParser.new(@long_fake_output)
70
+ parser.failures_output.should == (@shortened_fail_summary)
71
+ end
72
+
73
+ it "should be able to init with no output and later trigger process" do
74
+ parser = Guard::Cunit::CunitParser.new()
75
+ parser.parse_output(@long_fake_output)
76
+ parser.failures_output.should == (@shortened_fail_summary)
77
+ end
78
+ it "should be able to handle test exe with no output and put just failed as failure message" do
79
+ parser = Guard::Cunit::CunitParser.new()
80
+ parser.parse_output(nil)
81
+ parser.failures_output.should == ("Failed")
82
+ end
83
+ end
@@ -0,0 +1,239 @@
1
+ require "spec_helper.rb"
2
+
3
+ describe Guard::Cunit do
4
+
5
+ before (:all) do
6
+ @@first = true
7
+ @tmp_env = TempPrjEnv.new
8
+ @work_dir = Dir.getwd
9
+ end
10
+
11
+ def get_ld_path
12
+ case RUBY_PLATFORM
13
+ when /mingw/
14
+ ENV["PATH"]
15
+ when /mswin/
16
+ ENV["PATH"]
17
+ when /darwin/
18
+ ENV["DYLD_LIBRARY_PATH"]
19
+ else
20
+ ENV["LD_LIBRARY_PATH"]
21
+ end
22
+ end
23
+ def setup_guard
24
+ if @@first == true
25
+ Guard::setup({:no_interactions => true})
26
+ @@first = false
27
+ else
28
+ Guard::reload({})
29
+ end
30
+ end
31
+
32
+ before(:each) do
33
+ Dir.chdir(@work_dir)
34
+ tmp_work_dir=@tmp_env.create_tmp_prj_dir
35
+ Dir.chdir((tmp_work_dir))
36
+ Guard::UI.stub(:info)
37
+ IO.stub(:popen)
38
+ end
39
+
40
+ after(:each) do
41
+ Dir.chdir(@work_dir)
42
+ @tmp_env.cleanup_tmp_prj_dir
43
+ end
44
+
45
+ it "should inherit Guard class" do
46
+ subject.class.ancestors.should include(Guard::Guard)
47
+ end
48
+
49
+ context "Run guard" do
50
+
51
+ it "should run build" do
52
+
53
+ guardfile_has_unit_test_exe()
54
+ popen_successfull_fake("make clean")
55
+ popen_successfull_fake("make 2>&1")
56
+ fake_test_exe("./#{File.basename(Dir.getwd)}_unit",:pass)
57
+ cguard = Guard::Cunit::Runner.new
58
+ setup_guard
59
+ cguard.run
60
+
61
+ end
62
+
63
+
64
+ it "should run build on changes " do
65
+
66
+ cguard = Guard::Cunit.new
67
+ cguard.stub(:run_all).and_return(true)
68
+ Guard::UI.should_receive(:info).with("Process changes in #{File.basename(Dir.getwd)}")
69
+
70
+ cguard.run_on_change("#{File.basename(Dir.getwd)}")
71
+
72
+ end
73
+
74
+ it "should set libpath for executbles with current project directory by default" do
75
+ oldenv=get_ld_path
76
+
77
+ guardfile_has_unit_test_exe(:test_exe=>"jiji")
78
+ popen_successfull_fake("make clean")
79
+ popen_successfull_fake("make 2>&1")
80
+ fake_test_exe("./jiji",:pass)
81
+
82
+ cguard = Guard::Cunit::Runner.new
83
+ setup_guard
84
+ cguard.run
85
+ newenv =get_ld_path
86
+ newenv.should include("#{oldenv}")
87
+ newenv.should include("#{Dir.getwd}")
88
+ get_ld_path=oldenv
89
+ end
90
+
91
+
92
+ it "should set libpath to predefined lib directory when user has specified such in the Guardfile" do
93
+ oldenv=get_ld_path
94
+
95
+ guardfile_has_unit_test_exe(:test_exe=>"jiji",:libdir=>'lib')
96
+ popen_successfull_fake("make clean")
97
+ popen_successfull_fake("make 2>&1")
98
+ fake_test_exe("./jiji",:pass)
99
+
100
+ cguard = Guard::Cunit::Runner.new
101
+ setup_guard
102
+ cguard.run
103
+ newenv =get_ld_path
104
+ newenv.should include("#{oldenv}")
105
+ newenv.should include("#{File.join(Dir.getwd,"lib")}")
106
+ get_ld_path=oldenv
107
+ end
108
+
109
+
110
+ it "should run cunit test define in the Guardfile" do
111
+ guardfile_has_unit_test_exe(:test_exe =>"didi")
112
+
113
+ popen_successfull_fake("make clean")
114
+ popen_successfull_fake("make 2>&1")
115
+
116
+
117
+ fake_test_exe("./didi",:pass)
118
+ cguard = Guard::Cunit::Runner.new
119
+ setup_guard
120
+ cguard.run
121
+
122
+ end
123
+
124
+
125
+ it "should run predefined build command" do
126
+ guardfile_has_unit_test_exe(:test_exe =>"jiji",:builder => "./make_all.sh")
127
+ fake_test_exe("./jiji",:pass)
128
+ popen_successfull_fake("./make_all.sh")
129
+
130
+ popen_successfull_fake("make clean")
131
+
132
+ cguard = Guard::Cunit::Runner.new
133
+ setup_guard
134
+ cguard.run
135
+
136
+ end
137
+
138
+ it "should run predefined clean command" do
139
+ guardfile_has_unit_test_exe(:test_exe =>"jiji",:builder => "./make_all.sh",:cleaner=> "./clean_all.sh")
140
+ fake_test_exe("./jiji",:pass)
141
+ popen_successfull_fake("./make_all.sh")
142
+ popen_successfull_fake("./clean_all.sh")
143
+ cguard = Guard::Cunit::Runner.new
144
+ setup_guard
145
+ cguard.run
146
+
147
+ end
148
+
149
+ end
150
+
151
+
152
+ context "Handle exit codes" do
153
+ it "should report failure on build failed" do
154
+ guardfile_has_unit_test_exe()
155
+ popen_successfull_fake("make clean")
156
+ popen_failing_fake("make 2>&1")
157
+ cguard = Guard::Cunit::Runner.new
158
+ setup_guard
159
+ cguard.run.should == false
160
+ end
161
+
162
+ it "should block further tasks on build failed" do
163
+ guardfile_has_unit_test_exe(:test_exe=>"jiji")
164
+ popen_successfull_fake("make clean")
165
+ popen_failing_fake("make 2>&1")
166
+ f = File.new("./jiji", "w+", 0666)
167
+ f.close
168
+ IO.stub(:popen).with("jiji".split << {:err=>[:child, :out]})
169
+ IO.should_not_receive(:popen).with("jiji".split << {:err=>[:child, :out]})
170
+ cguard = Guard::Cunit::Runner.new
171
+ setup_guard
172
+ cguard.run.should == false
173
+ end
174
+
175
+
176
+ it "should report failure on test failed" do
177
+ guardfile_has_unit_test_exe(:test_exe=>"jiji")
178
+ popen_successfull_fake("make clean")
179
+ popen_successfull_fake("make 2>&1")
180
+ fake_test_exe("./jiji",:fail)
181
+ cguard = Guard::Cunit::Runner.new
182
+ setup_guard
183
+ cguard.run.should == false
184
+ end
185
+
186
+ end
187
+
188
+
189
+ context "Displaying notifications" do
190
+
191
+ it "should display failure if build fails" do
192
+ Guard::Notifier.stub(:notify)
193
+ guardfile_has_unit_test_exe()
194
+ Guard::Notifier.should_receive(:notify).with("Failed", :title => "Build Failed", :image => :failed, :priority => 2)
195
+ popen_successfull_fake("make clean")
196
+ popen_failing_fake("make 2>&1")
197
+ cguard = Guard::Cunit::Runner.new
198
+ setup_guard
199
+ cguard.run
200
+ end
201
+
202
+ it "should display failure if test fails" do
203
+ IO.stub(:popen)
204
+ Guard::Notifier.stub(:notify)
205
+ guardfile_has_unit_test_exe(:test_exe=>"jiji")
206
+ Guard::Notifier.should_receive(:notify).with( anything(), :title => "Test Failed", :image => :failed, :priority => 2 )
207
+ popen_successfull_fake("make clean")
208
+ popen_successfull_fake("make 2>&1")
209
+ fake_test_exe("./jiji",:fail)
210
+ cguard = Guard::Cunit::Runner.new
211
+ setup_guard
212
+ cguard.run
213
+ end
214
+
215
+ it "should display pending if test is absent" do
216
+ Guard::Notifier.stub(:notify)
217
+ guardfile_has_unit_test_exe()
218
+ Guard::Notifier.should_receive(:notify).with("Pending", :title => "Test Not Defined", :image => :pending, :priority => 2)
219
+ popen_successfull_fake("make clean")
220
+ popen_successfull_fake("make 2>&1")
221
+ cguard = Guard::Cunit::Runner.new
222
+ setup_guard
223
+ cguard.run
224
+ end
225
+
226
+ it "should display success if build and test succeeded" do
227
+ Guard::Notifier.stub(:notify)
228
+ guardfile_has_unit_test_exe()
229
+ Guard::Notifier.should_receive(:notify).with("Success", :title => "Test Passed", :image => :passed, :priority => 2)
230
+ popen_successfull_fake("make clean")
231
+ popen_successfull_fake("make 2>&1")
232
+ fake_test_exe(nil,:pass)
233
+ cguard = Guard::Cunit::Runner.new
234
+ Guard.add_guard('cunit')
235
+ cguard.run
236
+ end
237
+ end
238
+
239
+ end
@@ -0,0 +1,108 @@
1
+ require 'rubygems'
2
+ require 'fileutils'
3
+ require 'pathname'
4
+ require 'guard'
5
+ require 'guard/cunit'
6
+ require 'guard/cunit/runner'
7
+ require 'guard/cunit/cunit_parser'
8
+ require 'rspec'
9
+
10
+ # a class to set/cleanup environment for fake project
11
+ class TempPrjEnv
12
+ def initialize
13
+ @test_tmp = (Pathname.new(Dir.getwd)+"tmp").to_s
14
+ @test_prj_dir= ((Pathname.new(Dir.getwd)+"tmp")+"1test_prj").to_s
15
+ end
16
+
17
+ # create a tmp subdir and within it fake project directory
18
+ def create_tmp_prj_dir
19
+ begin
20
+ Dir.mkdir(@test_tmp,0777)
21
+ Dir.mkdir(@test_prj_dir,0777)
22
+ rescue Exception => e
23
+ puts "Could not make #{@test_tmp} dirs at #{Dir.getwd} - #{e.to_s}"
24
+ end
25
+ @test_prj_dir
26
+ end
27
+
28
+ # cleanup the subdir
29
+ def cleanup_tmp_prj_dir
30
+ begin
31
+ FileUtils.rm_r(@test_tmp)
32
+ rescue Exception => e
33
+ puts "Could not remove dirs #{e.to_s}"
34
+ end
35
+ end
36
+ end
37
+
38
+
39
+ #define fake script to return given exit code
40
+ def fake_script(code)
41
+
42
+ case RUBY_PLATFORM
43
+ when /mingw/
44
+ `exit #{code}`
45
+ when /mswin/
46
+ `exit #{code}`
47
+ else
48
+ `(exit #{code})`
49
+ end
50
+ end
51
+
52
+
53
+ #wrapper for popen for different platforms
54
+ def popen_fake(fakename,exp_result)
55
+
56
+ if( RUBY_PLATFORM.match(/mingw/)||RUBY_PLATFORM.match(/mswin/)||RUBY_VERSION.match("1.8"))
57
+ pipe_args = fakename
58
+ else
59
+ pipe_args = fakename.split << {:err=>[:child, :out]}
60
+ end
61
+
62
+ IO.stub(:popen).with(pipe_args)
63
+ if exp_result == false
64
+ IO.should_receive(:popen).with(pipe_args) { fake_script(1) }
65
+ else
66
+ IO.should_receive(:popen).with(pipe_args) { fake_script(0) }
67
+ end
68
+ end
69
+
70
+
71
+ # setup stub for system command with successful exit result
72
+ def popen_successfull_fake(fakename)
73
+ popen_fake(fakename,true)
74
+ end
75
+
76
+ # setup stub for system command with failing exit result
77
+ def popen_failing_fake(fakename)
78
+
79
+ popen_fake(fakename,false)
80
+ end
81
+
82
+ # fake the test executable runner, its existance and result
83
+ def fake_test_exe(exe_name,successful = :fail)
84
+ exe_name="./#{File.basename(Dir.getwd)}_unit" unless exe_name != nil
85
+ f = File.new(exe_name, "w+", 0666)
86
+ f.close
87
+ if successful == :pass
88
+ popen_successfull_fake(exe_name)
89
+ else
90
+ popen_failing_fake(exe_name)
91
+ end
92
+ end
93
+
94
+ # a generator for CUnit Guardfile
95
+ def guardfile_has_unit_test_exe(params={ :test_exe=>nil, :builder=>nil, :cleaner=>nil, :libdir=>nil})
96
+ File.open("Guardfile","w+",0644) do |file|
97
+ file.puts "guard \'cunit\' do"
98
+
99
+ file.puts " set_builder \"#{params[:builder]}\"" unless (params[:builder] == nil)
100
+ file.puts " set_cleaner \"#{params[:cleaner]}\"" unless (params[:cleaner] == nil)
101
+ file.puts " cunit_runner \"./#{params[:test_exe]}\"" unless (params[:test_exe] == nil)
102
+ file.puts " libdir \"#{params[:libdir]}\"" unless (params[:libdir] == nil)
103
+
104
+ file.puts ' watch(%r{((.+)\.c$)|((.+)\.h$)|((M|m)akefile$)} ) '
105
+ file.puts 'end'
106
+ end
107
+ end
108
+
metadata ADDED
@@ -0,0 +1,122 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: guard-cunit
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 2
10
+ version: 0.0.2
11
+ platform: ruby
12
+ authors:
13
+ - Tea Cup On Rocking Chair
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-12-02 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ type: :runtime
22
+ requirement: &id001 !ruby/object:Gem::Requirement
23
+ none: false
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ hash: 13
28
+ segments:
29
+ - 1
30
+ - 1
31
+ version: "1.1"
32
+ prerelease: false
33
+ name: guard
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ type: :development
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ hash: 3
43
+ segments:
44
+ - 0
45
+ version: "0"
46
+ prerelease: false
47
+ name: bundler
48
+ version_requirements: *id002
49
+ - !ruby/object:Gem::Dependency
50
+ type: :development
51
+ requirement: &id003 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ hash: 3
57
+ segments:
58
+ - 0
59
+ version: "0"
60
+ prerelease: false
61
+ name: rspec
62
+ version_requirements: *id003
63
+ description: Guard Cunit should automatically build your C project and run CUnit based tests
64
+ email:
65
+ - strandjata@gmail.com
66
+ executables: []
67
+
68
+ extensions: []
69
+
70
+ extra_rdoc_files: []
71
+
72
+ files:
73
+ - .travis.yml
74
+ - CHANGELOG.md
75
+ - Gemfile
76
+ - Guardfile
77
+ - README.md
78
+ - Rakefile
79
+ - guard-cunit.gemspec
80
+ - lib/guard/cunit.rb
81
+ - lib/guard/cunit/cunit_parser.rb
82
+ - lib/guard/cunit/runner.rb
83
+ - lib/guard/cunit/templates/Guardfile
84
+ - lib/guard/cunit/version.rb
85
+ - spec/guard_cunit_parser_spec.rb
86
+ - spec/guard_cunit_spec.rb
87
+ - spec/spec_helper.rb
88
+ homepage: http://teacup-on-rockingchair.github.com/guard-cunit/
89
+ licenses: []
90
+
91
+ post_install_message:
92
+ rdoc_options: []
93
+
94
+ require_paths:
95
+ - lib
96
+ required_ruby_version: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ hash: 3
102
+ segments:
103
+ - 0
104
+ version: "0"
105
+ required_rubygems_version: !ruby/object:Gem::Requirement
106
+ none: false
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ hash: 3
111
+ segments:
112
+ - 0
113
+ version: "0"
114
+ requirements: []
115
+
116
+ rubyforge_project: guard-cunit
117
+ rubygems_version: 1.8.24
118
+ signing_key:
119
+ specification_version: 3
120
+ summary: Guard gem for CUnit-driven projects
121
+ test_files: []
122
+