Skip to content

Commit 53f8f48

Browse files
committed
Add tests for #111
1 parent 8ee5df3 commit 53f8f48

File tree

2 files changed

+132
-1
lines changed

2 files changed

+132
-1
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
module Main where
2+
3+
import Data.IntMap
4+
import qualified Data.IntMap as IM
5+
6+
main = do
7+
nn (IM.fromList [(0,345),(1,34),(46,345)])
8+
nn (IM.fromList [(0,1)])
9+
nn (IM.fromList [(0,2), (2,4)])
10+
nn (IM.fromList [(0,3)])
11+
12+
nn :: IntMap Int -> IO ()
13+
nn !im = do
14+
if False
15+
then return ()
16+
else do
17+
nnn im
18+
return ()
19+
20+
nnn :: IntMap Int -> IO ()
21+
nnn im = do
22+
const (return ()) im

test/integration-tests/test/adapter.test.ts

Lines changed: 110 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ describe("Debug Adapter Tests", function () {
135135
if (e.body.exitCode == 0)
136136
resolve(e)
137137
else
138-
reject(new Error("Expecting ExitCode 1"))
138+
reject(new Error("Expecting ExitCode 0"))
139139
}))
140140
]);
141141
});
@@ -746,5 +746,114 @@ describe("Debug Adapter Tests", function () {
746746

747747
})
748748
})
749+
750+
describe("Conditional breakpoints (issue #111)", function () {
751+
it("Conditional expression breakpoints", async () => {
752+
let config = mkConfig({
753+
projectRoot: "/data/T111",
754+
entryFile: "T111.hs",
755+
entryPoint: "main",
756+
entryArgs: [],
757+
extraGhcArgs: []
758+
})
759+
760+
const expected = { path: config.projectRoot + "/" + config.entryFile, line: 13 }
761+
762+
await Promise.all([
763+
dc.waitForEvent('initialized').then(event => {
764+
return dc.setBreakpointsRequest({
765+
lines: [ 13 ],
766+
breakpoints: [ { line: 13, condition: "im IM.! 0 == 2" } ],
767+
source: { path: config.entryFile }
768+
});
769+
}).then(response => {
770+
return dc.configurationDoneRequest();
771+
}),
772+
773+
dc.launch(config),
774+
775+
dc.assertStoppedLocation('breakpoint', expected)
776+
]);
777+
778+
// Assert we only stopped when im IM.! 0 == 2 (and not earlier)
779+
const variables = await fetchLocalVars()
780+
const imVar = variables.get('im');
781+
782+
assert.strictEqual(imVar.value, 'Bin');
783+
const imChild = await expandVar(imVar);
784+
const _2Var = await imChild.get("_2");
785+
const _3Var = await imChild.get("_3");
786+
const _2Child = await expandVar(_2Var)
787+
const _3Child = await expandVar(_3Var)
788+
const _2_2Var = await _2Child.get("_2")
789+
const _3_2Var = await _3Child.get("_2")
790+
assert.strictEqual(_2_2Var.value, '2');
791+
assert.strictEqual(_3_2Var.value, '4');
792+
793+
// And doesn't stop again
794+
await dc.continueRequest();
795+
796+
await dc.waitForEvent('exited').then(e => new Promise((resolve, reject) => {
797+
if (e.body.exitCode == 0)
798+
resolve(e)
799+
else
800+
reject(new Error("Expecting ExitCode 0"))
801+
}))
802+
})
803+
804+
it("Hit count breakpoints", async () => {
805+
let config = mkConfig({
806+
projectRoot: "/data/T111",
807+
entryFile: "T111.hs",
808+
entryPoint: "main",
809+
entryArgs: [],
810+
extraGhcArgs: []
811+
})
812+
813+
const expected = { path: config.projectRoot + "/" + config.entryFile, line: 13 }
814+
const ignoreCount = 2 // ignore 2 hits and stop at third
815+
816+
await Promise.all([
817+
dc.waitForEvent('initialized').then(event => {
818+
return dc.setBreakpointsRequest({
819+
lines: [ 13 ],
820+
breakpoints: [ { line: 13, hitCondition: `${ignoreCount}` } ],
821+
source: { path: config.entryFile }
822+
});
823+
}).then(response => {
824+
return dc.configurationDoneRequest();
825+
}),
826+
827+
dc.launch(config),
828+
829+
dc.assertStoppedLocation('breakpoint', expected)
830+
]);
831+
832+
// Assert we only stopped at the 3rd hit
833+
const variables = await fetchLocalVars()
834+
const imVar = variables.get('im');
835+
836+
assert.strictEqual(imVar.value, 'Bin');
837+
const imChild = await expandVar(imVar);
838+
const _2Var = await imChild.get("_2");
839+
const _3Var = await imChild.get("_3");
840+
const _2Child = await expandVar(_2Var)
841+
const _3Child = await expandVar(_3Var)
842+
const _2_2Var = await _2Child.get("_2")
843+
const _3_2Var = await _3Child.get("_2")
844+
assert.strictEqual(_2_2Var.value, '2');
845+
assert.strictEqual(_3_2Var.value, '4');
846+
847+
// And doesn't stop again
848+
await dc.continueRequest();
849+
850+
await dc.waitForEvent('exited').then(e => new Promise((resolve, reject) => {
851+
if (e.body.exitCode == 0)
852+
resolve(e)
853+
else
854+
reject(new Error("Expecting ExitCode 0"))
855+
}))
856+
})
857+
})
749858
})
750859

0 commit comments

Comments
 (0)