Author: assaf
Date: Sat Dec 22 01:22:39 2007
New Revision: 606431

URL: http://svn.apache.org/viewvc?rev=606431&view=rev
Log:
Test framework componentized along the same lines as the compilers.

Added:
    incubator/buildr/trunk/lib/java/compilers.rb
      - copied unchanged from r606399, 
incubator/buildr/trunk/lib/java/compile.rb
    incubator/buildr/trunk/lib/java/test_frameworks.rb
      - copied, changed from r606399, incubator/buildr/trunk/lib/java/test.rb
Removed:
    incubator/buildr/trunk/lib/java/compile.rb
    incubator/buildr/trunk/lib/java/test.rb
Modified:
    incubator/buildr/trunk/CHANGELOG
    incubator/buildr/trunk/lib/core/compile.rb
    incubator/buildr/trunk/lib/core/test.rb
    incubator/buildr/trunk/lib/java.rb
    incubator/buildr/trunk/lib/java/packaging.rb
    incubator/buildr/trunk/spec/sandbox.rb
    incubator/buildr/trunk/spec/test_spec.rb

Modified: incubator/buildr/trunk/CHANGELOG
URL: 
http://svn.apache.org/viewvc/incubator/buildr/trunk/CHANGELOG?rev=606431&r1=606430&r2=606431&view=diff
==============================================================================
--- incubator/buildr/trunk/CHANGELOG (original)
+++ incubator/buildr/trunk/CHANGELOG Sat Dec 22 01:22:39 2007
@@ -7,6 +7,7 @@
 * Changed: Compile extension and CompileTask are now separate from the Java 
module.  Multiple compilers can be used, either guessed from the project 
layout, or specified with compile.using(:name).
 * Changed: Test extension and TestTask are now separate from the Java module.  
JUnit and TestNG are Java specific extensions picked using test.with(:name).
 * Changed: For compile and test, use dependencies instead of classpath (with 
works are before).
+* Changed: Test framework componentized along the same lines at the compilers.
 * Removed: Prepare tasks removed.
 * Fixed: Artifact.pom resolves artifact without classifier, i.e 
org.testng:testng:jar:jdk15:5.1 uses org.testng:testng:pom:5.1 (Tommy).
 * Fixed: More patches towards JRuby support, courtesy of Vic Borja.

Modified: incubator/buildr/trunk/lib/core/compile.rb
URL: 
http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/core/compile.rb?rev=606431&r1=606430&r2=606431&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/core/compile.rb (original)
+++ incubator/buildr/trunk/lib/core/compile.rb Sat Dec 22 01:22:39 2007
@@ -25,9 +25,7 @@
         compilers[compiler.name.to_sym] = compiler
       end
 
-    private
-
-      def compilers
+      def compilers #:nodoc:
         @compilers ||= {}
       end
 

Modified: incubator/buildr/trunk/lib/core/test.rb
URL: 
http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/core/test.rb?rev=606431&r1=606430&r2=606431&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/core/test.rb (original)
+++ incubator/buildr/trunk/lib/core/test.rb Sat Dec 22 01:22:39 2007
@@ -5,6 +5,52 @@
 
 module Buildr
 
+  class TestFramework
+
+    class << self
+      def has?(name)
+        frameworks.has_key?(name)
+      end
+
+      def select(name)
+        raise ArgumentError, "No #{name} framework available. Did you install 
it?" unless frameworks.include?(name.to_sym)
+        frameworks[name.to_sym]
+      end
+
+      # Adds a test framework to the list of supported frameworks.
+      def add(framework)
+        framework = framework.new if Class === framework
+        frameworks[framework.name.to_sym] = framework
+      end
+
+      def frameworks #:nodoc:
+        @frameworks ||= {}
+      end
+
+    end
+
+    class Base
+
+      def initialize(args = {})
+        args[:name] ||= self.class.name.split('::').last.downcase.to_sym
+        args[:requires] ||= []
+        args[:patterns] ||= []
+        args.each { |name, value| instance_variable_set "@#{name}", value }
+      end
+
+      attr_accessor :name
+      attr_accessor :requires
+      attr_accessor :patterns
+
+      def files(path)
+        Dir[*Array(patterns).map { |pattern| "#{path}/**/#{pattern}" }]
+      end
+
+    end
+  
+  end
+
+
   # The test task controls the entire test lifecycle.
   #
   # You can use the test task in three ways. You can access and configure 
