guard-cunit 0.0.1-x86-linux
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +11 -0
- data/CHANGELOG.md +1 -0
- data/Gemfile +6 -0
- data/Guardfile +11 -0
- data/README.md +70 -0
- data/Rakefile +24 -0
- data/doc/Gemfile.html +110 -0
- data/doc/Guard/Cunit/CunitParser.html +396 -0
- data/doc/Guard/Cunit/Runner.html +522 -0
- data/doc/Guard/Cunit.html +278 -0
- data/doc/Guard/CunitGuard.html +156 -0
- data/doc/Guard/Dsl.html +338 -0
- data/doc/Guard.html +149 -0
- data/doc/Guardfile.html +116 -0
- data/doc/Object.html +359 -0
- data/doc/Rakefile.html +132 -0
- data/doc/TempPrjEnv.html +239 -0
- data/doc/TestOutput.html +235 -0
- data/doc/created.rid +12 -0
- data/doc/images/add.png +0 -0
- data/doc/images/brick.png +0 -0
- data/doc/images/brick_link.png +0 -0
- data/doc/images/bug.png +0 -0
- data/doc/images/bullet_black.png +0 -0
- data/doc/images/bullet_toggle_minus.png +0 -0
- data/doc/images/bullet_toggle_plus.png +0 -0
- data/doc/images/date.png +0 -0
- data/doc/images/delete.png +0 -0
- data/doc/images/find.png +0 -0
- data/doc/images/loadingAnimation.gif +0 -0
- data/doc/images/macFFBgHack.png +0 -0
- data/doc/images/package.png +0 -0
- data/doc/images/page_green.png +0 -0
- data/doc/images/page_white_text.png +0 -0
- data/doc/images/page_white_width.png +0 -0
- data/doc/images/plugin.png +0 -0
- data/doc/images/ruby.png +0 -0
- data/doc/images/tag_blue.png +0 -0
- data/doc/images/tag_green.png +0 -0
- data/doc/images/transparent.png +0 -0
- data/doc/images/wrench.png +0 -0
- data/doc/images/wrench_orange.png +0 -0
- data/doc/images/zoom.png +0 -0
- data/doc/index.html +102 -0
- data/doc/js/darkfish.js +153 -0
- data/doc/js/jquery.js +18 -0
- data/doc/js/navigation.js +142 -0
- data/doc/js/search.js +94 -0
- data/doc/js/search_index.js +1 -0
- data/doc/js/searcher.js +228 -0
- data/doc/lib/guard/cunit/templates/Guardfile.html +115 -0
- data/doc/rdoc.css +543 -0
- data/doc/table_of_contents.html +157 -0
- data/guard-cunit.gemspec +29 -0
- data/lib/guard/cunit/cunit_parser.rb +70 -0
- data/lib/guard/cunit/runner.rb +99 -0
- data/lib/guard/cunit/templates/Guardfile +12 -0
- data/lib/guard/cunit/version.rb +7 -0
- data/lib/guard/cunit.rb +69 -0
- data/spec/guard_cunit_parser_spec.rb +79 -0
- data/spec/guard_cunit_spec.rb +198 -0
- data/spec/spec_helper.rb +72 -0
- metadata +167 -0
data/guard-cunit.gemspec
ADDED
@@ -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::CURRENT
|
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,70 @@
|
|
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
|
+
@output = TestOutput.new(task_output.dup)
|
38
|
+
get_summary
|
39
|
+
get_failures
|
40
|
+
end
|
41
|
+
|
42
|
+
# find summary of the cunit test reprot
|
43
|
+
def get_summary
|
44
|
+
@summary_output = TestOutput.new(@output[/Run Summary:[\w\W]*/])
|
45
|
+
end
|
46
|
+
|
47
|
+
#find failures from Cunit test report
|
48
|
+
def get_failures
|
49
|
+
@failures = TestOutput.new(@output[/Suite[\w\W]*/].sub(@summary_output,"").strip)
|
50
|
+
@failures.limit_to_rows!(3)
|
51
|
+
end
|
52
|
+
|
53
|
+
#display summary of the suites/tests/asserts
|
54
|
+
def cunit_output
|
55
|
+
@summary_output
|
56
|
+
end
|
57
|
+
|
58
|
+
#copy of the cunit output
|
59
|
+
def full_output
|
60
|
+
@output
|
61
|
+
end
|
62
|
+
|
63
|
+
#display failures output
|
64
|
+
def failures_output
|
65
|
+
@failures
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,99 @@
|
|
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
|
+
# run one phase of the guard via a system command/executable
|
43
|
+
#
|
44
|
+
def run_task(task_executable)
|
45
|
+
success = true
|
46
|
+
IO.popen(task_executable) do |myio|
|
47
|
+
@current_output = myio.read
|
48
|
+
end
|
49
|
+
success = false unless $?.exitstatus == 0
|
50
|
+
UI.info @current_output
|
51
|
+
success
|
52
|
+
end
|
53
|
+
|
54
|
+
# run clean before each run all start with clean
|
55
|
+
def run_clean
|
56
|
+
run_task(@@project_cleaner)
|
57
|
+
end
|
58
|
+
|
59
|
+
# run unit tests via cunit executable
|
60
|
+
def run_tests
|
61
|
+
# setup environment so it should include lib dir for ld path
|
62
|
+
ENV["LD_LIBRARY_PATH"]="#{ENV["LD_LIBRARY_PATH"]}:#{@@project_libdir}"
|
63
|
+
|
64
|
+
if( !File.exists? (@@cunit_runner) )
|
65
|
+
Notifier.notify("Pending", :title => "Test Not Defined", :image => :pending, :priority => 2)
|
66
|
+
success = false
|
67
|
+
else
|
68
|
+
success = run_task(@@cunit_runner)
|
69
|
+
@parser.parse_output(@current_output) unless (@cunit_output == nil)
|
70
|
+
if success == true
|
71
|
+
Notifier.notify("Success", :title => "Test Passed", :image => :passed, :priority => 2)
|
72
|
+
else
|
73
|
+
Notifier.notify("Failed", :title => "Test Failed", :image => :failed, :priority => 2,:message => @parser.failures_output)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
success
|
77
|
+
end
|
78
|
+
|
79
|
+
|
80
|
+
# run make command to build the project
|
81
|
+
def run_make
|
82
|
+
success = run_task(@@project_builder)
|
83
|
+
Notifier.notify("Failed", :title => "Build Failed", :image => :failed, :priority => 2) unless success == true
|
84
|
+
end
|
85
|
+
# run them all
|
86
|
+
def run
|
87
|
+
UI.info "Test runner: #{@@cunit_runner}"
|
88
|
+
UI.info "Builder: #{@@project_builder}"
|
89
|
+
UI.info "Cleaner: #{@@project_cleaner}"
|
90
|
+
UI.info "Libdir: #{@@project_libdir}"
|
91
|
+
|
92
|
+
run_clean
|
93
|
+
run_make
|
94
|
+
run_tests
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|
98
|
+
end
|
99
|
+
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
|
+
|
data/lib/guard/cunit.rb
ADDED
@@ -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,79 @@
|
|
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("Suite Simple calc CUNIT suite, Test Addition test had failures:
|
45
|
+
1. simplecalc_test.c:7 - CU_FAIL(\"TODO\")")
|
46
|
+
|
47
|
+
@fake_summary = String.new("Run Summary: Type Total Ran Passed Failed Inactive
|
48
|
+
suites 1 1 n/a 0 0
|
49
|
+
tests 1 1 0 1 0
|
50
|
+
asserts 1 1 0 1 n/a
|
51
|
+
|
52
|
+
Elapsed time = 0.000 seconds")
|
53
|
+
|
54
|
+
@shortened_fail_summary = String.new("Suite Simple calc CUNIT suite, Test Addition test had failures:
|
55
|
+
1. simplecalc_test.c:7 - CU_FAIL(\"TODO\")
|
56
|
+
2. simplecalc_test.c:17 - CU_FAIL(\"TODO\")
|
57
|
+
...")
|
58
|
+
|
59
|
+
end
|
60
|
+
|
61
|
+
|
62
|
+
it "should generate a UI summary and full output from given text input" do
|
63
|
+
parser = Guard::Cunit::CunitParser.new(@fake_output)
|
64
|
+
parser.full_output.should == @fake_output
|
65
|
+
parser.cunit_output.should == (@fake_summary)
|
66
|
+
parser.failures_output.should == (@fake_fail_summary)
|
67
|
+
end
|
68
|
+
|
69
|
+
it "failure summary should be maximum a 3 row output" do
|
70
|
+
parser = Guard::Cunit::CunitParser.new(@long_fake_output)
|
71
|
+
parser.failures_output.should == (@shortened_fail_summary)
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should be able to init with no output and later trigger process" do
|
75
|
+
parser = Guard::Cunit::CunitParser.new()
|
76
|
+
parser.parse_output @long_fake_output
|
77
|
+
parser.failures_output.should == (@shortened_fail_summary)
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,198 @@
|
|
1
|
+
require "spec_helper.rb"
|
2
|
+
|
3
|
+
|
4
|
+
describe Guard::Cunit do
|
5
|
+
|
6
|
+
before (:all) do
|
7
|
+
@@first = true
|
8
|
+
end
|
9
|
+
|
10
|
+
def setup_guard
|
11
|
+
if @@first == true
|
12
|
+
Guard::setup
|
13
|
+
@@first = false
|
14
|
+
else
|
15
|
+
Guard::reload
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
before(:each) do
|
20
|
+
tmp_work_dir=TempPrjEnv.create_tmp_prj_dir
|
21
|
+
@work_dir = Dir.getwd
|
22
|
+
Dir.chdir(tmp_work_dir)
|
23
|
+
Guard::UI.stub(:info)
|
24
|
+
IO.stub(:popen)
|
25
|
+
end
|
26
|
+
|
27
|
+
after(:each) do
|
28
|
+
Dir.chdir(@work_dir)
|
29
|
+
TempPrjEnv.cleanup_tmp_prj_dir
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should inherit Guard class" do
|
33
|
+
subject.class.ancestors.should include(Guard::Guard)
|
34
|
+
end
|
35
|
+
|
36
|
+
context "Run guard" do
|
37
|
+
|
38
|
+
it "should run build" do
|
39
|
+
|
40
|
+
guardfile_has_unit_test_exe()
|
41
|
+
popen_successfull_fake("make clean")
|
42
|
+
popen_successfull_fake("make 2>&1")
|
43
|
+
fake_test_exe("#{File.basename(Dir.getwd)}_unit",:pass)
|
44
|
+
cguard = Guard::Cunit::Runner.new
|
45
|
+
setup_guard
|
46
|
+
cguard.run
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
|
51
|
+
it "should run build on changes " do
|
52
|
+
|
53
|
+
cguard = Guard::Cunit.new
|
54
|
+
cguard.stub(:run_all).and_return(true)
|
55
|
+
Guard::UI.should_receive(:info).with("Process changes in #{File.basename(Dir.getwd)}")
|
56
|
+
|
57
|
+
cguard.run_on_change("#{File.basename(Dir.getwd)}")
|
58
|
+
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should set libpath for executbles with current project directory by default" do
|
62
|
+
oldenv=ENV["LD_LIBRARY_PATH"]
|
63
|
+
guardfile_has_unit_test_exe()
|
64
|
+
cguard = Guard::Cunit::Runner.new
|
65
|
+
setup_guard
|
66
|
+
cguard.run
|
67
|
+
newenv =ENV["LD_LIBRARY_PATH"]
|
68
|
+
newenv.should match("#{oldenv}:#{Dir.getwd}")
|
69
|
+
ENV["LD_LIBRARY_PATH"]=oldenv
|
70
|
+
end
|
71
|
+
|
72
|
+
|
73
|
+
it "should set libpath to predefined lib directory when user has specified such in the Guardfile" do
|
74
|
+
oldenv=ENV["LD_LIBRARY_PATH"]
|
75
|
+
guardfile_has_unit_test_exe(:libdir=>'./lib')
|
76
|
+
cguard = Guard::Cunit::Runner.new
|
77
|
+
setup_guard
|
78
|
+
cguard.run
|
79
|
+
newenv =ENV["LD_LIBRARY_PATH"]
|
80
|
+
newenv.should match("#{oldenv}:#{Dir.getwd}/lib")
|
81
|
+
ENV["LD_LIBRARY_PATH"]=oldenv
|
82
|
+
end
|
83
|
+
|
84
|
+
|
85
|
+
it "should run cunit test define in the Guardfile" do
|
86
|
+
guardfile_has_unit_test_exe(:test_exe => "jiji")
|
87
|
+
fake_test_exe("jiji",:pass)
|
88
|
+
cguard = Guard::Cunit.new
|
89
|
+
setup_guard
|
90
|
+
cguard.run_all
|
91
|
+
|
92
|
+
guardfile_has_unit_test_exe(:test_exe =>"didi")
|
93
|
+
fake_test_exe("didi",:pass)
|
94
|
+
cguard = Guard::Cunit::Runner.new
|
95
|
+
setup_guard
|
96
|
+
cguard.run
|
97
|
+
|
98
|
+
end
|
99
|
+
|
100
|
+
|
101
|
+
it "should run predefined build command" do
|
102
|
+
guardfile_has_unit_test_exe(:test_exe =>"jiji",:builder => "./make_all.sh")
|
103
|
+
fake_test_exe("jiji",:pass)
|
104
|
+
popen_successfull_fake("./make_all.sh")
|
105
|
+
cguard = Guard::Cunit::Runner.new
|
106
|
+
setup_guard
|
107
|
+
cguard.run
|
108
|
+
|
109
|
+
end
|
110
|
+
|
111
|
+
it "should run predefined clean command" do
|
112
|
+
guardfile_has_unit_test_exe(:test_exe =>"jiji",:builder => "./make_all.sh",:cleaner=> "./clean_all.sh")
|
113
|
+
fake_test_exe("jiji",:pass)
|
114
|
+
popen_successfull_fake("./make_all.sh")
|
115
|
+
popen_successfull_fake("./clean_all.sh")
|
116
|
+
cguard = Guard::Cunit::Runner.new
|
117
|
+
setup_guard
|
118
|
+
cguard.run
|
119
|
+
|
120
|
+
end
|
121
|
+
|
122
|
+
end
|
123
|
+
|
124
|
+
|
125
|
+
context "Handle exit codes" do
|
126
|
+
it "should report failure on build failed" do
|
127
|
+
guardfile_has_unit_test_exe()
|
128
|
+
popen_successfull_fake("make clean")
|
129
|
+
popen_failing_fake("make 2>&1")
|
130
|
+
cguard = Guard::Cunit::Runner.new
|
131
|
+
setup_guard
|
132
|
+
cguard.run.should == false
|
133
|
+
end
|
134
|
+
|
135
|
+
it "should report failure on test failed" do
|
136
|
+
guardfile_has_unit_test_exe(:test_exe=>"jiji")
|
137
|
+
popen_successfull_fake("make clean")
|
138
|
+
popen_successfull_fake("make 2>&1")
|
139
|
+
fake_test_exe("jiji",:fail)
|
140
|
+
cguard = Guard::Cunit::Runner.new
|
141
|
+
setup_guard
|
142
|
+
cguard.run.should == false
|
143
|
+
end
|
144
|
+
|
145
|
+
end
|
146
|
+
|
147
|
+
|
148
|
+
context "Displaying notifications" do
|
149
|
+
|
150
|
+
it "should display failure if build fails" do
|
151
|
+
Guard::Notifier.stub(:notify)
|
152
|
+
guardfile_has_unit_test_exe()
|
153
|
+
Guard::Notifier.should_receive(:notify).with("Failed", :title => "Build Failed", :image => :failed, :priority => 2)
|
154
|
+
popen_successfull_fake("make clean")
|
155
|
+
popen_failing_fake("make 2>&1")
|
156
|
+
cguard = Guard::Cunit::Runner.new
|
157
|
+
setup_guard
|
158
|
+
cguard.run
|
159
|
+
end
|
160
|
+
|
161
|
+
it "should display failure if test fails" do
|
162
|
+
IO.stub(:popen)
|
163
|
+
Guard::Notifier.stub(:notify)
|
164
|
+
guardfile_has_unit_test_exe(:test_exe=>"jiji")
|
165
|
+
Guard::Notifier.should_receive(:notify).with("Failed", :title => "Test Failed", :image => :failed, :priority => 2, :message => anything() )
|
166
|
+
popen_successfull_fake("make clean")
|
167
|
+
popen_successfull_fake("make 2>&1")
|
168
|
+
fake_test_exe("jiji",:fail)
|
169
|
+
cguard = Guard::Cunit::Runner.new
|
170
|
+
setup_guard
|
171
|
+
cguard.run
|
172
|
+
end
|
173
|
+
|
174
|
+
it "should display pending if test is absent" do
|
175
|
+
Guard::Notifier.stub(:notify)
|
176
|
+
guardfile_has_unit_test_exe()
|
177
|
+
Guard::Notifier.should_receive(:notify).with("Pending", :title => "Test Not Defined", :image => :pending, :priority => 2)
|
178
|
+
popen_successfull_fake("make clean")
|
179
|
+
popen_successfull_fake("make 2>&1")
|
180
|
+
cguard = Guard::Cunit::Runner.new
|
181
|
+
setup_guard
|
182
|
+
cguard.run
|
183
|
+
end
|
184
|
+
|
185
|
+
it "should display success if build and test succeeded" do
|
186
|
+
Guard::Notifier.stub(:notify)
|
187
|
+
guardfile_has_unit_test_exe()
|
188
|
+
Guard::Notifier.should_receive(:notify).with("Success", :title => "Test Passed", :image => :passed, :priority => 2)
|
189
|
+
popen_successfull_fake("make clean")
|
190
|
+
popen_successfull_fake("make 2>&1")
|
191
|
+
fake_test_exe(nil,:pass)
|
192
|
+
cguard = Guard::Cunit::Runner.new
|
193
|
+
Guard.add_guard('cunit')
|
194
|
+
cguard.run
|
195
|
+
end
|
196
|
+
end
|
197
|
+
|
198
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'guard'
|
3
|
+
require 'guard/cunit'
|
4
|
+
require 'guard/cunit/runner'
|
5
|
+
require 'guard/cunit/cunit_parser'
|
6
|
+
require 'rspec'
|
7
|
+
|
8
|
+
# a class to set/cleanup environment for fake project
|
9
|
+
class TempPrjEnv
|
10
|
+
|
11
|
+
@test_tmp = "./tmp"
|
12
|
+
@test_prj_dir="./tmp/1test_prj"
|
13
|
+
|
14
|
+
# create a tmp subdir and within it fake project directory
|
15
|
+
def self.create_tmp_prj_dir
|
16
|
+
begin
|
17
|
+
Dir.mkdir(@test_tmp)
|
18
|
+
Dir.mkdir(@test_prj_dir)
|
19
|
+
rescue
|
20
|
+
end
|
21
|
+
@test_prj_dir
|
22
|
+
end
|
23
|
+
|
24
|
+
# cleanup the subdir
|
25
|
+
def self.cleanup_tmp_prj_dir
|
26
|
+
begin
|
27
|
+
FileUtils.rm_rf(@test_prj_dir)
|
28
|
+
FileUtils.rm_rf(@test_tmp)
|
29
|
+
rescue
|
30
|
+
puts "Could not remove dirs"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
# setup stub for system command with successful exit result
|
36
|
+
def popen_successfull_fake(fakename)
|
37
|
+
IO.stub(:popen).with(fakename)
|
38
|
+
IO.should_receive(:popen).with(fakename) { `(exit 0)`}
|
39
|
+
end
|
40
|
+
|
41
|
+
# setup stub for system command with failing exit result
|
42
|
+
def popen_failing_fake(fakename)
|
43
|
+
IO.stub(:popen).with(fakename)
|
44
|
+
IO.should_receive(:popen).with(fakename) { `(exit 1)`}
|
45
|
+
end
|
46
|
+
|
47
|
+
# fake the test executable runner, its existance and result
|
48
|
+
def fake_test_exe(exe_name,successful = :fail)
|
49
|
+
exe_name="#{File.basename(Dir.getwd)}_unit" unless exe_name != nil
|
50
|
+
File.new(exe_name,"w+")
|
51
|
+
if successful == :pass
|
52
|
+
popen_successfull_fake(exe_name)
|
53
|
+
else
|
54
|
+
popen_failing_fake(exe_name)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
# a generator for CUnit Guardfile
|
59
|
+
def guardfile_has_unit_test_exe(params={ :test_exe=>nil, :builder=>nil, :cleaner=>nil, :libdir=>nil})
|
60
|
+
File.open("Guardfile","w+",0644) do |file|
|
61
|
+
file.puts "guard \'cunit\' do"
|
62
|
+
|
63
|
+
file.puts " set_builder \"#{params[:builder]}\"" unless (params[:builder] == nil)
|
64
|
+
file.puts " set_cleaner \"#{params[:cleaner]}\"" unless (params[:cleaner] == nil)
|
65
|
+
file.puts " cunit_runner \"#{params[:test_exe]}\"" unless (params[:test_exe] == nil)
|
66
|
+
file.puts " libdir \"#{params[:libdir]}\"" unless (params[:libdir] == nil)
|
67
|
+
|
68
|
+
file.puts ' watch(%r{((.+)\.c$)|((.+)\.h$)|((M|m)akefile$)} ) '
|
69
|
+
file.puts 'end'
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|