Skip to content

Commit d828118

Browse files
authored
Captures output. Refactors entrypoints (#328)
1 parent 9b29e91 commit d828118

File tree

5 files changed

+22
-21
lines changed

5 files changed

+22
-21
lines changed

protocol/types.nim

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,12 +1055,12 @@ type
10551055
tests*: seq[TestInfo]
10561056

10571057
TestProjectInfo* = object
1058-
entryPoints*: seq[string]
1058+
entryPoint*: string
10591059
suites*: Table[string, TestSuiteInfo]
10601060
error*: Option[string]
10611061

10621062
ListTestsParams* = object
1063-
entryPoints*: seq[string] #can be patterns? if empty we could do the same as nimble does or just run `nimble test args`
1063+
entryPoint*: string #can be patterns? if empty we could do the same as nimble does or just run `nimble test args`
10641064

10651065
ListTestsResult* = object
10661066
projectInfo*: TestProjectInfo
@@ -1080,9 +1080,11 @@ type
10801080
testResults*: seq[RunTestResult]
10811081

10821082
RunTestParams* = object
1083-
entryPoints*: seq[string]
1083+
entryPoint*: string
10841084
suiteName*: Option[string] #Optional, if provided, only run tests in the suite. Takes precedence over testName
10851085
testNames*: Option[seq[string]] #Optional, if provided, only run the specific tests
10861086

10871087
RunTestProjectResult* = object
10881088
suites*: seq[RunTestSuiteResult]
1089+
fullOutput*: string
1090+

routes.nim

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -855,9 +855,9 @@ proc listTests*(
855855
let nimPath = config.getNimPath()
856856
if nimPath.isNone:
857857
error "Nim path not found when listing tests"
858-
return ListTestsResult(projectInfo: TestProjectInfo(entryPoints: params.entryPoints, suites: initTable[string, TestSuiteInfo]()))
858+
return ListTestsResult(projectInfo: TestProjectInfo(entryPoint: params.entryPoint, suites: initTable[string, TestSuiteInfo]()))
859859
let workspaceRoot = ls.initializeParams.getRootPath
860-
let testProjectInfo = await listTests(params.entryPoints, nimPath.get(), workspaceRoot)
860+
let testProjectInfo = await listTests(params.entryPoint, nimPath.get(), workspaceRoot)
861861
result.projectInfo = testProjectInfo
862862

863863
proc runTests*(
@@ -869,7 +869,7 @@ proc runTests*(
869869
error "Nim path not found when running tests"
870870
return RunTestProjectResult()
871871
let workspaceRoot = ls.initializeParams.getRootPath
872-
await runTests(params.entryPoints, nimPath.get(), params.suiteName, params.testNames.get(@[]), workspaceRoot)
872+
await runTests(params.entryPoint, nimPath.get(), params.suiteName, params.testNames.get(@[]), workspaceRoot)
873873

874874
#Notifications
875875
proc initialized*(ls: LanguageServer, _: JsonNode): Future[void] {.async.} =

testrunner.nim

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ proc extractTestInfo*(rawOutput: string): TestProjectInfo =
1010
result.suites = initTable[string, TestSuiteInfo]()
1111
let lines = rawOutput.split("\n")
1212
var currentSuite = ""
13-
1413
for i, line in enumerate(lines):
1514
var name, file, ignore: string
1615
var lineNumber: int
@@ -38,12 +37,11 @@ proc getFullPath*(entryPoint: string, workspaceRoot: string): string =
3837
return entryPoint
3938

4039
proc listTests*(
41-
entryPoints: seq[string],
40+
entryPoint: string,
4241
nimPath: string,
4342
workspaceRoot: string
4443
): Future[TestProjectInfo] {.async.} =
45-
assert entryPoints.len == 1
46-
var entryPoint = getFullPath(entryPoints[0], workspaceRoot)
44+
var entryPoint = getFullPath(entryPoint, workspaceRoot)
4745
let process = await startProcess(
4846
nimPath,
4947
arguments = @["c", "-d:unittest2ListTests", "-r", "--listFullPaths", entryPoint],
@@ -94,14 +92,13 @@ proc parseTestResults*(xmlContent: string): RunTestProjectResult =
9492
result.suites.add(suite)
9593

9694
proc runTests*(
97-
entryPoints: seq[string],
95+
entryPoint: string,
9896
nimPath: string,
9997
suiteName: Option[string],
10098
testNames: seq[string],
10199
workspaceRoot: string
102100
): Future[RunTestProjectResult] {.async.} =
103-
assert entryPoints.len == 1
104-
var entryPoint = getFullPath(entryPoints[0], workspaceRoot)
101+
var entryPoint = getFullPath(entryPoint, workspaceRoot)
105102
if not fileExists(entryPoint):
106103
error "Entry point does not exist", entryPoint = entryPoint
107104
return RunTestProjectResult()
@@ -122,8 +119,9 @@ proc runTests*(
122119
)
123120
try:
124121
let res = await process.waitForExit(15.seconds)
122+
let processOutput = string.fromBytes(process.stdoutStream.read().await)
123+
125124
if not fileExists(resultFile):
126-
let processOutput = string.fromBytes(process.stdoutStream.read().await)
127125
let processError = string.fromBytes(process.stderrStream.read().await)
128126
error "Result file does not exist meaning tests were not run"
129127
error "Output from process", output = processOutput
@@ -132,6 +130,7 @@ proc runTests*(
132130
let xmlContent = readFile(resultFile)
133131
# echo "XML CONTENT: ", xmlContent
134132
result = parseTestResults(xmlContent)
133+
result.fullOutput = processOutput
135134
removeFile(resultFile)
136135
except Exception as e:
137136
let processOutput = string.fromBytes(process.stdoutStream.read().await)

tests/textensions.nim

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ suite "Nimlangserver extensions":
8888
}
8989
let initializeResult = waitFor client.initialize(initParams)
9090

91-
let listTestsParams = ListTestsParams(entryPoints: @["tests/projects/testrunner/tests/sampletests.nim".absolutePath])
91+
let listTestsParams = ListTestsParams(entryPoint: "tests/projects/testrunner/tests/sampletests.nim".absolutePath)
9292
let tests = client.call("extension/listTests", jsonutils.toJson(listTestsParams)).waitFor().jsonTo(
9393
ListTestsResult
9494
)
@@ -109,7 +109,7 @@ suite "Nimlangserver extensions":
109109
}
110110
let initializeResult = waitFor client.initialize(initParams)
111111

112-
let runTestsParams = RunTestParams(entryPoints: @["tests/projects/testrunner/tests/sampletests.nim".absolutePath])
112+
let runTestsParams = RunTestParams(entryPoint: "tests/projects/testrunner/tests/sampletests.nim".absolutePath)
113113
let runTestsRes = client.call("extension/runTests", jsonutils.toJson(runTestsParams)).waitFor().jsonTo(
114114
RunTestProjectResult
115115
)
@@ -132,7 +132,7 @@ suite "Nimlangserver extensions":
132132
let initializeResult = waitFor client.initialize(initParams)
133133

134134
let suiteName = "Sample Suite"
135-
let runTestsParams = RunTestParams(entryPoints: @["tests/projects/testrunner/tests/sampletests.nim".absolutePath], suiteName: suiteName)
135+
let runTestsParams = RunTestParams(entryPoint: "tests/projects/testrunner/tests/sampletests.nim".absolutePath, suiteName: some suiteName)
136136
let runTestsRes = client.call("extension/runTests", jsonutils.toJson(runTestsParams)).waitFor().jsonTo(
137137
RunTestProjectResult
138138
)
@@ -152,7 +152,7 @@ suite "Nimlangserver extensions":
152152
let initializeResult = waitFor client.initialize(initParams)
153153

154154
let testName = "Sample Test"
155-
let runTestsParams = RunTestParams(entryPoints: @["tests/projects/testrunner/tests/sampletests.nim".absolutePath], testNames: @[testName])
155+
let runTestsParams = RunTestParams(entryPoint: "tests/projects/testrunner/tests/sampletests.nim".absolutePath, testNames: some @[testName])
156156
let runTestsRes = client.call("extension/runTests", jsonutils.toJson(runTestsParams)).waitFor().jsonTo(RunTestProjectResult)
157157

158158
check runTestsRes.suites.len == 1
@@ -170,7 +170,7 @@ suite "Nimlangserver extensions":
170170
let initializeResult = waitFor client.initialize(initParams)
171171

172172
let testNames = @["Sample Test", "Sample Test 2"]
173-
let runTestsParams = RunTestParams(entryPoints: @["tests/projects/testrunner/tests/sampletests.nim".absolutePath], testNames: testNames)
173+
let runTestsParams = RunTestParams(entryPoint: "tests/projects/testrunner/tests/sampletests.nim".absolutePath, testNames: some testNames)
174174
let runTestsRes = client.call("extension/runTests", jsonutils.toJson(runTestsParams)).waitFor().jsonTo(RunTestProjectResult)
175175

176176
check runTestsRes.suites.len == 1
@@ -187,7 +187,7 @@ suite "Nimlangserver extensions":
187187

188188
let initializeResult = waitFor client.initialize(initParams)
189189

190-
let runTestsParams = RunTestParams(entryPoints: @["tests/projects/testrunner/tests/failingtest.nim".absolutePath])
190+
let runTestsParams = RunTestParams(entryPoint: "tests/projects/testrunner/tests/failingtest.nim".absolutePath)
191191
let runTestsRes = client.call("extension/runTests", jsonutils.toJson(runTestsParams)).waitFor().jsonTo(RunTestProjectResult)
192192

193193
check runTestsRes.suites.len == 1

tests/ttestrunner.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ suite "Test Parser":
3636
suite "Test Runner":
3737
test "should be able to run tests and retrieve results":
3838
let entryPoint = getCurrentDir() / "tests" / "projects" / "testrunner" / "tests" / "sampletests.nim"
39-
let testProjectResult = waitFor runTests(@[entryPoint], "nim", none(string), @[], "")
39+
let testProjectResult = waitFor runTests(entryPoint, "nim", none(string), @[], "")
4040
check testProjectResult.suites.len == 4
4141
check testProjectResult.suites[0].name == "Sample Tests"
4242
check testProjectResult.suites[0].tests == 1

0 commit comments

Comments
 (0)