specific test tasks,
@@ -53,10 +99,6 @@
       end
     end
 
-    # List of supported test framework, first one being a default. Test 
frameworks are added by
-    # including them in TestTask (e.g. JUnit, TestNG).
-    TEST_FRAMEWORKS = []
-
     # Default options already set on each test task.
     DEFAULT_OPTIONS = { :fail_on_failure=>true, :fork=>:once, :properties=>{}, 
:environment=>{} }
 
@@ -68,6 +110,7 @@
       parent = Project.task_in_parent_project(name)
       @options = parent && parent.respond_to?(:options) ? parent.options.clone 
: DEFAULT_OPTIONS.clone
       enhance { run_tests }
+      select :junit
     end
 
     # The dependencies used for running the tests. Includes the compiled files 
(compile.target)
@@ -159,8 +202,8 @@
     # :call-seq:
     #   using(options) => self
     #
-    # Sets various test options and returns self. Accepts a hash of options, 
or symbols (a symbol sets that
-    # option to true). For example:
+    # Sets various test options from a hash and returns self.  Can also be 
used to select
+    # the test framework.  For example:
     #   test.using :testng, :fork=>:each, :properties=>{ 
'url'=>'http://localhost:8080' }
     #
     # Currently supports the following options:
@@ -176,7 +219,13 @@
     # * false -- Do not fork, running all test cases in the same JVM.
     def using(*args)
       args.pop.each { |key, value| options[key.to_sym] = value } if Hash === 
args.last
-      args.each { |key| options[key.to_sym] = true }
+      args.each do |name|
+        if TestFramework.has?(name)
+          select name
+        else
+          options[name.to_sym] = true
+        end
+      end 
       self
     end
 
@@ -218,17 +267,18 @@
     # and reducing based on the include/exclude patterns.
     def files
       return [] unless compile.target
-      base = Pathname.new(compile.target.to_s)
-      patterns = 
self.class.const_get("#{framework.to_s.upcase}_TESTS_PATTERN").to_a
-      FileList[patterns.map { |pattern| "#{base}/**/#{pattern}" }].
-        map { |file| 
Pathname.new(file).relative_path_from(base).to_s.ext('').gsub(File::SEPARATOR, 
'.') }.
-        select { |name| include?(name) }.reject { |name| name =~ /\$/ }.sort
+      fail "No test framework selected" unless @framework
+      @files ||= begin
+        base = Pathname.new(compile.target.to_s)
+        @framework.files(compile.target.to_s).map { |file| 
Pathname.new(file).relative_path_from(base).to_s }.
+          select { |file| include?(file.ext('').gsub(File::SEPARATOR, '.')) 
}.sort
+      end
     end
 
     # *Deprecated*: Use files instead.
     def classes
       warn_deprecated 'Use files instead'
-      files
+      files.map { |file| file.ext('').gsub(File::SEPARATOR, '.') }
     end
 
     # List of failed tests. Set after running the tests.
@@ -249,7 +299,7 @@
     #
     # Returns the dependencies for the selected test frameworks. Necessary for 
compiling and running test cases.
     def requires
-      Array(self.class.const_get("#{framework.to_s.upcase}_REQUIRES"))
+      @framework ? Array(@framework.requires) : []
     end
 
     # :call-seq:
@@ -257,7 +307,7 @@
     #
     # Returns the test framework, e.g. :junit, :testng.
     def framework
-      @framework ||= TEST_FRAMEWORKS.detect { |name| options[name] } || 
TEST_FRAMEWORKS.first
+      @framework && @framework.name
     end
 
     # :call-seq:
@@ -273,22 +323,24 @@
 
   protected
 
+    attr_reader :project
+
+    def select(name)
+      @framework = TestFramework.select(name)
+    end
+
     # :call-seq:
     #   run_tests()
     #
     # Runs the test cases using the selected test framework. Executes as part 
of the task.
     def run_tests
+      rm_rf report_to.to_s
       files = self.files
       if files.empty?
         @failed_tests = []
       else
         puts "Running tests in [EMAIL PROTECTED]" if verbose
