buildr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From as...@apache.org
Subject svn commit: r615324 - in /incubator/buildr/trunk: lib/core/ lib/java/ lib/java/org/apache/buildr/ spec/
Date Fri, 25 Jan 2008 20:15:51 GMT
Author: assaf
Date: Fri Jan 25 12:15:50 2008
New Revision: 615324

URL: http://svn.apache.org/viewvc?rev=615324&view=rev
Log:
Breaking change to test framework to simplify handling of dependencies, tested against ODE

Modified:
    incubator/buildr/trunk/lib/core/common.rb
    incubator/buildr/trunk/lib/core/compile.rb
    incubator/buildr/trunk/lib/core/test.rb
    incubator/buildr/trunk/lib/java/org/apache/buildr/JUnitTestFilter.class
    incubator/buildr/trunk/lib/java/org/apache/buildr/JUnitTestFilter.java
    incubator/buildr/trunk/lib/java/test_frameworks.rb
    incubator/buildr/trunk/spec/java_packaging_spec.rb
    incubator/buildr/trunk/spec/java_test_frameworks.rb
    incubator/buildr/trunk/spec/test_spec.rb

Modified: incubator/buildr/trunk/lib/core/common.rb
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/core/common.rb?rev=615324&r1=615323&r2=615324&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/core/common.rb (original)
+++ incubator/buildr/trunk/lib/core/common.rb Fri Jan 25 12:15:50 2008
@@ -1,8 +1,8 @@
-require "tempfile"
-require "pathname"
-require "core/transports"
-require "open-uri"
-require "uri/open-sftp"
+require 'tempfile'
+require 'pathname'
+require 'core/transports'
+require 'open-uri'
+require 'uri/open-sftp'
 
 
 class Hash
@@ -13,13 +13,13 @@
     #   Hash.from_java_properties(string)
     #
     # Returns a hash from a string in the Java properties file format. For example:
-    #   str = "foo=bar\nbaz=fab"
+    #   str = 'foo=bar\nbaz=fab'
     #   Hash.from_properties(str)
-    #   => { "foo"=>"bar", "baz"=>"fab" }.to_properties
+    #   => { 'foo'=>'bar', 'baz'=>'fab' }.to_properties
     def from_java_properties(string)
