Skip to content

Commit 8482ec7

Browse files
committed
Propagate errors for badly written test suites
Previously if a module containing the test suite could not be imported without errors such test suite would be invisible to discovery tools. Now import errors are propagated to discovery results if a module looks like a test suite. See: #18
1 parent 44fe2b6 commit 8482ec7

File tree

1 file changed

+31
-7
lines changed

1 file changed

+31
-7
lines changed

Modules/UnitTest.Discover.pq

+31-7
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,30 @@ let
2323
Value.Metadata([Value]),
2424
Config[Suite.MetaField]
2525
)
26-
) otherwise
26+
) otherwise if LooksLikeSuiteWithError([Name], [Value])
27+
then
28+
ErrorSuiteMarker
29+
else
2730
null
2831
),
2932
each [SuiteVersion] <> null
3033
),
34+
LooksLikeSuiteWithError = (name, object) =>
35+
let
36+
NameLikeTest = Text.StartsWith(name, Config[Test.Prefix], Comparer.OrdinalIgnoreCase),
37+
ObjLikeError =
38+
Value.Is(object, type record)
39+
and Record.FieldCount(object) = 3
40+
and Record.FieldNames(object) = {"Reason", "Message", "Detail"},
41+
Return = NameLikeTest and ObjLikeError
42+
in
43+
Return,
44+
PropagateErrors = (suite) =>
45+
#table(
46+
{ "Test", "Result", "Status", "Description"},
47+
{{ null, suite, "ERROR", suite[Reason] & ": " &suite[Message]}}
48+
),
49+
ErrorSuiteMarker = "This looks like a test suite with invalid code",
3150
SuitesValid =
3251
if Table.IsEmpty(SuitesFilter)
3352
then error Error.Record("LibPQ.TestsNotFound", "No tests were found among local modules", null)
@@ -39,13 +58,18 @@ let
3958
{"Suite", "Object", "Version"}
4059
})
4160
),
42-
SuiteRunners = Record.FromList(
43-
List.Transform(
44-
Record.FieldValues(Config[Suite.Runners]),
45-
each LibPQ(_)
61+
SuiteRunners =
62+
Record.AddField(
63+
Record.FromList(
64+
List.Transform(
65+
Record.FieldValues(Config[Suite.Runners]),
66+
each LibPQ(_)
67+
),
68+
Record.FieldNames(Config[Suite.Runners])
69+
),
70+
ErrorSuiteMarker,
71+
PropagateErrors
4672
),
47-
Record.FieldNames(Config[Suite.Runners])
48-
),
4973
Run = Table.AddColumn(
5074
Suites,
5175
"Results",

0 commit comments

Comments
 (0)