-        @failed_tests = send("#{framework}_run",
-          :files        => files,
-          :dependencies => @dependencies + [compile.target],
-          :properties   => { 'baseDir' => compile.target.to_s 
}.merge(options[:properties] || {}),
-          :environment  => options[:environment] || {},
-          :java_args    => options[:java_args] || Buildr.options.java_args)
+        @failed_tests = @framework.run(files, self, (@dependencies + 
[compile.target]).compact.map(&:to_s))
         unless @failed_tests.empty?
           warn "The following tests failed:[EMAIL PROTECTED]('\n')}" if verbose
           fail 'Tests failed!'

Modified: incubator/buildr/trunk/lib/java.rb
URL: 
http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/java.rb?rev=606431&r1=606430&r2=606431&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/java.rb (original)
+++ incubator/buildr/trunk/lib/java.rb Sat Dec 22 01:22:39 2007
@@ -1,5 +1,5 @@
-require 'java/compile'
-require 'java/test'
+require 'java/compilers'
+require 'java/test_frameworks'
 require 'java/packaging'
 
 class Buildr::Project

Modified: incubator/buildr/trunk/lib/java/packaging.rb
URL: 
http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/java/packaging.rb?rev=606431&r1=606430&r2=606431&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/java/packaging.rb (original)
+++ incubator/buildr/trunk/lib/java/packaging.rb Sat Dec 22 01:22:39 2007
@@ -1,8 +1,8 @@
 require "core/project"
+require "core/compile"
+require "core/test"
 require "java/artifact"
 require "java/java"
-require "java/compile"
-require "java/test"
 require "tasks/zip"
 require "tasks/tar"
 

Copied: incubator/buildr/trunk/lib/java/test_frameworks.rb (from r606399, 
incubator/buildr/trunk/lib/java/test.rb)
URL: 
http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/java/test_frameworks.rb?p2=incubator/buildr/trunk/lib/java/test_frameworks.rb&p1=incubator/buildr/trunk/lib/java/test.rb&r1=606399&r2=606431&rev=606431&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/java/test.rb (original)
+++ incubator/buildr/trunk/lib/java/test_frameworks.rb Sat Dec 22 01:22:39 2007
@@ -1,11 +1,11 @@
 require 'core/build'
-require 'java/compile'
+require 'core/compile'
 require 'java/ant'
 require 'core/help'
 
 
 module Buildr
-  module Java
+  class TestFramework
 
     module JMock
       # JMock version..
@@ -14,14 +14,8 @@
       JMOCK_REQUIRES = ["jmock:jmock:jar:#{JMOCK_VERSION}"]
     end
 
-    # The JUnit test framework. This is the default test framework, but you 
can force it by
-    # adding the following to your project:
-    #   test.using :testng
-    #
-    # You can use the report method to control the junit:report task.
-    module JUnit
 
-      include JMock
+    class JUnit < Base
 
       # Used by the junit:report task. Access through JUnit#report if you want 
to set various
       # options for that task, for example:
@@ -72,17 +66,6 @@
 
       end
 
-      # JUnit version number.
-      JUNIT_VERSION = '4.3.1'
-      # JUnit specification.
-      JUNIT_REQUIRES = ["junit:junit:jar:#{JUNIT_VERSION}"] + JMOCK_REQUIRES
-      # Pattern for selecting JUnit test classes. Regardless of 
include/exclude patterns, only classes
-      # that match this pattern are used.
-      JUNIT_TESTS_PATTERN = [ 'Test*.class', '*Test.class' ]
-
-      # Ant-JUnit requires for JUnit and JUnit reports tasks.
-      Java.wrapper.setup { |jw| jw.classpath << 
"org.apache.ant:ant-junit:jar:#{Ant::VERSION}" }
-
       class << self
 
         # :call-seq:
@@ -96,20 +79,35 @@
           @report ||= Report.new
         end
 
-        def included(mod)
-          mod::TEST_FRAMEWORKS << :junit
-        end
-        private :included
+      end
+
+
+      # Ant-JUnit requires for JUnit and JUnit reports tasks.
+      ::Buildr::Java.wrapper.setup { |jw| jw.classpath << 
"org.apache.ant:ant-junit:jar:#{Ant::VERSION}" }
+
+      include JMock
+
+      # JUnit version number.
+      JUNIT_VERSION = '4.3.1'
+      # JUnit specification.
+      JUNIT_REQUIRES = ["junit:junit:jar:#{JUNIT_VERSION}"] + JMOCK_REQUIRES
+      # Pattern for selecting JUnit test classes. Regardless of 
include/exclude patterns, only classes
+      # that match this pattern are used.
+      JUNIT_TESTS_PATTERN = [ 'Test*.class', '*Test.class' ]
 
