Skip to content

Commit 052f671

Browse files
committed
Fix snapshot tests
Previously, the `LibrarySnapshotGenerator` was not working correctly making it impossible to update the snapshots with `snapshots/run`. This commit fixes the issue and updates the snapshots to reflect several versions of scip-java updates.
1 parent d5240e7 commit 052f671

38 files changed

+1108
-1307
lines changed

scip-java/src/main/scala/com/sourcegraph/scip_java/buildtools/ScipBuildTool.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,9 @@ class ScipBuildTool(index: IndexCommand) extends BuildTool("SCIP", index) {
111111
private def generateSemanticdb(): CommandResult = {
112112
parsedConfig match {
113113
case ValueResult(value) =>
114-
clean()
114+
if (index.cleanup) {
115+
clean()
116+
}
115117
try {
116118
compile(value)
117119
} catch {

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

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import com.sourcegraph.io.DeleteVisitor
1313
import com.sourcegraph.scip_java.Dependencies
1414
import com.sourcegraph.scip_semanticdb.JavaVersion
1515
import moped.annotations.DeprecatedName
16+
import moped.annotations.Description
1617
import moped.annotations.Hidden
1718
import moped.cli.Command
1819
import moped.cli.CommandParser
@@ -25,17 +26,20 @@ final case class IndexDependencyCommand(
2526
snapshotCommand: SnapshotCommand = SnapshotCommand(),
2627
dependency: String = "",
2728
provided: List[String] = Nil,
29+
@Description(
30+
"If true, deletes temporary files that are created during indexing"
31+
) cleanup: Boolean = true,
2832
snapshot: Boolean = false
2933
) extends Command {
3034
def app = index.app
3135
private val absoluteTarget = AbsolutePath
3236
.of(output, app.env.workingDirectory)
3337
.resolve(dependency.replace(":", "__"))
3438
private val indexTarget =
35-
if (!snapshot)
36-
absoluteTarget
37-
else
39+
if (snapshot)
3840
Files.createTempDirectory("scip-java-index")
41+
else
42+
absoluteTarget
3943
private val snapshotTarget = absoluteTarget
4044
def run(): Int = {
4145
if (dependency == "") {
@@ -70,12 +74,16 @@ final case class IndexDependencyCommand(
7074
snapshotCommand
7175
.copy(
7276
output = snapshotTarget,
77+
cleanup = cleanup,
78+
targetroot = List(indexTarget),
7379
app = app
7480
.withEnv(app.env.withWorkingDirectory(indexTarget))
7581
)
7682
.run()
7783
} finally {
78-
Files.walkFileTree(indexTarget, new DeleteVisitor())
84+
if (cleanup) {
85+
Files.walkFileTree(indexTarget, new DeleteVisitor())
86+
}
7987
}
8088
} else {
8189
exit
@@ -104,6 +112,7 @@ final case class IndexDependencyCommand(
104112
index
105113
.copy(
106114
buildTool = Some("scip"),
115+
cleanup = cleanup,
107116
app = app.withEnv(app.env.withWorkingDirectory(indexTarget))
108117
)
109118
.run()

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ case class SnapshotCommand(
3131
) targetroot: List[Path] = Nil,
3232
@Description("Output directory for the annotated snapshots") output: Path =
3333
Paths.get("generated"),
34+
cleanup: Boolean = true,
3435
@Inline() app: Application = Application.default
3536
) extends Command {
3637
def sourceroot: Path = app.env.workingDirectory
@@ -39,7 +40,9 @@ case class SnapshotCommand(
3940
val semanticdbPattern = FileSystems
4041
.getDefault
4142
.getPathMatcher("glob:**.semanticdb")
42-
Files.walkFileTree(output, new DeleteVisitor())
43+
if (cleanup) {
44+
Files.walkFileTree(output, new DeleteVisitor())
45+
}
4346
Files.createDirectories(output)
4447
val semanticdbFiles = ListBuffer.empty[TextDocument]
4548

scip-semanticdb/src/main/java/com/sourcegraph/scip_semanticdb/ScipSemanticdb.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,8 @@ private void processTypedDocument(Path path, PackageTable packages) {
120120
Scip.SymbolInformation.Builder tinfo =
121121
Scip.SymbolInformation.newBuilder().setSymbol(typedSymbol(info.getSymbol(), pkg));
122122

123-
for (String overriddenSymbol : info.getOverriddenSymbolsList()) {
123+
for (int i = 0; i < info.getOverriddenSymbolsCount(); i++) {
124+
String overriddenSymbol = info.getOverriddenSymbols(i);
124125
if (isIgnoredOverriddenSymbol(overriddenSymbol)) {
125126
continue;
126127
}

tests/snapshots/src/main/generated/BaseByteRenderer.scala

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,19 @@ import upickle.core.{ArrVisitor, ObjVisitor}
2323
*/
2424
class BaseByteRenderer[T <: upickle.core.ByteOps.Output]
2525
// ^^^^^^^^^^^^^^^^ definition ujson/BaseByteRenderer# class BaseByteRenderer[T <: Output]
26-
// ^^^^^^^^^^^^^^^^ definition ujson/BaseByteRenderer. object BaseByteRenderer
2726
// ^ definition ujson/BaseByteRenderer#[T] T <: Output
2827
// ^^^^^^^ reference upickle/
2928
// ^^^^ reference upickle/core/
3029
// ^^^^^^^ reference upickle/core/ByteOps.
3130
// ^^^^^^ reference upickle/core/ByteOps.Output#
3231
(out: T,
3332
// ^^^ definition ujson/BaseByteRenderer#out. private[this] val out: T
34-
// ^^^ definition ujson/BaseByteRenderer#`<init>`().(out) out: T
3533
// ^ reference ujson/BaseByteRenderer#[T]
3634
indent: Int = -1,
3735
// ^^^^^^ definition ujson/BaseByteRenderer#indent. private[this] val indent: Int
38-
// ^^^^^^ definition ujson/BaseByteRenderer#`<init>`().(indent) default indent: Int
3936
// ^^^ reference scala/Int#
4037
escapeUnicode: Boolean = false) extends JsVisitor[T, T]{
4138
// ^^^^^^^^^^^^^ definition ujson/BaseByteRenderer#escapeUnicode. private[this] val escapeUnicode: Boolean
42-
// ^^^^^^^^^^^^^ definition ujson/BaseByteRenderer#`<init>`().(escapeUnicode) default escapeUnicode: Boolean
4339
// ^^^^^^^ reference scala/Boolean#
4440
// ^^^^^^^^^ reference ujson/JsVisitor#
4541
// ^ reference ujson/BaseByteRenderer#[T]
@@ -69,13 +65,11 @@ class BaseByteRenderer[T <: upickle.core.ByteOps.Output]
6965

7066
private[this] var depth: Int = 0
7167
// ^^^^^ definition ujson/BaseByteRenderer#depth(). private[this] var depth: Int
72-
// ^^^^^ definition ujson/BaseByteRenderer#`depth_=`(). private[this] var depth_=(x$1: Int): Unit
7368
// ^^^ reference scala/Int#
7469

7570

7671
private[this] var commaBuffered = false
7772
// ^^^^^^^^^^^^^ definition ujson/BaseByteRenderer#commaBuffered(). private[this] var commaBuffered: Boolean
78-
// ^^^^^^^^^^^^^ definition ujson/BaseByteRenderer#`commaBuffered_=`(). private[this] var commaBuffered_=(x$1: Boolean): Unit
7973

8074
def flushBuffer() = {
8175
// ^^^^^^^^^^^ definition ujson/BaseByteRenderer#flushBuffer(). def flushBuffer(): Unit

tests/snapshots/src/main/generated/BaseCharRenderer.scala

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,19 @@ import upickle.core.{ArrVisitor, ObjVisitor}
2323
*/
2424
class BaseCharRenderer[T <: upickle.core.CharOps.Output]
2525
// ^^^^^^^^^^^^^^^^ definition ujson/BaseCharRenderer# class BaseCharRenderer[T <: Output]
26-
// ^^^^^^^^^^^^^^^^ definition ujson/BaseCharRenderer. object BaseCharRenderer
2726
// ^ definition ujson/BaseCharRenderer#[T] T <: Output
2827
// ^^^^^^^ reference upickle/
2928
// ^^^^ reference upickle/core/
3029
// ^^^^^^^ reference upickle/core/CharOps.
3130
// ^^^^^^ reference upickle/core/CharOps.Output#
3231
(out: T,
3332
// ^^^ definition ujson/BaseCharRenderer#out. private[this] val out: T
34-
// ^^^ definition ujson/BaseCharRenderer#`<init>`().(out) out: T
3533
// ^ reference ujson/BaseCharRenderer#[T]
3634
indent: Int = -1,
3735
// ^^^^^^ definition ujson/BaseCharRenderer#indent. private[this] val indent: Int
38-
// ^^^^^^ definition ujson/BaseCharRenderer#`<init>`().(indent) default indent: Int
3936
// ^^^ reference scala/Int#
4037
escapeUnicode: Boolean = false) extends JsVisitor[T, T]{
4138
// ^^^^^^^^^^^^^ definition ujson/BaseCharRenderer#escapeUnicode. private[this] val escapeUnicode: Boolean
42-
// ^^^^^^^^^^^^^ definition ujson/BaseCharRenderer#`<init>`().(escapeUnicode) default escapeUnicode: Boolean
4339
// ^^^^^^^ reference scala/Boolean#
4440
// ^^^^^^^^^ reference ujson/JsVisitor#
4541
// ^ reference ujson/BaseCharRenderer#[T]
@@ -69,13 +65,11 @@ class BaseCharRenderer[T <: upickle.core.CharOps.Output]
6965

7066
private[this] var depth: Int = 0
7167
// ^^^^^ definition ujson/BaseCharRenderer#depth(). private[this] var depth: Int
72-
// ^^^^^ definition ujson/BaseCharRenderer#`depth_=`(). private[this] var depth_=(x$1: Int): Unit
7368
// ^^^ reference scala/Int#
7469

7570

7671
private[this] var commaBuffered = false
7772
// ^^^^^^^^^^^^^ definition ujson/BaseCharRenderer#commaBuffered(). private[this] var commaBuffered: Boolean
78-
// ^^^^^^^^^^^^^ definition ujson/BaseCharRenderer#`commaBuffered_=`(). private[this] var commaBuffered_=(x$1: Boolean): Unit
7973

8074
def flushBuffer() = {
8175
// ^^^^^^^^^^^ definition ujson/BaseCharRenderer#flushBuffer(). def flushBuffer(): Unit

0 commit comments

Comments
 (0)