Skip to content

Commit 4a998c5

Browse files
committed
Correctly detect that a module is test suite
Instead of relying on module name to start with "test" (which is not required neither by UnitTest docs nor by implementation) we now inspect its source code and check if LibPQ UnitTest metadata field is mentioned.
1 parent 809d6dc commit 4a998c5

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

Modules/UnitTest.Discover.pq

+7-2
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,17 @@ let
3333
),
3434
LooksLikeSuiteWithError = (name, object) =>
3535
let
36-
NameLikeTest = Text.StartsWith(name, Config[Test.Prefix], Comparer.OrdinalIgnoreCase),
36+
ModuleFilename = object[Detail][LibPQ][LibPQ.Source], // error record is assumed
37+
Read.Text = LibPQ("Read.Text"),
38+
ModuleSource = Read.Text(ModuleFilename, true),
39+
ModuleIsTestSuite = Text.Contains(ModuleSource, Config[Suite.MetaField]),
3740
ObjLikeError =
3841
Value.Is(object, type record)
3942
and Record.FieldCount(object) = 3
4043
and Record.FieldNames(object) = {"Reason", "Message", "Detail"},
41-
Return = NameLikeTest and ObjLikeError
44+
Return = ObjLikeError and ModuleIsTestSuite // Order matters for short circuiting.
45+
// ModuleIsTestSuite assumes that
46+
// object is an error record
4247
in
4348
Return,
4449
PropagateErrors = (suite) =>

0 commit comments

Comments
 (0)