@@ -7,35 +7,66 @@ package nest
7
7
8
8
import scala .tools .nsc .util .ClassPath
9
9
import scala .tools .nsc .io .{ Path , File , Directory }
10
+ import scala .tools .nsc .Properties .{ propOrElse , propOrNone }
10
11
import Path ._
11
12
13
+ /** Get current value for path settings -- these depend on the mutable `testSourcePath`.
14
+ * Default values are read from system properties `partest.srcdir` and `partest.root`.
15
+ *
16
+ * TODO: make `testSourcePath` immutable, but that's pretty involved as a lot of stuff depends on it (all the more reason to refactor)
17
+ * (we don't use system properties to configure partest internally,
18
+ * as their behavior depends on the security policy in place -- e.g., ant does not allow overwriting properties)
19
+ *
20
+ * NOTE: the members are methods because `testSourcePath` changes.
21
+ */
12
22
object PathSettings {
13
- import PartestDefaults .{ testRootDir , srcDirName }
23
+ private [this ] var myTestSourcePath : String = null
24
+ private def defaultSrcDirName = propOrElse(" partest.srcdir" , " files" )
25
+
26
+ /** testSourcePath determines where we look for tests, relative to the `testRoot`
27
+ * after it's been read, it cannot be changed
28
+ */
29
+ def testSourcePath : String = {
30
+ if (myTestSourcePath eq null ) myTestSourcePath = defaultSrcDirName
31
+ myTestSourcePath
32
+ }
33
+
34
+ /** testSourcePath determines where we look for tests, relative to the `testRoot`
35
+ * it can be set only if it hasn't been read yet
36
+ */
37
+ def testSourcePath_= (path : String ): Unit = {
38
+ // assert(myTestSourcePath eq null, "Test Source Path set after use.")
39
+ myTestSourcePath = path
40
+ }
41
+
42
+ // defaults can be set using the environment, but note PathSettings is mutable
43
+ private def defaultTestRootName = propOrNone(" partest.root" )
14
44
15
45
private def cwd = Directory .Current getOrElse sys.error(" user.dir property not set" )
16
- private def isPartestDir (d : Directory ) = (d.name == " test" ) && (d / srcDirName isDirectory)
46
+ private def isPartestDir (d : Directory ) = (d.name == " test" ) && (d / testSourcePath isDirectory)
17
47
private def findJar (name : String , ds : Directory * ): Either [String , File ] =
18
48
ds.toStream flatMap (_.files) filter (_ hasExtension " jar" ) find ( _.name startsWith name ) map (Right (_)) getOrElse
19
49
Left (s " ' ${name}.jar' not found in ' ${ds map (_.path) mkString " , " }'. " )
20
50
21
51
// Directory <root>/test
22
- lazy val testRoot : Directory = testRootDir getOrElse {
52
+ def testRoot : Directory = (defaultTestRootName map ( Directory (_))) getOrElse {
23
53
val candidates : List [Directory ] = (cwd :: cwd.parents) flatMap (d => List (d, Directory (d / " test" )))
24
54
25
55
candidates find isPartestDir getOrElse sys.error(" Directory 'test' not found." )
26
56
}
57
+ def testParent = testRoot.parent
27
58
28
59
// Directory <root>/test/files or .../scaladoc
29
- lazy val srcDir = Directory (testRoot / srcDirName toCanonical)
60
+ def srcDir = Directory (testRoot / testSourcePath toCanonical)
30
61
31
62
// Directory <root>/build/pack/lib
32
- lazy val buildPackLibDir = Directory (buildDir / " pack" / " lib" )
63
+ private def buildPackLibDir = Directory (buildDir / " pack" / " lib" )
33
64
34
65
// Directory <root>/test/files/lib
35
- lazy val srcLibDir = Directory (srcDir / " lib" )
66
+ private def srcLibDir = Directory (srcDir / " lib" )
36
67
37
68
// Directory <root>/build
38
- lazy val buildDir : Directory = {
69
+ private def buildDir : Directory = {
39
70
val bases = testRoot :: testRoot.parents
40
71
// In the classic "ant" build, the relevant subdirectory is called build,
41
72
// but in the postmodern "sbt" build, it is called target. Look for both.
@@ -44,19 +75,10 @@ object PathSettings {
44
75
dirs.headOption getOrElse sys.error(" Neither 'build' nor 'target' dir found under test root " + testRoot + " ." )
45
76
}
46
77
47
-
48
- lazy val srcSpecLib = findJar(" instrumented" , Directory (srcDir / " speclib" ))
49
- lazy val srcCodeLib = findJar(" code" , Directory (srcDir / " codelib" ), Directory (testRoot / " files" / " codelib" ) /* work with --srcpath pending */ )
50
- lazy val agentLib = findJar(" scala-partest-javaagent" , buildPackLibDir)
51
- lazy val scalaCheck = findJar(" scalacheck" , buildPackLibDir, srcLibDir)
52
- lazy val testInterface = findJar(" test-interface" , buildPackLibDir, srcLibDir)
53
- lazy val diffUtils = findJar(" diffutils" , buildPackLibDir)
54
-
55
- /** The platform-specific support jar, `tools.jar`.
56
- */
57
- lazy val platformTools = PathResolver .SupplementalLocations .platformTools
58
- }
59
-
60
- class PathSettings () {
61
- // def classpathAsURLs: List[URL]
78
+ def srcSpecLib = findJar(" instrumented" , Directory (srcDir / " speclib" ))
79
+ def srcCodeLib = findJar(" code" , Directory (srcDir / " codelib" ), Directory (testRoot / " files" / " codelib" ) /* work with --srcpath pending */ )
80
+ def agentLib = findJar(" scala-partest-javaagent" , buildPackLibDir)
81
+ def scalaCheck = findJar(" scalacheck" , buildPackLibDir, srcLibDir)
82
+ def testInterface = findJar(" test-interface" , buildPackLibDir, srcLibDir)
83
+ def diffUtils = findJar(" diffutils" , buildPackLibDir)
62
84
}
0 commit comments