Skip to content

Commit ea43e27

Browse files
Workaround to fix flaky LSP test (#977)
The generated identifiers in the IR seem non-deterministic between execution environments: one can observe different names locally vs on the CI. This led to test failures in entirely unrelated PRs (#930, #923). As this is blocking the other PRs, I propose the hotfix contained in this PR. I'm also open to better suggestions on how to write this particular test case or on how to fix the non-determinism.
1 parent 7fc0b8b commit ea43e27

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

effekt/jvm/src/test/scala/effekt/LSPTests.scala

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ class LSPTests extends FunSuite {
2020
//
2121
//
2222

23-
2423
/**
2524
* @param compileOnChange The server currently uses `compileOnChange = false` by default, but we set it to `true` for testing
2625
* because we would like to switch to `didChange` events once we have working caching for references.
@@ -48,8 +47,21 @@ class LSPTests extends FunSuite {
4847
def withClientAndServer(testBlock: (MockLanguageClient, Server) => Unit): Unit = {
4948
withClientAndServer(true)(testBlock)
5049
}
50+
51+
/** Normalize the output of the IR by replacing the generated identifiers and stripping all whitespace
52+
*/
53+
def normalizeIRString(ir: String): String = {
54+
ir.replaceAll("_\\d+", "_whatever")
55+
.replaceAll("\\s+", " ")
56+
}
57+
58+
def assertIREquals(ir: String, expected: String): Unit = {
59+
val normalizedIR = normalizeIRString(ir)
60+
val normalizedExpected = normalizeIRString(expected)
61+
assertEquals(normalizedIR, normalizedExpected)
62+
}
5163

52-
// Fixtures
64+
// Fixtures
5365
//
5466
//
5567

@@ -769,8 +781,7 @@ class LSPTests extends FunSuite {
769781

770782
val receivedIRContent = client.receivedIR()
771783
assertEquals(receivedIRContent.length, 1)
772-
val fixedReceivedIR = receivedIRContent.head.content.replaceAll("Unit_\\d+", "Unit_whatever")
773-
assertEquals(fixedReceivedIR, expectedIRContents)
784+
assertIREquals(receivedIRContent.head.content, expectedIRContents)
774785
}
775786
}
776787

@@ -820,8 +831,7 @@ class LSPTests extends FunSuite {
820831

821832
val receivedIRContent = client.receivedIR()
822833
assertEquals(receivedIRContent.length, 1)
823-
val fixedReceivedIR = receivedIRContent.head.content.replaceAll("Int_\\d+", "Int_whatever").replaceAll("foo_\\d+", "foo_whatever")
824-
assertEquals(fixedReceivedIR, expectedIRContents)
834+
assertIREquals(receivedIRContent.head.content, expectedIRContents)
825835
}
826836
}
827837

0 commit comments

Comments
 (0)