Modified: incubator/buildr/trunk/lib/java/test.rb URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/java/test.rb?rev=605992&r1=605991&r2=605992&view=diff ============================================================================== --- incubator/buildr/trunk/lib/java/test.rb (original) +++ incubator/buildr/trunk/lib/java/test.rb Thu Dec 20 10:35:40 2007 @@ -568,12 +568,138 @@ end - class TestTask ; include JUnit ; include TestNG ; end + class TestTask + include JUnit + include TestNG + end end - class Project + # The integration tests task. Buildr has one such task (see Buildr#integration) that runs + # all tests marked with :integration=>true, and has a setup/teardown tasks separate from + # the unit tests. + class IntegrationTestsTask < Rake::Task + + def initialize(*args) #:nodoc: + super + @setup = task("#{name}:setup") + @teardown = task("#{name}:teardown") + enhance do + puts "Running integration tests..." if verbose + TestTask.run_local_tests true + end + end + + def execute() #:nodoc: + setup.invoke + begin + super + ensure + teardown.invoke + end + end + + # :call-seq: + # setup(*prereqs) => task + # setup(*prereqs) { |task| .. } => task + # + # Returns the setup task. The setup task is executed before running the integration tests. + def setup(*prereqs, &block) + @setup.enhance prereqs, &block + end + + # :call-seq: + # teardown(*prereqs) => task + # teardown(*prereqs) { |task| .. } => task + # + # Returns the teardown task. The teardown task is executed after running the integration tests. + def teardown(*prereqs, &block) + @teardown.enhance prereqs, &block + end + + end + + + # Methods added to Project to support compilation and running of test cases. + module Test + + include Extension + + first_time do + desc "Run all test cases" + task("test") { TestTask.run_local_tests false } + + # This rule takes a suffix and runs that test case in the current project. For example; + # buildr test:MyTest + # will run the test case class com.example.MyTest, if found in the current project. + # + # If you want to run multiple test cases, separate tham with a comma. You can also use glob + # (* and ?) patterns to match multiple tests, e.g. com.example.* to run all test cases in + # a given package. If you don't specify a glob pattern, asterisks are added for you. + rule /^test:.*$/ do |task| + TestTask.only_run task.name.scan(/test:(.*)/)[0][0].split(",") + task("test").invoke + end + + task "build" do |task| + # Make sure this happens as the last action on the build, so all other enhancements + # are made to run before starting the test cases. + task.enhance do + task("test").invoke unless Buildr.options.test == false + end + end + + IntegrationTestsTask.define_task("integration") + + # Similar to test:[pattern] but for integration tests. + rule /^integration:.*$/ do |task| + unless task.name.split(':')[1] =~ /^(setup|teardown)$/ + TestTask.only_run task.name.scan(/integration:(.*)/)[0][0].split(",") + task("integration").invoke + end + end + + # Anything that comes after local packaging (install, deploy) executes the integration tests, + # which do not conflict with integration invoking the project's own packaging (package=> + # integration=>foo:package is not circular, just confusing to debug.) + task "package" do |task| + task("integration").invoke if Buildr.options.test && Rake.application.original_dir == Dir.pwd + end + end + + before_define do |project| + # Define a recursive test task, and pass it a reference to the project so it can discover all other tasks. + Java::TestTask.define_task("test") + project.test.instance_eval { instance_variable_set :@project, project } + #project.recursive_task("test") + # Similar to the regular resources task but using different paths. + resources = Java::ResourcesTask.define_task("test:resources") + project.path_to("src/test/resources").tap { |dir| resources.from dir if File.exist?(dir) } + # Similar to the regular compile task but using different paths. + compile = Java::CompileTask.define_task("test:compile"=>[project.compile, task("test:prepare"), project.test.resources]) + project.path_to("src/test/java").tap { |dir| compile.from dir if File.exist?(dir) } + compile.into project.path_to(:target, "test-classes") + resources.filter.into compile.target + project.test.enhance [compile] + # Define the JUnit task here, otherwise we get a normal task. + Java::JUnitTask.define_task("test:junit") + # Define these tasks once, otherwise we may get a namespace error. + project.test.setup ; project.test.teardown + end + + after_define do |project| + # Copy the regular compile classpath over, and also include the generated classes, both of which + # can be used in the test cases. And don't forget the classpath required by the test framework (e.g. JUnit). + project.test.with project.compile.classpath, project.compile.target, project.test.requires + project.clean do + verbose(false) do + rm_rf project.test.compile.target.to_s + rm_rf project.test.report_to.to_s + end + end + end + # :call-seq: # test(*prereqs) => TestTask @@ -600,39 +726,36 @@ task("test").enhance prereqs, &block end - end - + # :call-seq: + # integration() { |task| .... } + # integration() => IntegrationTestTask + # + # Use this method to return the integration tests task, or enhance it with a block to execute. + # + # There is one integration tests task you can execute directly, or as a result of running the package + # task (or tasks that depend on it, like install and deploy). It contains all the tests marked with + # :integration=>true, all other tests are considered unit tests and run by the test task before packaging. + # So essentially: build=>test=>packaging=>integration=>install/deploy. + # + # You add new test cases from projects that define integration tests using the regular test task, + # but with the following addition: + # test.using :integration + # + # Use this method to enhance the setup and teardown tasks that are executed before (and after) all + # integration tests are run, for example, to start a Web server or create a database. + def integration(*deps, &block) + Rake::Task["rake:integration"].enhance deps, &block + end - Project.on_define do |project| - # Define a recursive test task, and pass it a reference to the project so it can discover all other tasks. - Java::TestTask.define_task("test") - project.test.instance_eval { instance_variable_set :@project, project } - #project.recursive_task("test") - # Similar to the regular resources task but using different paths. - resources = Java::ResourcesTask.define_task("test:resources") - project.path_to("src/test/resources").tap { |dir| resources.from dir if File.exist?(dir) } - # Similar to the regular compile task but using different paths. - compile = Java::CompileTask.define_task("test:compile"=>[project.compile, task("test:prepare"), project.test.resources]) - project.path_to("src/test/java").tap { |dir| compile.from dir if File.exist?(dir) } - compile.into project.path_to(:target, "test-classes") - resources.filter.into compile.target - project.test.enhance [compile] - # Define the JUnit task here, otherwise we get a normal task. - Java::JUnitTask.define_task("test:junit") - # Define these tasks once, otherwise we may get a namespace error. - project.test.setup ; project.test.teardown + end - project.enhance do |project| - # Copy the regular compile classpath over, and also include the generated classes, both of which - # can be used in the test cases. And don't forget the classpath required by the test framework (e.g. JUnit). - project.test.with project.compile.classpath, project.compile.target, project.test.requires - project.clean do - verbose(false) do - rm_rf project.test.compile.target.to_s - rm_rf project.test.report_to.to_s - end - end - end + # :call-seq: + # integration() { |task| .... } + # integration() => IntegrationTestTask + # + # Use this method to return the integration tests task. + def integration(*deps, &block) + Rake::Task["rake:integration"].enhance deps, &block end @@ -680,106 +803,6 @@ end - desc "Run all test cases" - task("test") { TestTask.run_local_tests false } - - # This rule takes a suffix and runs that test case in the current project. For example; - # buildr test:MyTest - # will run the test case class com.example.MyTest, if found in the current project. - # - # If you want to run multiple test cases, separate tham with a comma. You can also use glob - # (* and ?) patterns to match multiple tests, e.g. com.example.* to run all test cases in - # a given package. If you don't specify a glob pattern, asterisks are added for you. - rule /^test:.*$/ do |task| - TestTask.only_run task.name.scan(/test:(.*)/)[0][0].split(",") - task("test").invoke - end - - task "build" do |task| - # Make sure this happens as the last action on the build, so all other enhancements - # are made to run before starting the test cases. - task.enhance do - task("test").invoke unless Buildr.options.test == false - end - end - - - # The integration tests task. Buildr has one such task (see Buildr#integration) that runs - # all tests marked with :integration=>true, and has a setup/teardown tasks separate from - # the unit tests. - class IntegrationTestsTask < Rake::Task - - def initialize(*args) #:nodoc: - super - task "#{name}-setup" - task "#{name}-teardown" - enhance { puts "Running integration tests..." if verbose } - end - - def execute() #:nodoc: - setup.invoke - begin - super - ensure - teardown.invoke - end - end - - # :call-seq: - # setup(*prereqs) => task - # setup(*prereqs) { |task| .. } => task - # - # Returns the setup task. The setup task is executed before running the integration tests. - def setup(*prereqs, &block) - Rake::Task["rake:integration-setup"].enhance prereqs, &block - end - - # :call-seq: - # teardown(*prereqs) => task - # teardown(*prereqs) { |task| .. } => task - # - # Returns the teardown task. The teardown task is executed after running the integration tests. - def teardown(*prereqs, &block) - Rake::Task["rake:integration-teardown"].enhance prereqs, &block - end - - end - - # :call-seq: - # integration() { |task| .... } - # integration() => IntegrationTestTask - # - # Use this method to return the integration tests task, or enhance it with a block to execute. - # - # There is one integration tests task you can execute directly, or as a result of running the package - # task (or tasks that depend on it, like install and deploy). It contains all the tests marked with - # :integration=>true, all other tests are considered unit tests and run by the test task before packaging. - # So essentially: build=>test=>packaging=>integration=>install/deploy. - # - # You add new test cases from projects that define integration tests using the regular test task, - # but with the following addition: - # test.using :integration - # - # Use this method to enhance the setup and teardown tasks that are executed before (and after) all - # integration tests are run, for example, to start a Web server or create a database. - def integration(*deps, &block) - Rake::Task["rake:integration"].enhance deps, &block - end - - IntegrationTestsTask.define_task("integration") { TestTask.run_local_tests true } - - # Similar to test:[pattern] but for integration tests. - rule /^integration:.*$/ do |task| - TestTask.only_run task.name.scan(/integration:(.*)/)[0][0].split(",") - task("integration").invoke - end - - # Anything that comes after local packaging (install, deploy) executes the integration tests, - # which do not conflict with integration invoking the project's own packaging (package=> - # integration=>foo:package is not circular, just confusing to debug.) - task "package" do |task| - integration.invoke if Buildr.options.test && Rake.application.original_dir == Dir.pwd - end task("help") do
Added: incubator/buildr/trunk/lib/tasks.rb URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/tasks.rb?rev=605992&view=auto ============================================================================== --- incubator/buildr/trunk/lib/tasks.rb (added) +++ incubator/buildr/trunk/lib/tasks.rb Thu Dec 20 10:35:40 2007 @@ -0,0 +1,3 @@ +require 'tasks/concat.rb' +require 'tasks/zip.rb' +require 'tasks/tar.rb' Modified: incubator/buildr/trunk/test/checks.rb URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/test/checks.rb?rev=605992&r1=605991&r2=605992&view=diff ============================================================================== --- incubator/buildr/trunk/test/checks.rb (original) +++ incubator/buildr/trunk/test/checks.rb Thu Dec 20 10:35:40 2007 @@ -1,23 +1,7 @@ require File.join(File.dirname(__FILE__), 'sandbox') -module BuildChecks - def should_pass() - lambda { check }.should_not raise_error - end - - def should_fail() - lambda { check }.should raise_error(RuntimeError, /Checks failed/) - end - - def check() - project("foo").task("package").invoke - end -end - - describe Project, " check task" do - include BuildChecks it "should execute last thing from package task" do task "action" @@ -25,7 +9,7 @@ package :jar task("package").enhance { task("action").invoke } end - lambda { check }.should run_tasks(["foo:package", "action", "foo:check"]) + lambda { project("foo").task("package").invoke }.should run_tasks(["foo:package", "action", "foo:check"]) end it "should execute all project's expectations" do @@ -33,12 +17,12 @@ define "foo", :version=>"1.0" do check { task("expectation").invoke } end - lambda { check }.should run_task("expectation") + lambda { project("foo").task("package").invoke }.should run_task("expectation") end it "should succeed if there are no expectations" do define "foo", :version=>"1.0" - should_pass + lambda { project("foo").task("package").invoke }.should_not raise_error end it "should succeed if all expectations passed" do @@ -46,7 +30,7 @@ check { true } check { false } end - should_pass + lambda { project("foo").task("package").invoke }.should_not raise_error end it "should fail if any expectation failed" do @@ -55,13 +39,12 @@ check { fail "sorry" } check end - should_fail + lambda { project("foo").task("package").invoke }.should raise_error(RuntimeError, /Checks failed/) end end describe Project, "#check" do - include BuildChecks it "should add expectation" do define "foo" do @@ -79,7 +62,7 @@ description.should eql(subject.to_s) end end - should_pass + lambda { project("foo").task("package").invoke }.should_not raise_error end it "should treat single string argument as description, expectation against project" do @@ -90,7 +73,7 @@ description.should eql("#{subject} should be project") end end - should_pass + lambda { project("foo").task("package").invoke }.should_not raise_error end it "should treat single object argument as subject" do @@ -101,7 +84,7 @@ description.should eql(subject.to_s) end end - should_pass + lambda { project("foo").task("package").invoke }.should_not raise_error end it "should treat first object as subject, second object as description" do @@ -112,20 +95,19 @@ description.should eql("#{subject} should exist") end end - should_pass + lambda { project("foo").task("package").invoke }.should_not raise_error end it "should work without block" do define "foo" do check "implement later" end - should_pass + lambda { project("foo").task("package").invoke }.should_not raise_error end end -describe BuildChecks::Expectation, " matchers" do - include BuildChecks +describe Buildr::Checks::Expectation, " matchers" do it "should include Buildr matchers exist and contain" do define "foo" do @@ -134,7 +116,7 @@ self.should respond_to(:contain) end end - should_pass + lambda { project("foo").task("package").invoke }.should_not raise_error end it "should include RSpec matchers like be and eql" do @@ -144,7 +126,7 @@ self.should respond_to(:eql) end end - should_pass + lambda { project("foo").task("package").invoke }.should_not raise_error end it "should include RSpec predicates like be_nil and be_empty" do @@ -154,27 +136,26 @@ [].should be_empty end end - should_pass + lambda { project("foo").task("package").invoke }.should_not raise_error end end -describe BuildChecks::Expectation, " exist" do - include BuildChecks +describe Buildr::Checks::Expectation, " exist" do it "should pass if file exists" do define "foo" do build file("test") { |task| write task.name } check(file("test")) { it.should exist } end - should_pass + lambda { project("foo").task("package").invoke }.should_not raise_error end it "should fail if file does not exist" do define "foo" do check(file("test")) { it.should exist } end - should_fail + lambda { project("foo").task("package").invoke }.should raise_error(RuntimeError, /Checks failed/) end it "should not attempt to invoke task" do @@ -182,7 +163,7 @@ file("test") { |task| write task.name } check(file("test")) { it.should exist } end - should_fail + lambda { project("foo").task("package").invoke }.should raise_error(RuntimeError, /Checks failed/) end it "should pass if ZIP path exists" do @@ -191,7 +172,7 @@ package(:jar).include("resources") check(package(:jar).path("resources")) { it.should exist } end - should_pass + lambda { project("foo").task("package").invoke }.should_not raise_error end it "should fail if ZIP path does not exist" do @@ -200,7 +181,7 @@ package(:jar).include("resources") check(package(:jar)) { it.path("not-resources").should exist } end - should_fail + lambda { project("foo").task("package").invoke }.should raise_error(RuntimeError, /Checks failed/) end it "should pass if ZIP entry exists" do @@ -210,7 +191,7 @@ check(package(:jar).entry("resources/test")) { it.should exist } check(package(:jar).path("resources").entry("test")) { it.should exist } end - should_pass + lambda { project("foo").task("package").invoke }.should_not raise_error end it "should fail if ZIP path does not exist" do @@ -219,20 +200,19 @@ package(:jar).include("resources") check(package(:jar).entry("resources/test")) { it.should exist } end - should_fail + lambda { project("foo").task("package").invoke }.should raise_error(RuntimeError, /Checks failed/) end end -describe BuildChecks::Expectation, " exist" do - include BuildChecks +describe Buildr::Checks::Expectation, " exist" do it "should pass if file has no content" do define "foo" do build file("test") { write "test" } check(file("test")) { it.should be_empty } end - should_pass + lambda { project("foo").task("package").invoke }.should_not raise_error end it "should fail if file has content" do @@ -240,14 +220,14 @@ build file("test") { write "test", "something" } check(file("test")) { it.should be_empty } end - should_fail + lambda { project("foo").task("package").invoke }.should raise_error(RuntimeError, /Checks failed/) end it "should fail if file does not exist" do define "foo" do check(file("test")) { it.should be_empty } end - should_fail + lambda { project("foo").task("package").invoke }.should raise_error(RuntimeError, /Checks failed/) end it "should pass if directory is empty" do @@ -255,7 +235,7 @@ build file("test") { mkpath "test" } check(file("test")) { it.should be_empty } end - should_pass + lambda { project("foo").task("package").invoke }.should_not raise_error end it "should fail if directory has any files" do @@ -263,7 +243,7 @@ build file("test") { write "test/file" } check(file("test")) { it.should be_empty } end - should_fail + lambda { project("foo").task("package").invoke }.should raise_error(RuntimeError, /Checks failed/) end it "should pass if ZIP path is empty" do @@ -272,7 +252,7 @@ package(:jar).include("resources") check(package(:jar).path("resources")) { it.should be_empty } end - should_pass + lambda { project("foo").task("package").invoke }.should_not raise_error end it "should fail if ZIP path has any entries" do @@ -281,7 +261,7 @@ package(:jar).include("resources") check(package(:jar).path("resources")) { it.should be_empty } end - should_fail + lambda { project("foo").task("package").invoke }.should raise_error(RuntimeError, /Checks failed/) end it "should pass if ZIP entry has no content" do @@ -291,7 +271,7 @@ check(package(:jar).entry("resources/test")) { it.should be_empty } check(package(:jar).path("resources").entry("test")) { it.should be_empty } end - should_pass + lambda { project("foo").task("package").invoke }.should_not raise_error end it "should fail if ZIP entry has content" do @@ -300,7 +280,7 @@ package(:jar).include("resources") check(package(:jar).entry("resources/test")) { it.should be_empty } end - should_fail + lambda { project("foo").task("package").invoke }.should raise_error(RuntimeError, /Checks failed/) end it "should fail if ZIP entry does not exist" do @@ -309,20 +289,19 @@ package(:jar).include("resources") check(package(:jar).entry("resources/test")) { it.should be_empty } end - should_fail + lambda { project("foo").task("package").invoke }.should raise_error(RuntimeError, /Checks failed/) end end -describe BuildChecks::Expectation, " contain(file)" do - include BuildChecks +describe Buildr::Checks::Expectation, " contain(file)" do it "should pass if file content matches string" do define "foo" do build file("test") { write "test", "something" } check(file("test")) { it.should contain("thing") } end - should_pass + lambda { project("foo").task("package").invoke }.should_not raise_error end it "should pass if file content matches pattern" do @@ -330,7 +309,7 @@ build file("test") { write "test", "something\nor\nanother" } check(file("test")) { it.should contain(/or/) } end - should_pass + lambda { project("foo").task("package").invoke }.should_not raise_error end it "should pass if file content matches all arguments" do @@ -338,7 +317,7 @@ build file("test") { write "test", "something\nor\nanother" } check(file("test")) { it.should contain(/or/, /other/) } end - should_pass + lambda { project("foo").task("package").invoke }.should_not raise_error end it "should fail unless file content matchs all arguments" do @@ -346,7 +325,7 @@ build file("test") { write "test", "something" } check(file("test")) { it.should contain(/some/, /other/) } end - should_fail + lambda { project("foo").task("package").invoke }.should raise_error(RuntimeError, /Checks failed/) end it "should fail if file content does not match" do @@ -354,27 +333,26 @@ build file("test") { write "test", "something" } check(file("test")) { it.should contain(/other/) } end - should_fail + lambda { project("foo").task("package").invoke }.should raise_error(RuntimeError, /Checks failed/) end it "should fail if file does not exist" do define "foo" do check(file("test")) { it.should contain(/anything/) } end - should_fail + lambda { project("foo").task("package").invoke }.should raise_error(RuntimeError, /Checks failed/) end end -describe BuildChecks::Expectation, " contain(directory)" do - include BuildChecks +describe Buildr::Checks::Expectation, " contain(directory)" do it "should pass if directory contains file" do write "resources/test" define "foo" do check(file("resources")) { it.should contain("test") } end - should_pass + lambda { project("foo").task("package").invoke }.should_not raise_error end it "should pass if directory contains glob pattern" do @@ -382,7 +360,7 @@ define "foo" do check(file("resources")) { it.should contain("**/t*st") } end - should_pass + lambda { project("foo").task("package").invoke }.should_not raise_error end it "should pass if directory contains all arguments" do @@ -390,7 +368,7 @@ define "foo" do check(file("resources")) { it.should contain("**/test", "**/*") } end - should_pass + lambda { project("foo").task("package").invoke }.should_not raise_error end it "should fail unless directory contains all arguments" do @@ -398,7 +376,7 @@ define "foo" do check(file("resources")) { it.should contain("test", "or-not") } end - should_fail + lambda { project("foo").task("package").invoke }.should raise_error(RuntimeError, /Checks failed/) end it "should fail if directory is empty" do @@ -406,20 +384,19 @@ define "foo" do check(file("resources")) { it.should contain("test") } end - should_fail + lambda { project("foo").task("package").invoke }.should raise_error(RuntimeError, /Checks failed/) end it "should fail if directory does not exist" do define "foo" do check(file("resources")) { it.should contain } end - should_fail + lambda { project("foo").task("package").invoke }.should raise_error(RuntimeError, /Checks failed/) end end -describe BuildChecks::Expectation, " contain(zip.entry)" do - include BuildChecks +describe Buildr::Checks::Expectation, " contain(zip.entry)" do it "should pass if ZIP entry content matches string" do write "resources/test", "something" @@ -428,7 +405,7 @@ check(package(:jar).entry("resources/test")) { it.should contain("thing") } #check(package(:jar)) { it.entry("resources/test").should contain("thing") } end - should_pass + lambda { project("foo").task("package").invoke }.should_not raise_error end it "should pass if ZIP entry content matches pattern" do @@ -438,7 +415,7 @@ check(package(:jar).entry("resources/test")) { it.should contain(/or/) } #check(package(:jar)) { it.entry("resources/test").should contain(/or/) } end - should_pass + lambda { project("foo").task("package").invoke }.should_not raise_error end it "should pass if ZIP entry content matches all arguments" do @@ -448,7 +425,7 @@ check(package(:jar).entry("resources/test")) { it.should contain(/or/, /other/) } #check(package(:jar)) { it.entry("resources/test").should contain(/or/, /other/) } end - should_pass + lambda { project("foo").task("package").invoke }.should_not raise_error end it "should fail unless ZIP path contains all arguments" do @@ -458,7 +435,7 @@ check(package(:jar).entry("resources/test")) { it.should contain(/some/, /other/) } #check(package(:jar)) { it.entry("resources/test").should contain(/some/, /other/) } end - should_fail + lambda { project("foo").task("package").invoke }.should raise_error(RuntimeError, /Checks failed/) end it "should fail if ZIP entry content does not match" do @@ -468,7 +445,7 @@ check(package(:jar).entry("resources/test")) { it.should contain(/other/) } #check(package(:jar)) { it.entry("resources/test").should contain(/other/) } end - should_fail + lambda { project("foo").task("package").invoke }.should raise_error(RuntimeError, /Checks failed/) end it "should fail if ZIP entry does not exist" do @@ -478,13 +455,12 @@ check(package(:jar).entry("resources/test")) { it.should contain(/anything/) } #check(package(:jar)) { it.entry("resources/test").should contain(/anything/) } end - should_fail + lambda { project("foo").task("package").invoke }.should raise_error(RuntimeError, /Checks failed/) end end -describe BuildChecks::Expectation, " contain(zip.path)" do - include BuildChecks +describe Buildr::Checks::Expectation, " contain(zip.path)" do it "should pass if ZIP path contains file" do write "resources/test" @@ -492,7 +468,7 @@ package(:jar).include("resources") check(package(:jar).path("resources")) { it.should contain("test") } end - should_pass + lambda { project("foo").task("package").invoke }.should_not raise_error end it "should handle deep nesting" do @@ -503,7 +479,7 @@ check(package(:jar).path("resources")) { it.should contain("test/test2.efx") } check(package(:jar).path("resources/test")) { it.should contain("test2.efx") } end - should_pass + lambda { project("foo").task("package").invoke }.should_not raise_error end @@ -513,7 +489,7 @@ package(:jar).include("resources") check(package(:jar).path("resources")) { it.should contain("**/t*st") } end - should_pass + lambda { project("foo").task("package").invoke }.should_not raise_error end it "should pass if ZIP path contains all arguments" do @@ -522,7 +498,7 @@ package(:jar).include("resources") check(package(:jar).path("resources")) { it.should contain("**/test", "**/*") } end - should_pass + lambda { project("foo").task("package").invoke }.should_not raise_error end it "should fail unless ZIP path contains all arguments" do @@ -531,7 +507,7 @@ package(:jar).include("resources") check(package(:jar).path("resources")) { it.should contain("test", "or-not") } end - should_fail + lambda { project("foo").task("package").invoke }.should raise_error(RuntimeError, /Checks failed/) end it "should fail if ZIP path is empty" do @@ -540,6 +516,6 @@ package(:jar).include("resources") check(package(:jar).path("resources")) { it.should contain("test") } end - should_fail + lambda { project("foo").task("package").invoke }.should raise_error(RuntimeError, /Checks failed/) end end Modified: incubator/buildr/trunk/test/packaging.rb URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/test/packaging.rb?rev=605992&r1=605991&r2=605992&view=diff ============================================================================== --- incubator/buildr/trunk/test/packaging.rb (original) +++ incubator/buildr/trunk/test/packaging.rb Thu Dec 20 10:35:40 2007 @@ -86,7 +86,7 @@ it "should not include project version unless specified" do define "foo" - project("foo").manifest.has_key?("Implementation-Version").should be_false + project("foo").manifest["Implementation-Version"].should be_nil end it "should inherit from parent project" do Modified: incubator/buildr/trunk/test/sandbox.rb URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/test/sandbox.rb?rev=605992&r1=605991&r2=605992&view=diff ============================================================================== --- incubator/buildr/trunk/test/sandbox.rb (original) +++ incubator/buildr/trunk/test/sandbox.rb Thu Dec 20 10:35:40 2007 @@ -1,10 +1,10 @@ # This file is required twice when running spec test/*. unless defined?(Buildr) + require 'rubygems' #require "rake" $LOAD_PATH.unshift File.expand_path("#{File.dirname(__FILE__)}/../lib") - require "buildr" - #require File.join(File.dirname(__FILE__), "../lib", "buildr.rb") + require File.join(File.dirname(__FILE__), "../lib", "buildr.rb") # The local repository we use for testing is void of any artifacts, which will break given @@ -20,7 +20,7 @@ module Matchers - include BuildChecks::Matchers + include Checks::Matchers module ::Kernel #:nodoc: def warn(message) @@ -267,7 +267,7 @@ Rake.application.instance_eval { @original_dir = Dir.pwd } # Later on we'll want to lose all the on_define created during the test. - @sandbox[:on_define] = Project.class_eval { @on_define.dup } + @sandbox[:on_define] = Project.class_eval { (@on_define || []).dup } # Create a local repository we can play with. However, our local repository will be void # of some essential artifacts (e.g. JUnit artifacts required by build task), so we create @@ -320,7 +320,9 @@ end # Allow using matchers within the project definition. - class Buildr::Project ; include ::Spec::Matchers, ::Buildr::Matchers ; end + class Buildr::Project + include ::Spec::Matchers, ::Buildr::Matchers + end Spec::Runner.configure do |config| # Make all Buildr methods accessible from test cases, and add various helper methods. Added: incubator/buildr/trunk/test/spec.opts URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/test/spec.opts?rev=605992&view=auto ============================================================================== --- incubator/buildr/trunk/test/spec.opts (added) +++ incubator/buildr/trunk/test/spec.opts Thu Dec 20 10:35:40 2007 @@ -0,0 +1,6 @@ +--colour +--format +specdoc +--loadby +mtime +--backtrace Modified: incubator/buildr/trunk/test/test.rb URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/test/test.rb?rev=605992&r1=605991&r2=605992&view=diff ============================================================================== --- incubator/buildr/trunk/test/test.rb (original) +++ incubator/buildr/trunk/test/test.rb Thu Dec 20 10:35:40 2007 @@ -769,210 +769,210 @@ end -describe Buildr, "integration" do - it "should return the same task from all contexts" do - task = integration - define "foo" do +describe Buildr, 'integration' do + it 'should return the same task from all contexts' do + task = task('integration') + define 'foo' do integration.should be(task) - define "bar" do + define 'bar' do integration.should be(task) end end integration.should be(task) end - it "should respond to :setup and return setup task" do + it 'should respond to :setup and return setup task' do setup = integration.setup - define("foo") { integration.setup.should be(setup) } + define('foo') { integration.setup.should be(setup) } end - it "should respond to :setup and add prerequisites to integration:setup" do - define("foo") { integration.setup "prereq" } - integration.setup.prerequisites.should include("prereq") + it 'should respond to :setup and add prerequisites to integration:setup' do + define('foo') { integration.setup 'prereq' } + integration.setup.prerequisites.should include('prereq') end - it "should respond to :setup and add action for integration:setup" do - action = task("action") - define("foo") { integration.setup { action.invoke } } + it 'should respond to :setup and add action for integration:setup' do + action = task('action') + define('foo') { integration.setup { action.invoke } } lambda { integration.setup.invoke }.should run_tasks(action) end - it "should respond to :teardown and return teardown task" do + it 'should respond to :teardown and return teardown task' do teardown = integration.teardown - define("foo") { integration.teardown.should be(teardown) } + define('foo') { integration.teardown.should be(teardown) } end - it "should respond to :teardown and add prerequisites to integration:teardown" do - define("foo") { integration.teardown "prereq" } - integration.teardown.prerequisites.should include("prereq") + it 'should respond to :teardown and add prerequisites to integration:teardown' do + define('foo') { integration.teardown 'prereq' } + integration.teardown.prerequisites.should include('prereq') end - it "should respond to :teardown and add action for integration:teardown" do - action = task("action") - define("foo") { integration.teardown { action.invoke } } + it 'should respond to :teardown and add action for integration:teardown' do + action = task('action') + define('foo') { integration.teardown { action.invoke } } lambda { integration.teardown.invoke }.should run_tasks(action) end end -describe Rake::Task, "integration" do - it "should be a local task" do - define("foo") { test.using :integration } - define("bar", :base_dir=>"other") { test.using :integration } - lambda { task("integration").invoke }.should run_task("foo:test").but_not("bar:test") +describe Rake::Task, 'integration' do + it 'should be a local task' do + define('foo') { test.using :integration } + define('bar', :base_dir=>'other') { test.using :integration } + lambda { task('integration').invoke }.should run_task('foo:test').but_not('bar:test') end - it "should be a recursive task" do - define "foo" do + it 'should be a recursive task' do + define 'foo' do test.using :integration - define("bar") { test.using :integration } + define('bar') { test.using :integration } end - lambda { task("integration").invoke }.should run_tasks("foo:test", "foo:bar:test") + lambda { task('integration').invoke }.should run_tasks('foo:test', 'foo:bar:test') end - it "should find nested integration tests" do - define "foo" do - define("bar") { test.using :integration } + it 'should find nested integration tests' do + define 'foo' do + define('bar') { test.using :integration } end - lambda { task("integration").invoke }.should run_tasks("foo:bar:test").but_not("foo:test") + lambda { task('integration').invoke }.should run_tasks('foo:bar:test').but_not('foo:test') end - it "should ignore nested regular tasks" do - define "foo" do + it 'should ignore nested regular tasks' do + define 'foo' do test.using :integration - define("bar") { test.using :integration=>false } + define('bar') { test.using :integration=>false } end - lambda { task("integration").invoke }.should run_tasks("foo:test").but_not("foo:bar:test") + lambda { task('integration').invoke }.should run_tasks('foo:test').but_not('foo:bar:test') end - it "should agree not to run the same tasks as test" do - define "foo" do - define "bar" do + it 'should agree not to run the same tasks as test' do + define 'foo' do + define 'bar' do test.using :integration - define("baz") { test.using :integration=>false } + define('baz') { test.using :integration=>false } end end - lambda { task("test").invoke }.should run_tasks("foo:test", "foo:bar:baz:test").but_not("foo:bar:test") - lambda { task("integration").invoke }.should run_tasks("foo:bar:test").but_not("foo:test", "foo:bar:baz:test") + lambda { task('test').invoke }.should run_tasks('foo:test', 'foo:bar:baz:test').but_not('foo:bar:test') + lambda { task('integration').invoke }.should run_tasks('foo:bar:test').but_not('foo:test', 'foo:bar:baz:test') end - it "should run setup task before any project integration tests" do - define("foo") { test.using :integration } - define("bar") { test.using :integration } - lambda { task("integration").invoke }.should run_tasks([integration.setup, "bar:test", "foo:test"]) + it 'should run setup task before any project integration tests' do + define('foo') { test.using :integration } + define('bar') { test.using :integration } + lambda { task('integration').invoke }.should run_tasks([integration.setup, 'bar:test', 'foo:test']) end - it "should run teardown task after all project integrations tests" do - define("foo") { test.using :integration } - define("bar") { test.using :integration } - lambda { task("integration").invoke }.should run_tasks(["bar:test", "foo:test", integration.teardown]) + it 'should run teardown task after all project integrations tests' do + define('foo') { test.using :integration } + define('bar') { test.using :integration } + lambda { task('integration').invoke }.should run_tasks(['bar:test', 'foo:test', integration.teardown]) end - it "should run test cases marked for integration" do - write "src/test/java/FailingTest.java", - "public class FailingTest extends junit.framework.TestCase { public void testNothing() { assertTrue(false); } }" - define("foo") { test.using :integration } - lambda { task("test").invoke }.should_not raise_error - lambda { task("integration").invoke }.should raise_error(RuntimeError, /tests failed/i) + it 'should run test cases marked for integration' do + write 'src/test/java/FailingTest.java', + 'public class FailingTest extends junit.framework.TestCase { public void testNothing() { assertTrue(false); } }' + define('foo') { test.using :integration } + lambda { task('test').invoke }.should_not raise_error + lambda { task('integration').invoke }.should raise_error(RuntimeError, /tests failed/i) end - it "should run setup and teardown tasks marked for integration" do - define("foo") { test.using :integration } - lambda { task("test").invoke }.should run_tasks().but_not("foo:test:setup", "foo:test:teardown") - lambda { task("integration").invoke }.should run_tasks("foo:test:setup", "foo:test:teardown") + it 'should run setup and teardown tasks marked for integration' do + define('foo') { test.using :integration } + lambda { task('test').invoke }.should run_tasks().but_not('foo:test:setup', 'foo:test:teardown') + lambda { task('integration').invoke }.should run_tasks('foo:test:setup', 'foo:test:teardown') end - it "should run test actions marked for integration" do - task "action" - define "foo" do + it 'should run test actions marked for integration' do + task 'action' + define 'foo' do test.using :integration - test { task("action").invoke } + test { task('action').invoke } end - lambda { task("test").invoke }.should run_tasks().but_not("action") - lambda { task("integration").invoke }.should run_task("action") + lambda { task('test').invoke }.should run_tasks().but_not('action') + lambda { task('integration').invoke }.should run_task('action') end - it "should not fail if test=all" do - write "src/test/java/FailingTest.java", - "public class FailingTest extends junit.framework.TestCase { public void testNothing() { assertTrue(false); } }" - define("foo") { test.using :integration } + it 'should not fail if test=all' do + write 'src/test/java/FailingTest.java', + 'public class FailingTest extends junit.framework.TestCase { public void testNothing() { assertTrue(false); } }' + define('foo') { test.using :integration } options.test = :all - lambda { task("integration").invoke }.should_not raise_error + lambda { task('integration').invoke }.should_not raise_error end - it "should execute by local package task" do - define "foo", :version=>"1.0" do + it 'should execute by local package task' do + define 'foo', :version=>'1.0' do test.using :integration package :jar end - lambda { task("package").invoke }.should run_tasks(["foo:package", "foo:test"]) + lambda { task('package').invoke }.should run_tasks(['foo:package', 'foo:test']) end - it "should execute by local package task along with unit tests" do - define "foo", :version=>"1.0" do + it 'should execute by local package task along with unit tests' do + define 'foo', :version=>'1.0' do test.using :integration package :jar - define("bar") { test.using :integration=>false } + define('bar') { test.using :integration=>false } end - lambda { task("package").invoke }.should run_tasks(["foo:package", "foo:test"], - ["foo:bar:build", "foo:bar:test", "foo:bar:package"]) + lambda { task('package').invoke }.should run_tasks(['foo:package', 'foo:test'], + ['foo:bar:build', 'foo:bar:test', 'foo:bar:package']) end - it "should not execute by local package task if test=no" do - define "foo", :version=>"1.0" do + it 'should not execute by local package task if test=no' do + define 'foo', :version=>'1.0' do test.using :integration package :jar end options.test = false - lambda { task("package").invoke }.should run_task("foo:package").but_not("foo:test") + lambda { task('package').invoke }.should run_task('foo:package').but_not('foo:test') end end -describe "integration rule" do +describe 'integration rule' do before do - define "foo" do + define 'foo' do test.using :integration - define "bar" + define 'bar' end end - it "should execute integration tests on local project" do - lambda { task("integration:something").invoke }.should run_task("foo:test") + it 'should execute integration tests on local project' do + lambda { task('integration:something').invoke }.should run_task('foo:test') end - it "should reset tasks to specific pattern" do - task("integration:something").invoke - ["foo", "foo:bar"].map { |name| project(name) }.each do |project| - project.test.include?("something").should be_true - project.test.include?("nothing").should be_false - project.test.include?("SomeTest").should be_false + it 'should reset tasks to specific pattern' do + task('integration:something').invoke + ['foo', 'foo:bar'].map { |name| project(name) }.each do |project| + project.test.include?('something').should be_true + project.test.include?('nothing').should be_false + project.test.include?('SomeTest').should be_false end end - it "should apply *name* pattern" do - task("integration:something").invoke - project("foo").test.include?("prefix-something-suffix").should be_true - project("foo").test.include?("prefix-nothing-suffix").should be_false + it 'should apply *name* pattern' do + task('integration:something').invoke + project('foo').test.include?('prefix-something-suffix').should be_true + project('foo').test.include?('prefix-nothing-suffix').should be_false end - it "should not apply *name* pattern if asterisks used" do - task("integration:*something").invoke - project("foo").test.include?("prefix-something").should be_true - project("foo").test.include?("prefix-something-suffix").should be_false + it 'should not apply *name* pattern if asterisks used' do + task('integration:*something').invoke + project('foo').test.include?('prefix-something').should be_true + project('foo').test.include?('prefix-something-suffix').should be_false end - it "should accept multiple tasks separated by commas" do - task("integration:foo,bar").invoke - project("foo").test.include?("foo").should be_true - project("foo").test.include?("bar").should be_true - project("foo").test.include?("baz").should be_false + it 'should accept multiple tasks separated by commas' do + task('integration:foo,bar').invoke + project('foo').test.include?('foo').should be_true + project('foo').test.include?('bar').should be_true + project('foo').test.include?('baz').should be_false end - it "should execute only the named tasts" do - write "src/test/java/TestSomething.java", - "public class TestSomething extends junit.framework.TestCase { public void testNothing() {} }" - write "src/test/java/TestFails.java", "class TestFails {}" - task("integration:Something").invoke + it 'should execute only the named tasts' do + write 'src/test/java/TestSomething.java', + 'public class TestSomething extends junit.framework.TestCase { public void testNothing() {} }' + write 'src/test/java/TestFails.java', 'class TestFails {}' + task('integration:Something').invoke end end