+      def initialize
+        super :requires=>JUNIT_REQUIRES, :patterns=>JUNIT_TESTS_PATTERN
       end
 
-    private
+      def files(path)
+        # Ignore anonymous classes.
+        super(path).reject { |name| name =~ /\$/ }
+      end
 
-      def junit_run(args)
-        rm_rf report_to.to_s ; mkpath report_to.to_s
+      def run(files, task, dependencies)
         # Use Ant to execute the Junit tasks, gives us performance and 
reporting.
         Buildr.ant('junit') do |ant|
-          case options[:fork]
+          case task.options[:fork]
           when false
             forking = {}
           when :each
@@ -119,32 +117,35 @@
           else
             fail 'Option fork must be :once, :each or false.'
           end
-          ant.junit forking.merge(:clonevm=>options[:clonevm] || false, 
:dir=>@project.path_to) do
-            ant.classpath :path=>args[:dependencies].map(&:to_s).each { |path| 
file(path).invoke }.join(File::PATH_SEPARATOR)
-            args[:properties].each { |key, value| ant.sysproperty :key=>key, 
:value=>value }
-            args[:environment].each { |key, value| ant.env :key=>key, 
:value=>value }
-            java_args = args[:java_args]
-            java_args = java_args.split(' ') if String === java_args
+          mkpath task.report_to.to_s
+          ant.junit forking.merge(:clonevm=>task.options[:clonevm] || false, 
:dir=>task.send(:project).path_to) do
+            ant.classpath :path=>dependencies.each { |path| file(path).invoke 
}.join(File::PATH_SEPARATOR)
+            (task.options[:properties] || []).each { |key, value| 
ant.sysproperty :key=>key, :value=>value }
+            (task.options[:environment] || []).each { |key, value| ant.env 
:key=>key, :value=>value }
+            java_args = task.options[:java_args] || Buildr.options.java_args
+            java_args = java_args.split(/\s+/) if String === java_args
             java_args.each { |value| ant.jvmarg :value=>value } if java_args
             ant.formatter :type=>'plain'
-            ant.formatter :type=>'xml'
             ant.formatter :type=>'plain', :usefile=>false # log test
             ant.formatter :type=>'xml'
-            ant.batchtest :todir=>report_to.to_s, :failureproperty=>'failed' do
-              ant.fileset :dir=>compile.target.to_s do
-                args[:files].each { |cls| ant.include :name=>cls.gsub('.', 
'/').ext('class') }
+            ant.batchtest :todir=>task.report_to.to_s, 
:failureproperty=>'failed' do
+              ant.fileset :dir=>task.compile.target.to_s do
+                files.each { |file| ant.include :name=>file }
               end
             end
           end
           return [] unless ant.project.getProperty('failed')
         end
         # But Ant doesn't tell us what went kaput, so we'll have to parse the 
test files.
-        args[:files].inject([]) do |failed, name|
-          if report = File.read(File.join(report_to.to_s, "TEST-#{name}.txt")) 
rescue nil
+        files.inject([]) do |failed, file|
+          test = file.ext('').gsub(File::SEPARATOR, '.')
+          report_file = File.join(task.report_to.to_s, "TEST-#{test}.txt")
+          if File.exist?(report_file)
+            report = File.read(report_file)
             # The second line (if exists) is the status line and we scan it 
for its values.
             status = (report.split("\n")[1] || 
'').scan(/(run|failures|errors):\s*(\d+)/i).
               inject(Hash.new(0)) { |hash, pair| hash[pair[0].downcase.to_sym] 
= pair[1].to_i ; hash }
-            failed << name if status[:failures] > 0 || status[:errors] > 0
+            failed << test if status[:failures] > 0 || status[:errors] > 0
           end
           failed
         end
@@ -154,7 +155,7 @@
         desc "Generate JUnit tests report in #{report.target}"
         task('report') do |task|
           report.generate Project.projects
-          puts "Generated JUnit tests report in #{report.target}"
+          puts "Generated JUnit tests report in #{report.target}" if verbose
         end
       end
 
@@ -162,10 +163,10 @@
 
     end
 
+    TestFramework.add JUnit
 
