Class: Buildr::Scala::ScalaTest
- Inherits:
-
TestFramework::Java
- Object
- TestFramework::Base
- TestFramework::Java
- Buildr::Scala::ScalaTest
- Defined in:
- lib/buildr/scala/tests.rb
Overview
ScalaTest framework, the default test framework for Scala tests.
Support the following options:
-
:properties – Hash of system properties available to the test case.
-
:environment – Hash of environment variables available to the test case.
-
:java_args – Arguments passed as is to the JVM.
Constant Summary collapse
- VERSION =
'0.9.3'
Instance Attribute Summary collapse
-
#group_excludes ⇒ Object
annotation-based group exclusion.
-
#group_includes ⇒ Object
annotation-based group inclusion.
Attributes inherited from TestFramework::Base
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(test_task, options) ⇒ ScalaTest
constructor
A new instance of ScalaTest.
-
#run(tests, dependencies) ⇒ Object
:nodoc:.
-
#tests(dependencies) ⇒ Object
:nodoc:.
Methods inherited from TestFramework::Base
Constructor Details
#initialize(test_task, options) ⇒ ScalaTest
Returns a new instance of ScalaTest.
109 110 111 112 113 |
# File 'lib/buildr/scala/tests.rb', line 109 def initialize(test_task, ) super @group_includes = [] @group_excludes = [] end |
Instance Attribute Details
#group_excludes ⇒ Object
annotation-based group exclusion
107 108 109 |
# File 'lib/buildr/scala/tests.rb', line 107 def group_excludes @group_excludes end |
#group_includes ⇒ Object
annotation-based group inclusion
104 105 106 |
# File 'lib/buildr/scala/tests.rb', line 104 def group_includes @group_includes end |
Class Method Details
.applies_to?(project) ⇒ Boolean
:nodoc:
91 92 93 |
# File 'lib/buildr/scala/tests.rb', line 91 def applies_to?(project) #:nodoc: project.test.compile.language == :scala end |
.dependencies ⇒ Object
86 87 88 89 |
# File 'lib/buildr/scala/tests.rb', line 86 def dependencies ["org.scalatest:scalatest:jar:#{version}"] + ScalaSpecs.dependencies + ScalaCheck.dependencies + JMock.dependencies end |
Instance Method Details
#run(tests, dependencies) ⇒ Object
:nodoc:
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 |
# File 'lib/buildr/scala/tests.rb', line 122 def run(tests, dependencies) #:nodoc: mkpath task.report_to.to_s success = [] scalatest = tests.select { |t| t !~ /Specs?$/ } specs = tests.select { |t| t =~ /Specs?$/ } # Specs nostacktrace = ([:nostacktrace]) ? "-ns" : "" = { :properties => [:properties], :java_args => [:java_args], :classpath => dependencies} specs.each do |spec| Java.load begin Java::Commands.java(spec, ) rescue => e print e. else success << spec end end # ScalaTest = 'TFGBSAR' # testSucceeded, testFailed, testIgnored, suiteAborted, runStopped, runAborted, runCompleted scalatest.each do |suite| info "ScalaTest #{suite.inspect}" # Use Ant to execute the ScalaTest task, gives us performance and reporting. reportFile = File.join(task.report_to.to_s, "TEST-#{suite}.txt") taskdef = Buildr.artifacts(self.class.dependencies).each(&:invoke).map(&:to_s) Buildr.ant('scalatest') do |ant| ant.taskdef :name=>'scalatest', :classname=>'org.scalatest.tools.ScalaTestTask', :classpath=>taskdef.join(File::PATH_SEPARATOR) ant.scalatest :runpath=>dependencies.join(File::PATH_SEPARATOR) do ant.suite :classname=>suite ant.reporter :type=>'stdout', :config=> ant.reporter :type=>'file', :filename=> reportFile, :config=> ant.includes group_includes.join(" ") if group_includes ant.excludes group_excludes.join(" ") if group_excludes ([:properties] || []).each { |name, value| ant.property :name=>name, :value=>value } end end # Parse for failures, errors, etc. # This is a bit of a pain right now because ScalaTest doesn't flush its # output synchronously before the Ant test finishes so we have to loop # and wait for an indication that the test run was completed. failed = false completed = false wait = 0 while (!completed) do File.open(reportFile, "r") do |input| while (line = input.gets) do failed = (line =~ /(TEST FAILED -)|(RUN STOPPED)|(RUN ABORTED)/) unless failed completed |= (line =~ /Run completed\./) break if (failed || completed) end end wait += 1 break if (failed || wait > 10) unless completed sleep(1) end end success << suite if (completed && !failed) end success end |
#tests(dependencies) ⇒ Object
:nodoc:
115 116 117 118 119 120 |
# File 'lib/buildr/scala/tests.rb', line 115 def tests(dependencies) #:nodoc: suites = filter_classes(dependencies, :interfaces => %w{org.scalatest.Suite}) # we should really filter using :class => %w{org.specs.Specification} instead of naming convention specs = filter_classes(dependencies, :class_names => [/Specs?$/]) [suites, specs].flatten end |