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 =
case when Buildr::Scala.version?(2.7) '1.3' when Buildr::Scala.version < "2.11" '1.8' else '2.2.6' end
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(scalatest, 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.
136 137 138 139 140 |
# File 'lib/buildr/scala/tests.rb', line 136 def initialize(test_task, ) super @group_includes = [] @group_excludes = [] end |
Instance Attribute Details
#group_excludes ⇒ Object
annotation-based group exclusion
134 135 136 |
# File 'lib/buildr/scala/tests.rb', line 134 def group_excludes @group_excludes end |
#group_includes ⇒ Object
annotation-based group inclusion
131 132 133 |
# File 'lib/buildr/scala/tests.rb', line 131 def group_includes @group_includes end |
Class Method Details
.applies_to?(project) ⇒ Boolean
:nodoc:
125 126 127 |
# File 'lib/buildr/scala/tests.rb', line 125 def applies_to?(project) #:nodoc: !Dir[project.path_to(:source, :test, :scala, '**/*.scala')].empty? end |
.dependencies ⇒ Object
121 122 123 |
# File 'lib/buildr/scala/tests.rb', line 121 def dependencies [specs] + Check.dependencies + JMock.dependencies + JUnit.dependencies + Mockito.dependencies + ["org.scala-lang.modules:scala-xml_2.11:jar:1.0.5"] end |
.specs ⇒ Object
109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/buildr/scala/tests.rb', line 109 def specs custom = Buildr.settings.build['scala.test'] return custom if (custom =~ /:/) if Buildr::Scala.version?(2.7, 2.8) "org.scalatest:scalatest:jar:#{version}" elsif Buildr::Scala.version < "2.11" "org.scalatest:scalatest_#{Buildr::Scala.version_without_build}:jar:#{version}" else "org.scalatest:scalatest_#{Buildr::Scala.version_major_minor}:jar:#{version}" end end |
Instance Method Details
#run(scalatest, dependencies) ⇒ Object
:nodoc:
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 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 |
# File 'lib/buildr/scala/tests.rb', line 146 def run(scalatest, dependencies) #:nodoc: mkpath task.report_to.to_s success = [] = if (ScalaTest.version =~ /^0\./) 'TFGBSAR' # testSucceeded, testFailed, testIgnored, suiteAborted, runStopped, runAborted, runCompleted else '' end scalatest.each do |suite| info "ScalaTest #{suite.inspect}" # Use Ant to execute the ScalaTest task, gives us performance and reporting. reportDir = task.report_to.to_s reportFile = File.join(reportDir, "TEST-#{suite}.txt") taskdef = Buildr.artifacts(self.class.dependencies).each(&:invoke).map(&:to_s) Buildr.ant('scalatest') do |ant| # ScalaTestTask was deprecated in 1.2, in favor of ScalaTestAntTask classname = (ScalaTest.version =~ /^1\.[01]/) ? \ 'org.scalatest.tools.ScalaTestTask' : 'org.scalatest.tools.ScalaTestAntTask' ant.taskdef :name=>'scalatest', :classname=>classname, :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.reporter :type=>(ScalaTest.version == "1.0") ? "xml" : "junitxml", :directory=> reportDir, :config=> # TODO: This should be name=>value pairs! #ant.includes group_includes.join(" ") if group_includes #ant.excludes group_excludes.join(" ") if group_excludes ([:properties] || []).each { |name, value| ant.config :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 =~ /(TESTS? FAILED)|(RUN STOPPED)|(RUN ABORTED)/) unless failed completed |= (line =~ /Run completed/) break if (failed) 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:
142 143 144 |
# File 'lib/buildr/scala/tests.rb', line 142 def tests(dependencies) #:nodoc: filter_classes(dependencies, :interfaces => %w{org.scalatest.Suite}) end |