Skip to content

Commit 9e7245d

Browse files
committed
Add classpath test to ScipBuildToolSuite
1 parent 40961fc commit 9e7245d

2 files changed

Lines changed: 37 additions & 0 deletions

File tree

tests/buildTools/src/test/scala/tests/BaseBuildToolSuite.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ abstract class BaseBuildToolSuite extends MopedSuite(ScipJava.app) {
6666
expectedError: Option[String => Unit] = None,
6767
expectedPackages: String = "",
6868
initCommand: => List[String] = Nil,
69+
prepare: () => Unit = () => (),
6970
targetRoot: Option[String] = None,
7071
tools: List[Tool] = Nil
7172
): Unit = {
@@ -97,6 +98,8 @@ abstract class BaseBuildToolSuite extends MopedSuite(ScipJava.app) {
9798

9899
FileLayout.fromString(original, root = workingDirectory)
99100

101+
prepare()
102+
100103
val targetroot = workingDirectory.resolve(
101104
targetRoot.getOrElse("targetroot")
102105
)

tests/buildTools/src/test/scala/tests/ScipBuildToolSuite.scala

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,38 @@ class ScipBuildToolSuite extends BaseBuildToolSuite {
3434
|""".stripMargin,
3535
expectedSemanticdbFiles = 2
3636
)
37+
38+
checkBuild(
39+
"compiles-with-classpath",
40+
"""|/lsif-java.json
41+
|{"classpath": ["lib-classes"]}
42+
|/foo/Example.java
43+
|package foo;
44+
|import bar.Greeter;
45+
|public class Example {
46+
| public String hello() { return new Greeter().greet(); }
47+
|}
48+
|""".stripMargin,
49+
expectedSemanticdbFiles = 1,
50+
prepare = () => {
51+
// Compile a small library to a classes directory inside the working
52+
// directory so the index command resolves `bar.Greeter` via the
53+
// `classpath` field in lsif-java.json. Source lives in a separate temp
54+
// directory to avoid being indexed itself.
55+
val libSrcDir = os.temp.dir(prefix = "scip-classpath-lib")
56+
val libSrc = libSrcDir / "bar" / "Greeter.java"
57+
os.write(
58+
libSrc,
59+
"""|package bar;
60+
|public class Greeter {
61+
| public String greet() { return "hi"; }
62+
|}
63+
|""".stripMargin,
64+
createFolders = true
65+
)
66+
val libClasses = os.Path(workingDirectory) / "lib-classes"
67+
os.makeDir.all(libClasses)
68+
os.proc("javac", "-d", libClasses.toString, libSrc.toString).call()
69+
}
70+
)
3771
}

0 commit comments

Comments
 (0)