-    # The TestNG test framework. Use by adding the following to your project:
-    #   test.using :testng
-    module TestNG
+
+    class TestNG < Base
 
       include JMock
 
@@ -177,23 +178,21 @@
       # that match this pattern are used.
       TESTNG_TESTS_PATTERN = [ 'Test*.class', '*Test.class', '*TestCase.class' 
]
 
-      class << self
-
-        def included(mod)
-          mod::TEST_FRAMEWORKS << :testng
-        end
-        private :included
-
+      def initialize
+        super :requires=>TESTNG_REQUIRES, :patterns=>TESTNG_TESTS_PATTERN
       end
 
-    private
+      def files(path)
+        # Ignore anonymous classes.
+        super(path).reject { |name| name =~ /\$/ }
+      end
 
-      def testng_run(args)
-        cmd_args = [ 'org.testng.TestNG', '-sourcedir', 
compile.sources.join(';'), '-suitename', @project.name ]
-        cmd_args << '-d' << report_to.to_s
-        cmd_options = args.only(:properties, :java_args)
-        cmd_options[:classpath] = args[:dependencies]
-        args[:files].inject([]) do |failed, test|
+      def run(files, task, dependencies)
+        cmd_args = [ 'org.testng.TestNG', '-sourcedir', 
task.compile.sources.join(';'), '-suitename', task.send(:project).name ]
+        cmd_args << '-d' << task.report_to.to_s
+        cmd_options = { :properties=>task.options[:properties], 
:java_args=>task.options[:java_args],
+                        :classpath=>dependencies }
+        files.map { |file| file.ext('').gsub(File::SEPARATOR, '.') 
}.inject([]) do |failed, test|
           begin
             Buildr.java cmd_args, '-testclass', test, 
cmd_options.merge(:name=>test)
             failed
@@ -205,11 +204,8 @@
 
     end
 
-  end
+    TestFramework.add TestNG
 
-  class TestTask
-    include Java::JUnit
-    include Java::TestNG
   end
 
 end

Modified: incubator/buildr/trunk/spec/sandbox.rb
URL: 
http://svn.apache.org/viewvc/incubator/buildr/trunk/spec/sandbox.rb?rev=606431&r1=606430&r2=606431&view=diff
==============================================================================
--- incubator/buildr/trunk/spec/sandbox.rb (original)
+++ incubator/buildr/trunk/spec/sandbox.rb Sat Dec 22 01:22:39 2007
@@ -12,7 +12,7 @@
   # repository and cache these across test cases.
   repositories.remote << "http://repo1.maven.org/maven2";
   Java.wrapper.load # Anything added to the classpath.
-  artifacts(TestTask::JUNIT_REQUIRES, TestTask::TESTNG_REQUIRES, 
Java::JMock::JMOCK_REQUIRES).each { |a| file(a).invoke }
+  artifacts(TestFramework.frameworks.values.map(&:requires).flatten).each { 
|a| file(a).invoke }
   task("buildr:initialize").invoke
 
 

Modified: incubator/buildr/trunk/spec/test_spec.rb
URL: 
http://svn.apache.org/viewvc/incubator/buildr/trunk/spec/test_spec.rb?rev=606431&r1=606430&r2=606431&view=diff
==============================================================================
--- incubator/buildr/trunk/spec/test_spec.rb (original)
+++ incubator/buildr/trunk/spec/test_spec.rb Sat Dec 22 01:22:39 2007
@@ -154,27 +154,6 @@
     lambda { task("clean").invoke }.should change { 
File.exist?(project("foo").test.report_to.to_s) }.to(false)
   end
 
-  it "should pass baseDir property to test case" do
-    define "foo", :base_dir=>"somewhere"
-    project("foo").test.stub!(:files).and_return ["TestThis"] 
-    project("foo").test.should_receive(:junit_run) do |arg|
-      arg[:properties]["baseDir"].should 
eql(project("foo").test.compile.target.to_s)
-      []
-    end
-    project("foo").test.invoke
-  end 
-
-  it "should pass environment variables to test case" do
-    define "foo" do
-      test.using :environment=>{ "foo"=>"bar" }
-    end
-    project("foo").test.stub!(:files).and_return ["TestThis"] 
-    project("foo").test.should_receive(:junit_run) do |arg|
-      arg[:environment]["foo"].should eql("bar")
-      []
-    end
-    project("foo").test.invoke
-  end 
 end
 
 
