| Name | Total Lines | Lines of Code | Total Coverage | Code Coverage |
|---|---|---|---|---|
| lib/buildr/scala/tests.rb | 200 | 136 | 39.50%
|
41.18%
|
Code reported as executed by Ruby looks like this...and this: this line is also marked as covered.Lines considered as run by rcov, but not reported by Ruby, look like this,and this: these lines were inferred by rcov (using simple heuristics).Finally, here's a line marked as not executed.
1 # Licensed to the Apache Software Foundation (ASF) under one or more |
2 # contributor license agreements. See the NOTICE file distributed with this |
3 # work for additional information regarding copyright ownership. The ASF |
4 # licenses this file to you under the Apache License, Version 2.0 (the |
5 # "License"); you may not use this file except in compliance with the License. |
6 # You may obtain a copy of the License at |
7 # |
8 # http://www.apache.org/licenses/LICENSE-2.0 |
9 # |
10 # Unless required by applicable law or agreed to in writing, software |
11 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
12 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
13 # License for the specific language governing permissions and limitations under |
14 # the License. |
15 |
16 |
17 require 'buildr/core/build' |
18 require 'buildr/core/compile' |
19 require 'buildr/java/ant' |
20 require 'buildr/java/tests' |
21 |
22 |
23 module Buildr::Scala |
24 # Scala::Check is available when using Scala::Test or Scala::Specs |
25 module Check |
26 VERSION = case |
27 when Buildr::Scala.version?("2.7") |
28 '1.6' |
29 when Buildr::Scala.version?("2.8.0") |
30 '1.7' |
31 when Buildr::Scala.version?("2.8.1") |
32 '1.8' |
33 else |
34 '1.9' |
35 end |
36 |
37 class << self |
38 def version |
39 Buildr.settings.build['scala.check'] || VERSION |
40 end |
41 |
42 def classifier |
43 Buildr.settings.build['scala.check.classifier'] |
44 end |
45 |
46 def artifact |
47 Buildr.settings.build['scala.check.artifact'] || "scalacheck_#{Buildr::Scala.version_without_build}" |
48 end |
49 |
50 def dependencies |
51 return [version] if (version =~ /:/) |
52 if classifier |
53 ["org.scala-tools.testing:#{artifact}:jar:#{classifier}:#{version}"] |
54 else |
55 ["org.scala-tools.testing:#{artifact}:jar:#{version}"] |
56 end |
57 end |
58 |
59 private |
60 def const_missing(const) |
61 return super unless const == :REQUIRES # TODO: remove in 1.5 |
62 Buildr.application.deprecated "Please use Scala::Check.dependencies/.version instead of ScalaCheck::REQUIRES/VERSION" |
63 dependencies |
64 end |
65 end |
66 end |
67 |
68 |
69 # ScalaTest framework, the default test framework for Scala tests. |
70 # |
71 # Support the following options: |
72 # * :properties -- Hash of system properties available to the test case. |
73 # * :environment -- Hash of environment variables available to the test case. |
74 # * :java_args -- Arguments passed as is to the JVM. |
75 class ScalaTest < Buildr::TestFramework::Java |
76 |
77 VERSION = Buildr::Scala.version?(2.7, 2.8) ? '1.3' : '1.6.1' |
78 |
79 class << self |
80 def version |
81 custom = Buildr.settings.build['scala.test'] |
82 (custom =~ /:/) ? Buildr.artifact(custom).version : VERSION |
83 end |
84 |
85 def specs |
86 custom = Buildr.settings.build['scala.test'] |
87 return custom if (custom =~ /:/) |
88 if Buildr::Scala.version?(2.7, 2.8) |
89 "org.scalatest:scalatest:jar:#{version}" |
90 else |
91 "org.scalatest:scalatest_#{Buildr::Scala.version_without_build}:jar:#{version}" |
92 end |
93 end |
94 |
95 def dependencies |
96 [specs] + Check.dependencies + JMock.dependencies + JUnit.dependencies |
97 end |
98 |
99 def applies_to?(project) #:nodoc: |
100 !Dir[project.path_to(:source, :test, :scala, '**/*.scala')].empty? |
101 end |
102 |
103 private |
104 def const_missing(const) |
105 return super unless const == :REQUIRES # TODO: remove in 1.5 |
106 Buildr.application.deprecated "Please use Scala::Test.dependencies/.version instead of ScalaTest::REQUIRES/VERSION" |
107 dependencies |
108 end |
109 end |
110 |
111 # annotation-based group inclusion |
112 attr_accessor :group_includes |
113 |
114 # annotation-based group exclusion |
115 attr_accessor :group_excludes |
116 |
117 def initialize(test_task, options) |
118 super |
119 @group_includes = [] |
120 @group_excludes = [] |
121 end |
122 |
123 def tests(dependencies) #:nodoc: |
124 filter_classes(dependencies, :interfaces => %w{org.scalatest.Suite}) |
125 end |
126 |
127 def run(scalatest, dependencies) #:nodoc: |
128 mkpath task.report_to.to_s |
129 success = [] |
130 |
131 reporter_options = if (ScalaTest.version =~ /^0\./) |
132 'TFGBSAR' # testSucceeded, testFailed, testIgnored, suiteAborted, runStopped, runAborted, runCompleted |
133 else |
134 '' |
135 end |
136 |
137 scalatest.each do |suite| |
138 info "ScalaTest #{suite.inspect}" |
139 # Use Ant to execute the ScalaTest task, gives us performance and reporting. |
140 reportDir = task.report_to.to_s |
141 reportFile = File.join(reportDir, "TEST-#{suite}.txt") |
142 taskdef = Buildr.artifacts(self.class.dependencies).each(&:invoke).map(&:to_s) |
143 Buildr.ant('scalatest') do |ant| |
144 # ScalaTestTask was deprecated in 1.2, in favor of ScalaTestAntTask |
145 classname = (ScalaTest.version =~ /^1\.[01]/) ? \ |
146 'org.scalatest.tools.ScalaTestTask' : 'org.scalatest.tools.ScalaTestAntTask' |
147 ant.taskdef :name=>'scalatest', :classname=>classname, |
148 :classpath=>taskdef.join(File::PATH_SEPARATOR) |
149 ant.scalatest :runpath=>dependencies.join(File::PATH_SEPARATOR) do |
150 ant.suite :classname=>suite |
151 ant.reporter :type=>'stdout', :config=>reporter_options |
152 ant.reporter :type=>'file', :filename=> reportFile, :config=>reporter_options |
153 ant.reporter :type=>(ScalaTest.version == "1.0") ? "xml" : "junitxml", |
154 :directory=> reportDir, :config=>reporter_options |
155 # TODO: This should be name=>value pairs! |
156 #ant.includes group_includes.join(" ") if group_includes |
157 #ant.excludes group_excludes.join(" ") if group_excludes |
158 (options[:properties] || []).each { |name, value| ant.config :name=>name, :value=>value } |
159 end |
160 end |
161 |
162 # Parse for failures, errors, etc. |
163 # This is a bit of a pain right now because ScalaTest doesn't flush its |
164 # output synchronously before the Ant test finishes so we have to loop |
165 # and wait for an indication that the test run was completed. |
166 failed = false |
167 completed = false |
168 wait = 0 |
169 while (!completed) do |
170 File.open(reportFile, "r") do |input| |
171 while (line = input.gets) do |
172 failed = (line =~ /(TESTS? FAILED)|(RUN STOPPED)|(RUN ABORTED)/) unless failed |
173 completed |= (line =~ /Run completed/) |
174 break if (failed) |
175 end |
176 end |
177 wait += 1 |
178 break if (failed || wait > 10) |
179 unless completed |
180 sleep(1) |
181 end |
182 end |
183 success << suite if (completed && !failed) |
184 end |
185 |
186 success |
187 end # run |
188 |
189 end # ScalaTest |
190 |
191 end |
192 |
193 |
194 # Backwards compatibility stuff. Remove in 1.5. |
195 module Buildr |
196 ScalaCheck = Scala::Check |
197 ScalaTest = Scala::ScalaTest |
198 end |
199 |
200 Buildr::TestFramework << Buildr::Scala::ScalaTest |
Generated on 2011-07-06 23:35:38 -0700 with rcov 0.9.8