-      string.gsub(/\\\n/, "").split("\n").select { |line| line =~ /^[^#].*=.*/ }.
+      string.gsub(/\\\n/, '').split("\n").select { |line| line =~ /^[^#].*=.*/ }.
         map { |line| line.gsub(/\\[trnf\\]/) { |escaped| {?t=>"\t", ?r=>"\r", ?n=>"\n",
?f=>"\f", ?\\=>"\\"}[escaped[1]] } }.
-        map { |line| line.split("=") }.
+        map { |line| line.split('=') }.
         inject({}) { |hash, (name, value)| hash.merge(name=>value) }
     end
 
@@ -51,13 +51,13 @@
   end
 
   # :call-seq:
-  #   to_java_properties() => string
+  #   to_java_properties => string
   #
   # Convert hash to string format used for Java properties file. For example:
-  #   { "foo"=>"bar", "baz"=>"fab" }.to_properties
+  #   { 'foo'=>'bar', 'baz'=>'fab' }.to_properties
   #   => foo=bar
   #      baz=fab
-  def to_java_properties()
+  def to_java_properties
     keys.sort.map { |key|
       value = self[key].gsub(/[\t\r\n\f\\]/) { |escape| "\\" + {"\t"=>"t", "\r"=>"r",
"\n"=>"n", "\f"=>"f", "\\"=>"\\"}[escape] }
       "#{key}=#{value}"
@@ -71,7 +71,7 @@
   class FileList
     class << self
       def recursive(*dirs)
-        FileList[dirs.map { |dir| File.join(dir, "/**/{*,.*}") }].reject { |file| File.basename(file)
=~ /^[.]{1,2}$/ }
+        FileList[dirs.map { |dir| File.join(dir, '/**/{*,.*}') }].reject { |file| File.basename(file)
=~ /^[.]{1,2}$/ }
       end
     end
   end
@@ -112,9 +112,9 @@
   #
   # For example:
   #   COMMONS             = struct(
-  #     :collections      =>"commons-collections:commons-collections:jar:3.1",
-  #     :lang             =>"commons-lang:commons-lang:jar:2.1",
-  #     :logging          =>"commons-logging:commons-logging:jar:1.0.3",
+  #     :collections      =>'commons-collections:commons-collections:jar:3.1',
+  #     :lang             =>'commons-lang:commons-lang:jar:2.1',
+  #     :logging          =>'commons-logging:commons-logging:jar:1.0.3',
   #   )
   #
   #   compile.with COMMONS.logging
@@ -129,16 +129,16 @@
   # Write the contents into a file. The second form calls the block and writes the result.
   #
   # For example:
-  #   write "TIMESTAMP", Time.now
-  #   write("TIMESTAMP") { Time.now }
+  #   write 'TIMESTAMP', Time.now
+  #   write('TIMESTAMP') { Time.now }
   #
   # Yields to the block before writing the file, so you can chain read and write together.
   # For example:
-  #   write("README") { read("README").sub("${build}", Time.now) }
+  #   write('README') { read('README').sub("${build}", Time.now) }
   def write(name, content = nil)
     mkpath File.dirname(name), :verbose=>false
     content = yield if block_given?
-    File.open(name.to_s, "wb") { |file| file.write content.to_s }
+    File.open(name.to_s, 'wb') { |file| file.write content.to_s }
     content.to_s
   end
 
@@ -150,8 +150,8 @@
   # the result of the block.
   #
   # For example:
-  #   puts read("README")
-  #   read("README") { |text| puts text }
+  #   puts read('README')
+  #   read('README') { |text| puts text }
   def read(name)
     contents = File.open(name.to_s) { |f| f.read }
     if block_given?
@@ -175,7 +175,7 @@
   # checksums on the server it will verify the download before saving it.
   #
   # For example:
-  #   download "image.jpg"=>"http://example.com/theme/image.jpg"
+  #   download 'image.jpg'=>'http://example.com/theme/image.jpg'
   def download(args)
     args = URI.parse(args) if String === args
     if URI === args
@@ -184,7 +184,7 @@
       temp = Tempfile.open(File.basename(args.to_s))
       file(temp.path).tap do |task|
         # Since temporary file exists, force a download.
-        class << task ; def needed?() ; true ; end ; end
+        class << task ; def needed? ; true ; end ; end
         task.sources << args
         task.enhance { args.download temp }
       end
@@ -207,7 +207,7 @@
   # You can specify the mapping using a Hash, and it will map ${key} fields found in each
source
   # file into the appropriate value in the target file. For example:
   #
-  #   filter.using "version"=>"1.2", "build"=>Time.now
+  #   filter.using 'version'=>'1.2', 'build'=>Time.now
   #
   # will replace all occurrences of <tt>${version}</tt> with <tt>1.2</tt>,
and <tt>${build}</tt>
   # with the current date/time.
@@ -221,13 +221,13 @@
   # A filter has one target directory, but you can specify any number of source directories,
   # either when creating the filter or calling #from. Include/exclude patterns are specified
   # relative to the source directories, so:
-  #   filter.include "*.png"
+  #   filter.include '*.png'
   # will only include PNG files from any of the source directories.
   #
   # See Buildr#filter.
   class Filter
 
-    def initialize() #:nodoc:
+    def initialize #:nodoc:
       @include = []
       @exclude = []
       @sources = []
@@ -242,7 +242,7 @@
     # Adds additional directories from which to copy resources.
     #
     # For example:
-    #   filter.from("src").into("target").using("build"=>Time.now)
+    #   filter.from('src').into('target').using('build'=>Time.now)
     def from(*sources)
       @sources |= sources.flatten.map { |dir| file(dir.to_s) }
       self
@@ -257,7 +257,7 @@
     # Sets the target directory into which files are copied and returns self.
     #
     # For example:
-    #   filter.from("src").into("target").using("build"=>Time.now)
+    #   filter.from('src').into('target').using('build'=>Time.now)
     def into(dir)
       @target = file(dir.to_s) { |task| run if target == task && !sources.empty?
}
       self
@@ -293,7 +293,7 @@
 
     # :call-seq:
     #   using(mapping) => self
-    #   using() { |file_name, contents| ... } => self
+    #   using { |file_name, contents| ... } => self
     #
     # Specifies the mapping to use and returns self.
     #
@@ -306,9 +306,9 @@
     # * Regexp -- Maps the matched data (e.g. <code>/=(.*?)=/</code>
     #
     # For example:
-    #   filter.using "version"=>"1.2"
+    #   filter.using 'version'=>'1.2'
     # Is the same as:
-    #   filter.using :maven, "version"=>"1.2"
+    #   filter.using :maven, 'version'=>'1.2'
     #
     # You can also pass a proc or method. It will be called with the file name and content,
     # to return the mapped content.
@@ -319,26 +319,26 @@
       when Hash # Maven hash mapping
         using :maven, *args
       when Symbol # Mapping from a method
-        raise ArgumentError, "Expected mapper type followed by mapping hash" unless args.size
== 2 && Hash === args[1]
+        raise ArgumentError, 'Expected mapper type followed by mapping hash' unless args.size
== 2 && Hash === args[1]
         @mapper, @mapping = *args
       when Regexp # Mapping using a regular expression
-        raise ArgumentError, "Expected regular expression followed by mapping hash" unless
args.size == 2 && Hash === args[1]
+        raise ArgumentError, 'Expected regular expression followed by mapping hash' unless
args.size == 2 && Hash === args[1]
         @mapper, @mapping = *args
       else
-        raise ArgumentError, "Expected proc, method or a block" if args.size > 1 || (args.first
&& block)
+        raise ArgumentError, 'Expected proc, method or a block' if args.size > 1 || (args.first
&& block)
         @mapping = args.first || block
       end
       self
     end
 
     # :call-seq:
-    #    run() => boolean
+    #    run => boolean
     #
     # Runs the filter.
-    def run()
-      raise "No source directory specified, where am I going to find the files to filter?"
if sources.empty?
+    def run
+      raise 'No source directory specified, where am I going to find the files to filter?'
if sources.empty?
       sources.each { |source| raise "Source directory #{source} doesn't exist" unless File.exist?(source.to_s)
}
-      raise "No target directory specified, where am I going to copy the files to?" if target.nil?
+      raise 'No target directory specified, where am I going to copy the files to?' if target.nil?
 
       copy_map = sources.flatten.map(&:to_s).inject({}) do |map, source|
         base = Pathname.new(source)
@@ -365,17 +365,17 @@
             mkpath File.dirname(dest)
             case mapping
             when Proc, Method # Call on input, accept output.
-              mapped = mapping.call(path, File.open(source, "rb") { |file| file.read })
-              File.open(dest, "wb") { |file| file.write mapped }
+              mapped = mapping.call(path, File.open(source, 'rb') { |file| file.read })
+              File.open(dest, 'wb') { |file| file.write mapped }
             when Hash # Map ${key} to value
-              content = File.open(source, "rb") { |file| file.read }
+              content = File.open(source, 'rb') { |file| file.read }
               if Symbol === @mapper
                 mapped = send("#{@mapper}_mapper", content) { |key| mapping[key] }
               else
                 mapped = regexp_mapper(content) { |key| mapping[key] }
               end
                 #gsub(/\$\{[^}]*\}/) { |str| mapping[str[2..-2]] || str }
-              File.open(dest, "wb") { |file| file.write mapped }
+              File.open(dest, 'wb') { |file| file.write mapped }
             when nil # No mapping.
               cp source, dest
               File.chmod(0664, dest)
@@ -390,7 +390,7 @@
     end
 
     # Returns the target directory. 
-    def to_s()
+    def to_s
       @target.to_s
     end
 
@@ -424,10 +424,10 @@
   # A filter is not a task, you must call the Filter#run method to execute it.
   #
   # For example, to copy all files from one directory to another:
-  #   filter("src/files").into("target/classes").run
+  #   filter('src/files').into('target/classes').run
   # To include only the text files, and replace each instance of <tt>${build}</tt>
with the current
   # date/time:
-  #   filter("src/files").into("target/classes").include("*.txt").using("build"=>Time.now).run
+  #   filter('src/files').into('target/classes').include('*.txt').using('build'=>Time.now).run
   def filter(*sources)
     Filter.new.from(*sources)
   end
@@ -448,11 +448,11 @@
   #   warn_deprecated(message)
   #
   # Use with deprecated methods and classes. This method automatically adds the file name
and line number,
-  # and the text "Deprecated" before the message, and eliminated duplicate warnings. It only
warns when
+  # and the text 'Deprecated' before the message, and eliminated duplicate warnings. It only
warns when
   # running in verbose mode.
   #
   # For example:
-  #   warn_deprecated "Please use new_foo instead of foo."
+  #   warn_deprecated 'Please use new_foo instead of foo.'
   def warn_deprecated(message) #:nodoc:
     return unless verbose
     "#{caller[1]}: Deprecated: #{message}".tap do |message|

Modified: incubator/buildr/trunk/lib/core/compile.rb
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/core/compile.rb?rev=615324&r1=615323&r2=615324&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/core/compile.rb (original)
+++ incubator/buildr/trunk/lib/core/compile.rb Fri Jan 25 12:15:50 2008
@@ -364,7 +364,10 @@
     def initialize(*args) #:nodoc:
       super
       @filter = Buildr::Filter.new
-      enhance { filter.run unless filter.sources.empty? }
+      enhance do
+        mkpath target.to_s, :verbose=>false
+        filter.run unless filter.sources.empty?
+      end
     end
 
     # :call-seq:

Modified: incubator/buildr/trunk/lib/core/test.rb
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/core/test.rb?rev=615324&r1=615323&r2=615324&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/core/test.rb (original)
+++ incubator/buildr/trunk/lib/core/test.rb Fri Jan 25 12:15:50 2008
@@ -329,24 +329,16 @@
       self
     end
 
-    # :call-seq:
-    #    tests => strings
-    #
-    # List the tests that this task will run.
-    def tests
-      fail "No test framework selected" unless framework
-      @tests ||= @framework.tests(@project).select { |test| include?(test) }.sort
-    end
-
     # *Deprecated*: Use tests instead.
     def classes
       warn_deprecated 'Call tests instead of classes'
       tests
     end
 
+    # After running the task, returns all tests selected to run, based on availability and
include/exclude pattern.
+    attr_reader :tests
     # After running the task, returns all the tests that failed, empty array if all tests
passed.
     attr_reader :failed_tests
-
     # After running the task, returns all the tests that passed, empty array if no tests
passed.
     attr_reader :passed_tests
 
@@ -356,9 +348,11 @@
     # Returns the test framework, e.g. :junit, :testng.
     def framework
       unless @framework
-        frameworks = TestFramework.frameworks.select { |cls| cls.applies_to?(@project) }
-        candidate = @project.parent && frameworks.detect { |framework| framework.to_sym
== @project.parent.test.framework } ||
-          frameworks.first
+        # Start with all frameworks that apply (e.g. JUnit and TestNG for Java),
+        # and pick the first (default) one, unless already specified in parent project.
+        candidates = TestFramework.frameworks.select { |cls| cls.applies_to?(@project) }
+        candidate = @project.parent && candidates.detect { |framework| framework.to_sym
== @project.parent.test.framework } ||
+          candidates.first
         self.framework = candidate if candidate
       end
       @framework && @framework.class.to_sym
@@ -389,7 +383,7 @@
       #  each { |name| options[name] = @parent_task.options[name] } if @parent_task.respond_to?(:options)
       @framework = cls.new(options)
       # Test framework dependency.
-      with @framework.class.dependencies
+      with @framework.dependencies
     end
 
     # :call-seq:
@@ -404,13 +398,15 @@
 
     # Runs the tests using the selected test framework.
     def run_tests
+      dependencies = Buildr.artifacts(self.dependencies).map(&:to_s).uniq
       rm_rf report_to.to_s
-      if tests.empty?
+      @tests = @framework.tests(self, dependencies).select { |test| include?(test) }.sort
+      if @tests.empty?
         @passed_tests, @failed_tests = [], []
       else
         puts "Running tests in #{@project.name}" if verbose
-        @passed_tests = @framework.run(tests, self, @dependencies.compact.map(&:to_s))
-        @failed_tests = tests - @passed_tests
+        @passed_tests = @framework.run(@tests, self, dependencies)
+        @failed_tests = @tests - @passed_tests
         unless @failed_tests.empty?
           warn "The following tests failed:\n#{@failed_tests.join('\n')}" if verbose
           fail 'Tests failed!'
@@ -424,6 +420,11 @@
       @exclude.clear
     end
 
+    def invoke_prerequisites(args, chain) #:nodoc:
+      @prerequisites |= FileList[@dependencies.uniq]
+      super
+    end
+
   end
 
 
@@ -540,7 +541,7 @@
       test.with Array(project.resources.target)
       # Dependency on compiled tests and resources.  Dependencies added using with.
       test.dependencies.concat Array(test.compile.target) if test.compile.target
-      test.dependencies.concat Array(test.resources.target)
+      test.dependencies.concat Array(test.resources.target) if test.resources.sources
       # Picking up the test frameworks adds further dependencies.
       test.framework
 

Modified: incubator/buildr/trunk/lib/java/org/apache/buildr/JUnitTestFilter.class
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/java/org/apache/buildr/JUnitTestFilter.class?rev=615324&r1=615323&r2=615324&view=diff
==============================================================================
Binary files - no diff available.

Modified: incubator/buildr/trunk/lib/java/org/apache/buildr/JUnitTestFilter.java
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/java/org/apache/buildr/JUnitTestFilter.java?rev=615324&r1=615323&r2=615324&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/java/org/apache/buildr/JUnitTestFilter.java (original)
+++ incubator/buildr/trunk/lib/java/org/apache/buildr/JUnitTestFilter.java Fri Jan 25 12:15:50
2008
@@ -1,5 +1,7 @@
 package org.apache.buildr;
 
+import java.io.File;
+import java.io.IOException;
 import java.net.URL;
 import java.net.URLClassLoader;
 import java.net.MalformedURLException;
@@ -9,10 +11,15 @@
 
   private ClassLoader _loader;
 
-  public JUnitTestFilter(String[] paths) throws MalformedURLException {
+  public JUnitTestFilter(String[] paths) throws IOException {
     URL[] urls = new URL[paths.length];
-    for (int i = 0 ; i < paths.length ; ++i)
-      urls[i] = new URL("file://" + paths[i]);
+    for (int i = 0 ; i < paths.length ; ++i) {
+      File file = new File(paths[i]).getCanonicalFile();
+      if (file.exists())
+        urls[i] = file.toURL();
+      else
+        throw new IOException("No file or directory with the name " + file);
+    }
     _loader = new URLClassLoader(urls, getClass().getClassLoader());
   }
 

Modified: incubator/buildr/trunk/lib/java/test_frameworks.rb
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/java/test_frameworks.rb?rev=615324&r1=615323&r2=615324&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/java/test_frameworks.rb (original)
+++ incubator/buildr/trunk/lib/java/test_frameworks.rb Fri Jan 25 12:15:50 2008
@@ -107,16 +107,20 @@
 
     end
 
-    def tests(project) #:nodoc:
-      return [] unless project.test.compile.target
-      target = Pathname.new(project.test.compile.target.to_s)
+    def tests(task, dependencies) #:nodoc:
+      return [] unless task.compile.target
+      target = Pathname.new(task.compile.target.to_s)
       candidates = Dir["#{target}/**/*.class"].
         map { |file| Pathname.new(file).relative_path_from(target).to_s.ext('').gsub(File::SEPARATOR,
'.') }.
         reject { |name| name =~ /\$/ }
-      classpath = [target.to_s + '/'] + Buildr.artifacts(dependencies).map(&:to_s)
-      Java.load # JRuby necessiated casting.
-      Java.org.apache.buildr.JUnitTestFilter.new(classpath.map(&:to_s).to_java(Java.java.lang.String)).
-        filter(candidates.to_java(Java.java.lang.String)).map(&:to_s)
+      begin
+        Java.load
+        Java.org.apache.buildr.JUnitTestFilter.new(dependencies.to_java(Java.java.lang.String)).
+          filter(candidates.to_java(Java.java.lang.String)).map(&:to_s)
+      rescue =>ex
+        puts "#{ex.class}: #{ex.message}" if verbose
+        raise
+      end
     end
 
     def run(tests, task, dependencies) #:nodoc:
@@ -134,7 +138,7 @@
         end
         mkpath task.report_to.to_s
         ant.junit forking.merge(:clonevm=>options[:clonevm] || false, :dir=>task.send(:project).path_to)
do
-          ant.classpath :path=>dependencies.each { |path| file(path).invoke }.join(File::PATH_SEPARATOR)
+          ant.classpath :path=>dependencies.join(File::PATH_SEPARATOR)
           (options[:properties] || []).each { |key, value| ant.sysproperty :key=>key,
:value=>value }
           (options[:environment] || []).each { |key, value| ant.env :key=>key, :value=>value
}
           ant.formatter :type=>'plain'
@@ -199,9 +203,9 @@
 
     end
 
-    def tests(project) #:nodoc:
-      return [] unless project.test.compile.target
-      target = Pathname.new(project.test.compile.target.to_s)
+    def tests(task, dependencies) #:nodoc:
+      return [] unless task.compile.target
+      target = Pathname.new(task.compile.target.to_s)
       Dir["#{target}/**/*.class"].
         map { |file| Pathname.new(file).relative_path_from(target).to_s.ext('').gsub(File::SEPARATOR,
'.') }.
         reject { |name| name =~ /\$/ }.select { |name| cls_name = name.split('.').last
@@ -230,3 +234,9 @@
 
 Buildr::TestFramework << Buildr::JUnit
 Buildr::TestFramework << Buildr::TestNG
+
+# Backward compatibility crap.
+Buildr::JUnit::JUNIT_REQUIRES = Buildr::JUnit::REQUIRES
+Buildr::TestNG::TestNG_REQUIRES = Buildr::TestNG::REQUIRES
+Java::JUnit = Buildr::JUnit
+Java::TestNG = Buildr::TestNG

Modified: incubator/buildr/trunk/spec/java_packaging_spec.rb
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/spec/java_packaging_spec.rb?rev=615324&r1=615323&r2=615324&view=diff
==============================================================================
--- incubator/buildr/trunk/spec/java_packaging_spec.rb (original)
+++ incubator/buildr/trunk/spec/java_packaging_spec.rb Fri Jan 25 12:15:50 2008
@@ -387,11 +387,6 @@
     inspect_war { |files| files.should include('test.html') }
   end
 
-  it 'should ignore webapp directory if missing' do
-    define('foo', :version=>'1.0') { package(:war) }
-    inspect_war { |files| files.should eql(['META-INF/', 'META-INF/MANIFEST.MF']) }
-  end
-
   it 'should accept files from :classes option' do
     write 'src/main/java/Test.java', 'class Test {}'
     write 'classes/test'

Modified: incubator/buildr/trunk/spec/java_test_frameworks.rb
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/spec/java_test_frameworks.rb?rev=615324&r1=615323&r2=615324&view=diff
==============================================================================
--- incubator/buildr/trunk/spec/java_test_frameworks.rb (original)
+++ incubator/buildr/trunk/spec/java_test_frameworks.rb Fri Jan 25 12:15:50 2008
@@ -33,13 +33,17 @@
   it 'should include public classes extending junit.framework.TestCase' do
     write 'src/test/java/com/example/FirstTest.java', <<-JAVA
       package com.example;
-      public class FirstTest extends junit.framework.TestCase { }
+      public class FirstTest extends junit.framework.TestCase {
+        public void testNothing() { }
+      }
     JAVA
     write 'src/test/java/com/example/AnotherOne.java', <<-JAVA
       package com.example;
-      public class AnotherOne extends junit.framework.TestCase { }
+      public class AnotherOne extends junit.framework.TestCase {
+        public void testNothing() { }
+      }
     JAVA
-    define('foo').test.compile.invoke
+    define('foo').test.invoke
     project('foo').test.tests.should include('com.example.FirstTest', 'com.example.AnotherOne')
   end
 
@@ -47,18 +51,21 @@
     write 'src/test/java/NotATest.java', <<-JAVA
       public class NotATest { }
     JAVA
-    define('foo').test.compile.invoke
+    define('foo').test.invoke
     project('foo').test.tests.should be_empty
   end
 
   it 'should ignore inner classes' do
     write 'src/test/java/InnerClassTest.java', <<-JAVA
       public class InnerClassTest extends junit.framework.TestCase {
+        public void testNothing() { }
+
         public class InnerTest extends junit.framework.TestCase {
+          public void testNothing() { }
         }
       }
     JAVA
-    define('foo').test.compile.invoke
+    define('foo').test.invoke
     project('foo').test.tests.should eql(['InnerClassTest'])
   end
 
@@ -263,14 +270,14 @@
     write 'src/test/java/com/example/TestThis.java', 'package com.example; public class TestThis
{}'
     write 'src/test/java/com/example/ThisTest.java', 'package com.example; public class ThisTest
{}'
     define('foo') { test.using(:testng) }
-    project('foo').test.compile.invoke
+    project('foo').test.invoke
     project('foo').test.tests.should include('com.example.TestThis', 'com.example.ThisTest')
   end
 
   it 'should ignore classes not using Test prefix or suffix' do
     write 'src/test/java/NotATestClass.java', 'public class NotATestClass {}'
     define('foo') { test.using(:testng) }
-    project('foo').test.compile.invoke
+    project('foo').test.invoke
     project('foo').test.tests.should be_empty
   end
 
@@ -282,7 +289,7 @@
       }
     JAVA
     define('foo') { test.using(:testng) }
-    project('foo').test.compile.invoke
+    project('foo').test.invoke
     project('foo').test.tests.should eql(['InnerClassTest'])
   end
 

Modified: incubator/buildr/trunk/spec/test_spec.rb
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/spec/test_spec.rb?rev=615324&r1=615323&r2=615324&view=diff
==============================================================================
--- incubator/buildr/trunk/spec/test_spec.rb (original)
+++ incubator/buildr/trunk/spec/test_spec.rb Fri Jan 25 12:15:50 2008
@@ -231,17 +231,14 @@
 
 
 describe Buildr::TestTask, 'with passing tests' do
-  def tests
-    @tests ||= ['PassingTest1', 'PassingTest2']
-  end
-
   def test_task
     @test_task ||= begin
-      tests = self.tests
       define 'foo' do
         test.using(:junit)
-        test.stub!(:tests).and_return(tests.clone)
-        test.instance_eval { @framework.stub!(:run).and_return(tests.clone) }
+        test.instance_eval do
+          @framework.stub!(:tests).and_return(['PassingTest1', 'PassingTest2'])
+          @framework.stub!(:run).and_return(['PassingTest1', 'PassingTest2'])
+        end
       end
       project('foo').test
     end
@@ -257,7 +254,7 @@
   
   it 'should return passed tests' do
     test_task.invoke
-    test_task.passed_tests.should == tests
+    test_task.passed_tests.should == ['PassingTest1', 'PassingTest2']
   end
 
   it 'should return no failed tests' do



Mime
View raw message