@@ -221,7 +200,7 @@
   end
 
   it "should fail if only one test fails" do
-    project("foo").test.stub!(:junit_run).and_return [EMAIL PROTECTED]
+    TestFramework.frameworks[:junit].stub!(:run).and_return [EMAIL PROTECTED]
     lambda { project("foo").test.invoke }.should raise_error(RuntimeError, 
/Tests failed/)
   end
 
@@ -236,7 +215,7 @@
     @tests = ["FailingTest1", "FailingTest2"]
     define "foo"
     project("foo").test.stub!(:files).and_return @tests
-    project("foo").test.stub!(:junit_run).and_return @tests
+    TestFramework.frameworks[:junit].stub!(:run).and_return @tests
   end
 
   it "should fail" do
@@ -260,7 +239,7 @@
 end
 
 
-describe Buildr::TestTask, " using junit" do
+describe Buildr::TestFramework::JUnit do
   before do
     write "src/test/java/PassingTest.java", 
       "public class PassingTest extends junit.framework.TestCase { public void 
testNothing() {} }"
@@ -270,29 +249,29 @@
   end
 
   it "should include JUnit requirements" do
-    project("foo").test.requires.should include(*TestTask::JUNIT_REQUIRES)
-    project("foo").test.compile.dependencies.should 
include(*artifacts(TestTask::JUNIT_REQUIRES))
-    project("foo").test.dependencies.should 
include(*artifacts(TestTask::JUNIT_REQUIRES))
+    project("foo").test.requires.should 
include(*TestFramework::JUnit::JUNIT_REQUIRES)
+    project("foo").test.compile.dependencies.should 
include(*artifacts(TestFramework::JUnit::JUNIT_REQUIRES))
+    project("foo").test.dependencies.should 
include(*artifacts(TestFramework::JUnit::JUNIT_REQUIRES))
   end
 
   it "should include JMock requirements" do
-    project("foo").test.requires.should include(*TestTask::JMOCK_REQUIRES)
-    project("foo").test.compile.dependencies.should 
include(*artifacts(TestTask::JMOCK_REQUIRES))
-    project("foo").test.dependencies.should 
include(*artifacts(TestTask::JMOCK_REQUIRES))
+    project("foo").test.requires.should 
include(*TestFramework::JMock::JMOCK_REQUIRES)
+    project("foo").test.compile.dependencies.should 
include(*artifacts(TestFramework::JMock::JMOCK_REQUIRES))
+    project("foo").test.dependencies.should 
include(*artifacts(TestFramework::JMock::JMOCK_REQUIRES))
   end
 
   it "should include classes starting with and ending with Test" do
     ["TestThis", "ThisTest", "ThisThat"].each do |name|
       write "target/test/classes/#{name}.class"
     end
-    project("foo").test.files.map { |file| File.basename(file) }.should == 
["TestThis", "ThisTest"]
+    project("foo").test.files.map { |file| File.basename(file) }.should == 
["TestThis.class", "ThisTest.class"]
   end
 
   it "should ignore inner classes" do
     ["TestThis", "TestThis$Innner"].each do |name|
       write "target/test/classes/#{name}.class"
     end
-    project("foo").test.files.map { |file| File.basename(file) }.should == 
["TestThis"]
+    project("foo").test.files.map { |file| File.basename(file) }.should == 
["TestThis.class"]
   end
 
   it "should pass when JUnit test case passes" do
@@ -305,6 +284,12 @@
     lambda { project("foo").test.invoke }.should raise_error(RuntimeError, 
/Tests failed/)
   end
 
+  it 'should report failed test names' do
+    project("foo").test.include "FailingTest"
+    project("foo").test.invoke rescue
+    project("foo").test.failed_tests.should eql(['FailingTest'])
+  end
+
   it "should report to reports/junit" do
     project("foo").test.report_to.should 
be(project("foo").file("reports/junit"))
     project("foo").test.include("PassingTest").invoke
@@ -354,29 +339,29 @@
   end
 
   it "should include TestNG requirements" do
