Skip to content

Commit 12c0d14

Browse files
committed
Fix SnapshotCommandSuite to assert SCIP format instead of SemanticDB
1 parent a71fd0a commit 12c0d14

File tree

2 files changed

+33
-9
lines changed

2 files changed

+33
-9
lines changed

scip-java/src/main/scala/com/sourcegraph/scip_java/commands/SnapshotCommand.scala

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ case class SnapshotCommand(
4141
Files.walkFileTree(output, new DeleteVisitor())
4242
}
4343
Files.createDirectories(output)
44+
var foundScipFile = false
4445
targetroot.foreach { root =>
4546
Files.walkFileTree(
4647
root,
@@ -50,6 +51,7 @@ case class SnapshotCommand(
5051
attrs: BasicFileAttributes
5152
): FileVisitResult = {
5253
if (scipPattern.matches(file)) {
54+
foundScipFile = true
5355
val index = Scip.Index.parseFrom(Files.readAllBytes(file))
5456
val root = URI.create(index.getMetadata.getProjectRoot)
5557
index
@@ -77,8 +79,15 @@ case class SnapshotCommand(
7779
}
7880
)
7981
}
80-
81-
0
82+
if (foundScipFile) {
83+
0
84+
} else {
85+
app.error(
86+
s"no SCIP files found. To fix this problem, make sure that one of the directories " +
87+
s"in ${targetroot.mkString(", ")} contains a `*.scip` file."
88+
)
89+
1
90+
}
8291
}
8392
}
8493

tests/unit/src/test/scala/tests/SnapshotCommandSuite.scala

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,22 +28,37 @@ class SnapshotCommandSuite extends MopedSuite(ScipJava.app) {
2828
.compileSemanticdb(List(Input.VirtualFile("main/Sample.java", code)))
2929

3030
val generatedpath = workingDirectory.resolve("generated")
31-
val exitCode = app().run(
31+
32+
val indexExit = app().run(
33+
List(
34+
"index-semanticdb",
35+
"--output",
36+
targetroot.resolve("index.scip").toString,
37+
targetroot.toString
38+
)
39+
)
40+
assertEquals(indexExit, 0, clues(app.capturedOutput))
41+
42+
val snapshotExit = app().run(
3243
List("snapshot", "--output", generatedpath.toString, targetroot.toString)
3344
)
34-
assertEquals(exitCode, 0, clues(app.capturedOutput))
45+
assertEquals(snapshotExit, 0, clues(app.capturedOutput))
3546
assertNoDiff(
3647
FileLayout.asString(generatedpath),
3748
"""|/main/Sample.java
3849
|package main;
3950
|
4051
|public class Sample {
41-
|// ^^^^^^ definition main/Sample# public class Sample
42-
|// ^^^^^^ definition main/Sample#`<init>`(). public Sample()
52+
|// ^^^^^^ definition semanticdb maven . . main/Sample#
53+
|// documentation ```java\npublic class Sample\n```
54+
|// ^^^^^^ definition semanticdb maven . . main/Sample#`<init>`().
55+
|// documentation ```java\npublic Sample()\n```
4356
| public static void main(String[] asdf) {}
44-
|// ^^^^ definition main/Sample#main(). public static void main(String[] asdf)
45-
|// ^^^^^^ reference java/lang/String#
46-
|// ^^^^ definition local0 String[] asdf
57+
|// ^^^^ definition semanticdb maven . . main/Sample#main().
58+
|// documentation ```java\npublic static void main(String[] asdf)\n```
59+
|// ^^^^^^ reference semanticdb maven jdk 11 java/lang/String#
60+
|// ^^^^ definition local 0
61+
|// documentation ```java\nString[] asdf\n```
4762
|}
4863
|""".stripMargin
4964
)

0 commit comments

Comments
 (0)