-    project("foo").test.requires.should include(*TestTask::TESTNG_REQUIRES)
-    project("foo").test.compile.dependencies.should 
include(*artifacts(TestTask::TESTNG_REQUIRES))
-    project("foo").test.dependencies.should 
include(*artifacts(TestTask::TESTNG_REQUIRES))
+    project("foo").test.requires.should 
include(*TestFramework::TestNG::TESTNG_REQUIRES)
+    project("foo").test.compile.dependencies.should 
include(*artifacts(TestFramework::TestNG::TESTNG_REQUIRES))
+    project("foo").test.dependencies.should 
include(*artifacts(TestFramework::TestNG::TESTNG_REQUIRES))
   end
 
   it "should include TestNG requirements" do
-    project("foo").test.requires.should include(*TestTask::JMOCK_REQUIRES)
-    project("foo").test.compile.dependencies.should 
include(*artifacts(TestTask::JMOCK_REQUIRES))
-    project("foo").test.dependencies.should 
include(*artifacts(TestTask::JMOCK_REQUIRES))
+    project("foo").test.requires.should 
include(*TestFramework::JMock::JMOCK_REQUIRES)
+    project("foo").test.compile.dependencies.should 
include(*artifacts(TestFramework::JMock::JMOCK_REQUIRES))
+    project("foo").test.dependencies.should 
include(*artifacts(TestFramework::JMock::JMOCK_REQUIRES))
   end
 
   it "should include classes starting with and ending with Test" do
     ["TestThis", "ThisTest", "ThisThat"].each do |name|
       write File.join(project("foo").test.compile.target.to_s, 
name).ext("class")
     end
-    project("foo").test.files.map { |file| File.basename(file) }.should == 
["TestThis", "ThisTest"]
+    project("foo").test.files.map { |file| File.basename(file) }.should == 
["TestThis.class", "ThisTest.class"]
   end
 
   it "should ignore inner classes" do
     ["TestThis", "TestThis$Innner"].each do |name|
       write "target/test/classes/#{name}.class"
     end
-    project("foo").test.files.map { |file| File.basename(file) }.should == 
["TestThis"]
+    project("foo").test.files.map { |file| File.basename(file) }.should == 
["TestThis.class"]
   end
 
   it "should pass when TestNG test case passes" do
@@ -389,6 +374,12 @@
     lambda { project("foo").test.invoke }.should raise_error(RuntimeError, 
/Tests failed/)
   end
 
+  it 'should report failed test names' do
+    project("foo").test.include "FailingTest"
+    project("foo").test.invoke rescue
+    project("foo").test.failed_tests.should eql(['FailingTest'])
+  end
+
   it "should report to reports/testng" do
     project("foo").test.report_to.should 
be(project("foo").file("reports/testng"))
   end
@@ -702,17 +693,17 @@
 describe Rake::Task, "junit:report" do
 
   it "should default to the target directory reports/junit" do
-    JUnit.report.target.should eql("reports/junit")
+    TestFramework::JUnit.report.target.should eql("reports/junit")
   end
 
   it "should generate report into the target directory" do
-    JUnit.report.target = "test-report"
-    lambda { task("junit:report").invoke }.should change { 
File.exist?(JUnit.report.target) }.to(true)
+    TestFramework::JUnit.report.target = "test-report"
+    lambda { task("junit:report").invoke }.should change { 
File.exist?(TestFramework::JUnit.report.target) }.to(true)
   end
 
   it "should clean after itself" do
-    mkpath JUnit.report.target
-    lambda { task("clean").invoke }.should change { 
File.exist?(JUnit.report.target) }.to(false)
+    mkpath TestFramework::JUnit.report.target
+    lambda { task("clean").invoke }.should change { 
File.exist?(TestFramework::JUnit.report.target) }.to(false)
   end
 
   it "should generate a consolidated XML report" do
@@ -720,17 +711,17 @@
   end
 
   it "should default to generating a report with frames" do
-    JUnit.report.frames.should be_true
+    TestFramework::JUnit.report.frames.should be_true
   end
 
   it "should generate single page when frames is false" do
-    JUnit.report.frames = false
+    TestFramework::JUnit.report.frames = false
     task("junit:report").invoke
     file("reports/junit/html/junit-noframes.html").should exist
   end
 
   it "should generate frame page when frames is false" do
-    JUnit.report.frames = true
+    TestFramework::JUnit.report.frames = true
     task("junit:report").invoke
     file("reports/junit/html/index.html").should exist
   end
@@ -745,7 +736,7 @@
   end
 
   after do
-    JUnit.instance_eval { @report = nil }
+    TestFramework::JUnit.instance_eval { @report = nil }
   end
 end
 


Reply via email to