lawspec 0.23.0 → 0.25.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +167 -1
- package/README.md +29 -22
- package/UNICODE-LICENSE.txt +39 -0
- package/api.mjs +14 -23
- package/bin/lawspec.mjs +200 -67
- package/build.json +381 -155
- package/builtin-data-names.mjs +73 -0
- package/compatibility.json +21 -0
- package/core.wasm +2 -2
- package/doctor.mjs +98 -1
- package/examples/native-payments/clojure/lawspec.json +62 -0
- package/examples/native-payments/clojure/src/domain/payments.clj +11 -0
- package/examples/native-payments/clojure/test/domain/payment_generators.clj +9 -0
- package/examples/native-payments/csharp/lawspec.json +13 -2
- package/examples/native-payments/elixir/lawspec.json +14 -3
- package/examples/native-payments/erlang/lawspec.json +14 -3
- package/examples/native-payments/fsharp/lawspec.json +14 -3
- package/examples/native-payments/gleam/lawspec.json +14 -3
- package/examples/native-payments/go/lawspec.json +14 -3
- package/examples/native-payments/groovy/lawspec.json +176 -0
- package/examples/native-payments/groovy/src/main/groovy/domain/PaymentsDomain.groovy +49 -0
- package/examples/native-payments/groovy/src/test/groovy/domain/PaymentGenerators.groovy +15 -0
- package/examples/native-payments/haskell/lawspec.json +14 -3
- package/examples/native-payments/java/lawspec.json +14 -3
- package/examples/native-payments/javascript/lawspec.json +14 -3
- package/examples/native-payments/kotlin/lawspec.json +14 -3
- package/examples/native-payments/python/lawspec.json +14 -3
- package/examples/native-payments/rust/lawspec.json +14 -3
- package/examples/native-payments/scala/lawspec.json +176 -0
- package/examples/native-payments/scala/src/main/scala/domain/PaymentsDomain.scala +18 -0
- package/examples/native-payments/scala/src/test/scala/domain/PaymentGenerators.scala +8 -0
- package/examples/native-payments/swift/lawspec.json +165 -0
- package/examples/native-payments/swift/src/Native/PaymentsDomain.swift +35 -0
- package/examples/native-payments/swift/tests/Native/PaymentGenerators.swift +12 -0
- package/examples/native-payments/typescript/lawspec.json +14 -3
- package/examples/packages/orders/lawspec.json +25 -5
- package/examples/packages/orders/orders.lawspec +36 -34
- package/examples/packages/shop-domain/src/domain.lawspec +23 -21
- package/examples/packages/shop-tax-1/src/rates.lawspec +4 -4
- package/examples/packages/shop-tax-2/src/rates.lawspec +5 -4
- package/examples/rc1/authorization-snapshots.lawspec +112 -0
- package/examples/rc1/banner-filenames.lawspec +63 -0
- package/examples/rc1/bit-codec.lawspec +56 -0
- package/examples/rc1/bounded-witness-search.lawspec +144 -0
- package/examples/rc1/conflicting-requirements.lawspec +30 -0
- package/examples/rc1/constructive-witnesses.lawspec +113 -0
- package/examples/rc1/documentary-review.lawspec +42 -0
- package/examples/rc1/empty-domains.lawspec +46 -0
- package/examples/rc1/finite-integer-domains.lawspec +75 -0
- package/examples/rc1/law-metadata.lawspec +29 -0
- package/examples/rc1/native-payments.lawspec +107 -0
- package/examples/rc1/nesting/rrr.lawspec +33 -0
- package/examples/rc1/nesting/rru.lawspec +56 -0
- package/examples/rc1/nesting/rur.lawspec +57 -0
- package/examples/rc1/nesting/ruu.lawspec +77 -0
- package/examples/rc1/nesting/urr.lawspec +52 -0
- package/examples/rc1/nesting/uru.lawspec +72 -0
- package/examples/rc1/nesting/uur.lawspec +73 -0
- package/examples/rc1/nesting/uuu.lawspec +95 -0
- package/examples/rc1/order-workflow.lawspec +126 -0
- package/examples/rc1/parcel-measurements.lawspec +92 -0
- package/examples/rc1/picture-records.lawspec +51 -0
- package/examples/rc1/picture-tuples.lawspec +47 -0
- package/examples/rc1/record-payloads.lawspec +56 -0
- package/examples/rc1/recursive-records.lawspec +64 -0
- package/examples/rc1/refund-conformance.lawspec +44 -0
- package/examples/rc1/refund-policy.lawspec +88 -0
- package/examples/rc1/requirement-composition.lawspec +89 -0
- package/examples/rc1/structural-records.lawspec +53 -0
- package/examples/rc1-authoring.lawspec +56 -0
- package/examples-command.mjs +11 -5
- package/explain.mjs +112 -0
- package/expression-presentation.mjs +333 -0
- package/files.mjs +16 -0
- package/index.d.ts +934 -12
- package/lsp.mjs +231 -0
- package/migrate.mjs +135 -0
- package/migration-bindings.mjs +86 -0
- package/migration-cases.mjs +45 -0
- package/migration-collections.mjs +54 -0
- package/migration-correspondence.mjs +275 -0
- package/migration-generation.mjs +99 -0
- package/migration-laws.mjs +102 -0
- package/migration-records.mjs +166 -0
- package/migration-source.mjs +247 -0
- package/migration-write.mjs +156 -0
- package/native-evidence.mjs +187 -0
- package/native-examples.mjs +8 -1
- package/node-events-reporter.mjs +23 -0
- package/package.json +8 -1
- package/positional-fields.mjs +13 -0
- package/proof.d.ts +35 -0
- package/proof.mjs +174 -0
- package/scala-coverage.mjs +56 -0
- package/starter-rc1.lawspec +25 -0
- package/templates.mjs +65 -3
- package/test-command.mjs +177 -29
- package/typed-presentation.mjs +165 -0
package/templates.mjs
CHANGED
|
@@ -14,7 +14,11 @@ export const targets = [
|
|
|
14
14
|
"elixir",
|
|
15
15
|
"gleam",
|
|
16
16
|
"fsharp",
|
|
17
|
-
"csharp"
|
|
17
|
+
"csharp",
|
|
18
|
+
"scala",
|
|
19
|
+
"groovy",
|
|
20
|
+
"clojure",
|
|
21
|
+
"swift"
|
|
18
22
|
];
|
|
19
23
|
export const targetLabels = [
|
|
20
24
|
[
|
|
@@ -68,6 +72,22 @@ export const targetLabels = [
|
|
|
68
72
|
[
|
|
69
73
|
"csharp",
|
|
70
74
|
"C#"
|
|
75
|
+
],
|
|
76
|
+
[
|
|
77
|
+
"scala",
|
|
78
|
+
"Scala"
|
|
79
|
+
],
|
|
80
|
+
[
|
|
81
|
+
"groovy",
|
|
82
|
+
"Groovy"
|
|
83
|
+
],
|
|
84
|
+
[
|
|
85
|
+
"clojure",
|
|
86
|
+
"Clojure"
|
|
87
|
+
],
|
|
88
|
+
[
|
|
89
|
+
"swift",
|
|
90
|
+
"Swift"
|
|
71
91
|
]
|
|
72
92
|
];
|
|
73
93
|
|
|
@@ -84,7 +104,11 @@ export const commands = {
|
|
|
84
104
|
"elixir": "mix test",
|
|
85
105
|
"gleam": "gleam test",
|
|
86
106
|
"fsharp": "dotnet test",
|
|
87
|
-
"csharp": "dotnet test"
|
|
107
|
+
"csharp": "dotnet test",
|
|
108
|
+
"scala": "scala test .",
|
|
109
|
+
"groovy": "gradle test",
|
|
110
|
+
"clojure": "clojure -M:test",
|
|
111
|
+
"swift": "swift test"
|
|
88
112
|
};
|
|
89
113
|
|
|
90
114
|
export const setup = {
|
|
@@ -100,7 +124,11 @@ export const setup = {
|
|
|
100
124
|
"elixir": "Use Erlang/OTP 29, Elixir 1.20.x and StreamData 1.4.0 as a direct Hex test dependency. Run mix deps.get and MIX_ENV=test mix deps.compile. In MIX_ENV=test include src and test/support in erlc_paths, and lib and test/support in elixirc_paths. Add LawSpec.Beam.ExUnitFormatter to ExUnit's formatters in test/test_helper.exs and use unfiltered discovery. Run mix test. Programs importing lawspec.crypto or lawspec.network need OTP's post-quantum crypto support and a Unix C toolchain (WSL on Windows). Install OpenSSL 3.5+ development headers with the same major version as OTP, then run escript lawspec_crypto_build.escript before compiling. The builder uses pkg-config or Homebrew; LAWSPEC_OPENSSL_PREFIX overrides the installation. Ship the compiled priv directory with the application.",
|
|
101
125
|
"gleam": "Use Erlang/OTP 29, Gleam 1.18 or 1.19, gleam_stdlib 1.0.5, gleeunit 1.11.0 and qcheck 1.0.5. Select target=erlang, src/test directories, and the lawspec_test_support development dependency at ./test-support. In test/<package>_test.gleam use @external(erlang, \"lawspec_beam_test_run\", \"gleam_main\") pub fn main() -> Nil. Prepare dependencies with gleam build, then run gleam test. Programs importing lawspec.crypto or lawspec.network need OTP's post-quantum crypto support and a Unix C toolchain (WSL on Windows). Install OpenSSL 3.5+ development headers with the same major version as OTP, then run escript lawspec_crypto_build.escript before compiling. The builder uses pkg-config or Homebrew; LAWSPEC_OPENSSL_PREFIX overrides the installation. Ship the compiled priv directory with the application.",
|
|
102
126
|
"fsharp": "Use the .NET 10 SDK (10.0.100 or later) with F# 10. dotnet test runs on Microsoft.Testing.Platform (global.json opts in) with xunit.v3 4.0.2; the generated runtime projects under lawspec/ use FSharp.Core from the SDK, LawSpec.Testing runs properties on FsCheck 3.4.0 and, for a program that imports lawspec.crypto or lawspec.network, BouncyCastle.Cryptography 2.7.0. Import src/LawSpec.Sources.props and tests/LawSpec.Tests.props in the project files, as lawspec init does. Run dotnet build.",
|
|
103
|
-
"csharp": "Use the .NET 10 SDK (10.0.100 or later); the LawSpec runtime is F# and builds with the SDK's F# compiler. dotnet test runs on Microsoft.Testing.Platform (global.json opts in) with xunit.v3 4.0.2 and FsCheck 3.4.0 (referenced by lawspec/LawSpec.Testing); for a program that imports lawspec.crypto or lawspec.network the runtime also uses BouncyCastle.Cryptography 2.7.0. Reference lawspec/LawSpec.Runtime from the source project and lawspec/LawSpec.Testing from the test project, as lawspec init does. Run dotnet build."
|
|
127
|
+
"csharp": "Use the .NET 10 SDK (10.0.100 or later); the LawSpec runtime is F# and builds with the SDK's F# compiler. dotnet test runs on Microsoft.Testing.Platform (global.json opts in) with xunit.v3 4.0.2 and FsCheck 3.4.0 (referenced by lawspec/LawSpec.Testing); for a program that imports lawspec.crypto or lawspec.network the runtime also uses BouncyCastle.Cryptography 2.7.0. Reference lawspec/LawSpec.Runtime from the source project and lawspec/LawSpec.Testing from the test project, as lawspec init does. Run dotnet build.",
|
|
128
|
+
"scala": "Use JDK 25 and Scala CLI 1.16 (the scala command), with Scala 3.9.0, ScalaCheck 1.20.0 and ScalaTest 3.2.20 (scalatest-funsuite) as test dependencies in project.scala; a program that imports lawspec.crypto or lawspec.network also needs Bouncy Castle bcprov-jdk18on 1.86. Run scala compile --test .",
|
|
129
|
+
"groovy": "Use JDK 25, Gradle 9.3.0 with the groovy plugin, Groovy 5.0.8 (org.apache.groovy:groovy), Spock 2.5-groovy-5.0, JetCheck 0.3.0 and JUnit Jupiter's API 5.14.0, and useJUnitPlatform(); the Java model compiles jointly with the Groovy sources, so src/main/java and src/test/java are Groovy source directories. A program that imports lawspec.crypto or lawspec.network also needs Bouncy Castle bcprov-jdk18on 1.86. Run gradle testClasses.",
|
|
130
|
+
"clojure": "Use JDK 25 and the Clojure CLI 1.12 with Clojure 1.12.5 and, for tests, test.check 1.1.3 (the :test alias). The Java model in java/src compiles with the JDK's compiler into target/classes, which lawspec.build does before the tests run (clojure -M:build compiles it alone). A program that imports lawspec.crypto or lawspec.network also needs Bouncy Castle bcprov-jdk18on 1.86. Run clojure -M:test.",
|
|
131
|
+
"swift": "Use Swift 6.2 or later (Xcode 26 on macOS 26, where CryptoKit has ML-KEM and ML-DSA) and SwiftPM. The generated runtime and test support are local targets under lawspec/ with no package dependencies; tests run on Swift Testing, from the toolchain, with LawSpec's own property engine. Package.swift declares the targets LawSpecRuntime, LawSpecTesting, App (src) and AppTests (tests), as lawspec init writes it. Run swift build --build-tests."
|
|
104
132
|
};
|
|
105
133
|
|
|
106
134
|
// Each target's build files in the readable and the compact (minified) layout.
|
|
@@ -240,6 +268,40 @@ const scaffolds = {
|
|
|
240
268
|
"src/Example.csproj": "<Project Sdk=\"Microsoft.NET.Sdk\">\n<PropertyGroup>\n<TargetFramework>net10.0</TargetFramework>\n<RootNamespace>Example</RootNamespace>\n<Nullable>disable</Nullable>\n</PropertyGroup>\n<Import Project=\"LawSpec.Sources.props\" />\n<ItemGroup>\n<ProjectReference Include=\"../lawspec/LawSpec.Runtime/LawSpec.Runtime.fsproj\" />\n</ItemGroup>\n</Project>\n",
|
|
241
269
|
"tests/Example.Tests.csproj": "<Project Sdk=\"Microsoft.NET.Sdk\">\n<PropertyGroup>\n<TargetFramework>net10.0</TargetFramework>\n<OutputType>Exe</OutputType>\n<IsPackable>false</IsPackable>\n<IsTestProject>true</IsTestProject>\n<Nullable>disable</Nullable>\n</PropertyGroup>\n<Import Project=\"LawSpec.Tests.props\" />\n<ItemGroup>\n<ProjectReference Include=\"../src/Example.csproj\" />\n<ProjectReference Include=\"../lawspec/LawSpec.Testing/LawSpec.Testing.fsproj\" />\n<PackageReference Include=\"xunit.v3\" Version=\"4.0.2\" />\n</ItemGroup>\n</Project>\n"
|
|
242
270
|
}
|
|
271
|
+
},
|
|
272
|
+
"scala": {
|
|
273
|
+
"readable": {
|
|
274
|
+
"project.scala": "// The build, for Scala CLI (the scala command): scala test .\n//> using scala 3.9.0\n//> using options -deprecation -feature\n//> using javaOpt --sun-misc-unsafe-memory-access=allow\n//> using test.dep org.scalacheck::scalacheck:1.20.0\n//> using test.dep org.scalatest::scalatest-funsuite:3.2.20\n"
|
|
275
|
+
},
|
|
276
|
+
"compact": {
|
|
277
|
+
"project.scala": "// The build, for Scala CLI (the scala command): scala test .\n//> using scala 3.9.0\n//> using options -deprecation -feature\n//> using javaOpt --sun-misc-unsafe-memory-access=allow\n//> using test.dep org.scalacheck::scalacheck:1.20.0\n//> using test.dep org.scalatest::scalatest-funsuite:3.2.20\n"
|
|
278
|
+
}
|
|
279
|
+
},
|
|
280
|
+
"groovy": {
|
|
281
|
+
"readable": {
|
|
282
|
+
"settings.gradle": "rootProject.name = 'lawspec-example'\n",
|
|
283
|
+
"build.gradle": "plugins {\n id 'groovy'\n}\n\nrepositories {\n mavenCentral()\n}\n\njava {\n toolchain { languageVersion = JavaLanguageVersion.of(25) }\n}\n\nsourceSets {\n main { java { srcDirs = [] }; groovy { srcDirs = ['src/main/groovy', 'src/main/java'] } }\n test { java { srcDirs = [] }; groovy { srcDirs = ['src/test/groovy', 'src/test/java'] } }\n}\n\ntasks.withType(org.gradle.api.tasks.compile.GroovyCompile).configureEach {\n groovyOptions.forkOptions.memoryMaximumSize = '2g'\n}\n\ndependencies {\n implementation 'org.apache.groovy:groovy:5.0.8'\n testImplementation platform('org.spockframework:spock-bom:2.5-groovy-5.0')\n testImplementation 'org.spockframework:spock-core'\n testImplementation 'org.jetbrains:jetCheck:0.3.0'\n testImplementation 'org.junit.jupiter:junit-jupiter-api:5.14.0'\n testRuntimeOnly 'org.junit.platform:junit-platform-launcher'\n}\n\ntest {\n useJUnitPlatform()\n}\n"
|
|
284
|
+
},
|
|
285
|
+
"compact": {
|
|
286
|
+
"settings.gradle": "rootProject.name = 'lawspec-example'\n",
|
|
287
|
+
"build.gradle": "plugins { id 'groovy' }\nrepositories { mavenCentral() }\njava { toolchain { languageVersion = JavaLanguageVersion.of(25) } }\nsourceSets { main { java { srcDirs = [] }; groovy { srcDirs = ['src/main/groovy', 'src/main/java'] } }; test { java { srcDirs = [] }; groovy { srcDirs = ['src/test/groovy', 'src/test/java'] } } }\ntasks.withType(org.gradle.api.tasks.compile.GroovyCompile).configureEach { groovyOptions.forkOptions.memoryMaximumSize = '2g' }\ndependencies { implementation 'org.apache.groovy:groovy:5.0.8'; testImplementation platform('org.spockframework:spock-bom:2.5-groovy-5.0'); testImplementation 'org.spockframework:spock-core'; testImplementation 'org.jetbrains:jetCheck:0.3.0'; testImplementation 'org.junit.jupiter:junit-jupiter-api:5.14.0'; testRuntimeOnly 'org.junit.platform:junit-platform-launcher' }\ntest { useJUnitPlatform() }\n"
|
|
288
|
+
}
|
|
289
|
+
},
|
|
290
|
+
"clojure": {
|
|
291
|
+
"readable": {
|
|
292
|
+
"deps.edn": "{:paths [\"src\" \"target/classes\"]\n :deps {org.clojure/clojure {:mvn/version \"1.12.5\"}}\n :aliases\n {:test {:extra-paths [\"test\" \"target/test-classes\"]\n :extra-deps {org.clojure/test.check {:mvn/version \"1.1.3\"}}\n :main-opts [\"-m\" \"lawspec.test-runner\"]}\n :build {:main-opts [\"-m\" \"lawspec.build\"]}}}\n"
|
|
293
|
+
},
|
|
294
|
+
"compact": {
|
|
295
|
+
"deps.edn": "{:paths [\"src\" \"target/classes\"]\n :deps {org.clojure/clojure {:mvn/version \"1.12.5\"}}\n :aliases\n {:test {:extra-paths [\"test\" \"target/test-classes\"]\n :extra-deps {org.clojure/test.check {:mvn/version \"1.1.3\"}}\n :main-opts [\"-m\" \"lawspec.test-runner\"]}\n :build {:main-opts [\"-m\" \"lawspec.build\"]}}}\n"
|
|
296
|
+
}
|
|
297
|
+
},
|
|
298
|
+
"swift": {
|
|
299
|
+
"readable": {
|
|
300
|
+
"Package.swift": "// swift-tools-version: 6.2\nimport PackageDescription\n\nlet package = Package(\n name: \"Example\",\n platforms: [.macOS(.v26)],\n targets: [\n .target(name: \"LawSpecRuntime\", path: \"lawspec/LawSpecRuntime\"),\n .target(name: \"LawSpecTesting\", dependencies: [\"LawSpecRuntime\"], path: \"lawspec/LawSpecTesting\"),\n .target(name: \"App\", dependencies: [\"LawSpecRuntime\"], path: \"src\"),\n .testTarget(name: \"AppTests\", dependencies: [\"App\", \"LawSpecRuntime\", \"LawSpecTesting\"], path: \"tests\"),\n ]\n)\n"
|
|
301
|
+
},
|
|
302
|
+
"compact": {
|
|
303
|
+
"Package.swift": "// swift-tools-version: 6.2\nimport PackageDescription\nlet package = Package(\n name: \"Example\",\n platforms: [.macOS(.v26)],\n targets: [\n .target(name: \"LawSpecRuntime\", path: \"lawspec/LawSpecRuntime\"),\n .target(name: \"LawSpecTesting\", dependencies: [\"LawSpecRuntime\"], path: \"lawspec/LawSpecTesting\"),\n .target(name: \"App\", dependencies: [\"LawSpecRuntime\"], path: \"src\"),\n .testTarget(name: \"AppTests\", dependencies: [\"App\", \"LawSpecRuntime\", \"LawSpecTesting\"], path: \"tests\"),\n ]\n)\n"
|
|
304
|
+
}
|
|
243
305
|
}
|
|
244
306
|
};
|
|
245
307
|
|
package/test-command.mjs
CHANGED
|
@@ -15,13 +15,14 @@ import path from "node:path";
|
|
|
15
15
|
|
|
16
16
|
// Folders that hold dependencies, build output or caches, not code under test.
|
|
17
17
|
const skipped = new Set([".git", ".lawspec", "node_modules", "dist", "build", "target", "out", ".gradle", "bin", "obj", "TestResults",
|
|
18
|
-
".stack-work", "_build", "deps", ".elixir_ls", "__pycache__", ".hypothesis", ".pytest_cache", ".venv", "venv", ".idea", ".vscode"
|
|
18
|
+
".stack-work", "_build", "deps", ".elixir_ls", "__pycache__", ".hypothesis", ".pytest_cache", ".venv", "venv", ".idea", ".vscode",
|
|
19
|
+
".scala-build", ".bsp", ".bloop", ".metals", ".build", ".swiftpm"]);
|
|
19
20
|
// Build and lock files, which choose the toolchain and dependencies.
|
|
20
21
|
const environmentFiles = ["package.json", "package-lock.json", "tsconfig.json", "pyproject.toml", "go.mod",
|
|
21
22
|
"go.sum", "pom.xml", "build.gradle", "build.gradle.kts", "settings.gradle", "settings.gradle.kts",
|
|
22
23
|
"Cargo.toml", "Cargo.lock", "stack.yaml", "stack.yaml.lock", "package.yaml",
|
|
23
24
|
"rebar.config", "rebar.config.script", "rebar.lock", "mix.exs", "mix.lock", "gleam.toml", "manifest.toml",
|
|
24
|
-
"global.json", "Directory.Build.props", "Directory.Packages.props", "NuGet.config"];
|
|
25
|
+
"global.json", "Directory.Build.props", "Directory.Packages.props", "NuGet.config", "project.scala", "Package.swift", "Package.resolved"];
|
|
25
26
|
|
|
26
27
|
const digest = (value) => createHash("sha256").update(value).digest("hex");
|
|
27
28
|
// The crypto builder owns these outputs. Inputs and other priv/ assets still
|
|
@@ -98,6 +99,12 @@ const groupBy = (entries, key) => {
|
|
|
98
99
|
return [...groups.entries()];
|
|
99
100
|
};
|
|
100
101
|
|
|
102
|
+
// Hpack discovers generated modules before native result keys are computed.
|
|
103
|
+
// Stack owns this metadata transformation; no compilation or tests run here.
|
|
104
|
+
export function configurationInvocations(target) {
|
|
105
|
+
return target.language==='haskell'?[{command:'stack',args:['--no-terminal','config','build-files']}]:[];
|
|
106
|
+
}
|
|
107
|
+
|
|
101
108
|
// Rebar and Mix run their configured compile hooks. Gleam has no corresponding
|
|
102
109
|
// hook, so build its generated crypto bridge before starting a native test VM.
|
|
103
110
|
export function preparationInvocations(target, files) {
|
|
@@ -156,11 +163,30 @@ export function benchmarkInvocations(target, entries, { offline = false } = {})
|
|
|
156
163
|
args: [...(offline ? ["--offline"] : []), "--console=plain", "test", "--rerun", "--tests", className(file, "src/test/kotlin", ".kt")],
|
|
157
164
|
env: { "kotest.filter.tests": filter, kotest_filter_tests: filter } };
|
|
158
165
|
});
|
|
166
|
+
// The Clojure runner selects tests by namespace and name prefix.
|
|
167
|
+
if (language === "clojure") {
|
|
168
|
+
const ns = (file) => without(relativeTo(file, "test"), ".clj").replaceAll("/", ".").replaceAll("_", "-");
|
|
169
|
+
return [{ command: target.clojure || "clojure",
|
|
170
|
+
args: ["-M:test", ...entries.flatMap((e) => ["--select", `${ns(e.file)}/${e.name}`])] }];
|
|
171
|
+
}
|
|
172
|
+
// Spock names each feature in words; Gradle's filters select it by name.
|
|
173
|
+
if (language === "groovy")
|
|
174
|
+
return [{ command: target.gradle || "gradle",
|
|
175
|
+
args: [...(offline ? ["--offline"] : []), "--console=plain", "test", "--rerun",
|
|
176
|
+
...entries.flatMap((e) => ["--tests", `${className(e.file, "src/test/groovy", ".groovy")}.${e.name}`])] }];
|
|
159
177
|
if (language === "rust")
|
|
160
178
|
return groupBy(entries, (e) => e.file).map(([file, marks]) => ({ command: "cargo",
|
|
161
179
|
args: ["test", ...(offline ? ["--offline"] : []), "--test", path.posix.basename(file, ".rs"), "--", "--exact", "--nocapture", ...marks.map((e) => e.name)] }));
|
|
162
180
|
if (language === "fsharp" || language === "csharp")
|
|
163
181
|
return [{ command: "dotnet", args: ["test", ...entries.flatMap((e) => ["--filter-query", `/*/*/*/${e.name}`])] }];
|
|
182
|
+
if (language === "scala")
|
|
183
|
+
return groupBy(entries, (e) => e.file).map(([file, marks]) => ({ command: target.scala || "scala",
|
|
184
|
+
args: ["test", ".", ...(offline ? ["--offline"] : []), "--test-only", className(file, "src/test/scala", ".scala"), "--",
|
|
185
|
+
...marks.flatMap((e) => ["-z", e.name])] }));
|
|
186
|
+
// Swift Testing selects tests by a regular expression over their ids
|
|
187
|
+
// (Module.Suite/function()), one --filter per benchmark, OR'd.
|
|
188
|
+
if (language === "swift")
|
|
189
|
+
return [{ command: target.swift || "swift", args: ["test", ...entries.flatMap((e) => ["--filter", `/${regex(e.name)}\\(`])] }];
|
|
164
190
|
if (language === "haskell") {
|
|
165
191
|
const module = (e) => without(relativeTo(e.file, "test"), "Spec.hs").replaceAll("/", ".");
|
|
166
192
|
// hspec matches by substring, and a benchmark's name has spaces, so each
|
|
@@ -177,7 +203,14 @@ export function benchmarkInvocations(target, entries, { offline = false } = {})
|
|
|
177
203
|
// LawSpec.TestNames), then a kind after a separator no name contains, so one
|
|
178
204
|
// law's name never selects another's. `scratch` is a folder for reports;
|
|
179
205
|
// `coverage` asks each runner to measure coverage too (see coverageSetup).
|
|
180
|
-
export function invocations(
|
|
206
|
+
export function invocations(...arguments_) {
|
|
207
|
+
return nativeInvocations(...arguments_).map(run => {
|
|
208
|
+
const matches=run.matches??run.ran;
|
|
209
|
+
return matches?{...run,matches,ran:test=>test.status==='passed'?matches(test):[]}:run;
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
function nativeInvocations(target, entries, { offline = false, scratch = ".", coverage = null, xdist = false,
|
|
181
214
|
root = process.cwd(), coverageConfig } = {}) {
|
|
182
215
|
if (!entries.length) return [];
|
|
183
216
|
const language = target.language;
|
|
@@ -186,12 +219,14 @@ export function invocations(target, entries, { offline = false, scratch = ".", c
|
|
|
186
219
|
const directory = testDir || defaultDir;
|
|
187
220
|
return file.startsWith(directory + "/") ? file.slice(directory.length + 1) : file;
|
|
188
221
|
};
|
|
189
|
-
const
|
|
222
|
+
const model = (entry) => entry.kind === "model";
|
|
223
|
+
const named = (entry) => new RegExp(`^${regex(entry.name)}${model(entry) ? "$" : "_"}`);
|
|
190
224
|
const className = (file, defaultDir, extension) => without(relativeTo(file, defaultDir), extension).replaceAll("/", ".");
|
|
191
225
|
if (["erlang", "elixir", "gleam"].includes(language)) {
|
|
192
226
|
const run = randomUUID();
|
|
193
227
|
const file = path.join(scratch, `beam-${run}.jsonl`);
|
|
194
228
|
const identity = (entry) => `${entry.unit}::${entry.name}`;
|
|
229
|
+
const matching = test => entries.filter(entry => test.identity === identity(entry));
|
|
195
230
|
const env = { LAWSPEC_BEAM_REPORT: file, LAWSPEC_BEAM_RUN: run };
|
|
196
231
|
const measured = coverage ? {run, file: path.resolve(coverage, "runs", `${run}.coverdata`),
|
|
197
232
|
...(language === "elixir" ? {beamDirectory: coverageConfig?.compilePath} : {}),
|
|
@@ -222,34 +257,52 @@ export function invocations(target, entries, { offline = false, scratch = ".", c
|
|
|
222
257
|
}
|
|
223
258
|
}
|
|
224
259
|
return [{ laws: entries, command, args, env, ...(measured ? {coverage: measured} : {}), report: {kind: "beam-events", file, run},
|
|
225
|
-
ran:
|
|
260
|
+
matches: matching, ran: test => test.status === "passed" ? matching(test) : [] }];
|
|
226
261
|
}
|
|
227
262
|
if (language === "python")
|
|
228
|
-
return groupBy(entries, (e) => e.file).
|
|
263
|
+
return groupBy(entries, (e) => e.file).flatMap(([file, selected], n) => {
|
|
264
|
+
const laws=selected.filter(entry=>!model(entry));
|
|
265
|
+
const models=selected.filter(model);
|
|
266
|
+
const invocations=[];
|
|
229
267
|
const report = path.join(scratch, `pytest-${n}.xml`);
|
|
230
268
|
// parallel: pytest-xdist runs the tests on several workers, when it
|
|
231
269
|
// is installed (lawspec test checks); otherwise one after another.
|
|
232
|
-
const workers = xdist &&
|
|
270
|
+
const workers = xdist && selected.some((e) => e.parallel) ? ["-p", "xdist", "-n", "auto"] : [];
|
|
233
271
|
const pytest = ["-m", "pytest", "-q", ...workers, file, "-k", laws.map((e) => `${e.name}__`).join(" or "), `--junitxml=${report}`];
|
|
234
|
-
|
|
272
|
+
if(laws.length)invocations.push({ laws, command: target.python || "python3",
|
|
235
273
|
args: coverage ? ["-m", "coverage", "run", "--append", `--data-file=${path.join(coverage, ".coverage")}`, ...pytest.slice(1)] : pytest,
|
|
236
274
|
report: { kind: "junit", files: [report] },
|
|
237
|
-
ran: (test) => laws.filter((e) => test.name.startsWith(`${e.name}__`)) };
|
|
275
|
+
ran: (test) => laws.filter((e) => test.name.startsWith(`${e.name}__`)) });
|
|
276
|
+
if(models.length){
|
|
277
|
+
const modelReport=path.join(scratch,`pytest-model-${n}.xml`);
|
|
278
|
+
const arguments_=["-m","pytest","-q",...workers,
|
|
279
|
+
...new Set(models.map(entry=>`${file}::${entry.name}`)),`--junitxml=${modelReport}`];
|
|
280
|
+
invocations.push({laws:models,command:target.python||"python3",
|
|
281
|
+
args:coverage?["-m","coverage","run","--append",`--data-file=${path.join(coverage,".coverage")}`,...arguments_.slice(1)]:arguments_,
|
|
282
|
+
report:{kind:"junit",files:[modelReport]},
|
|
283
|
+
ran:test=>models.filter(entry=>test.name===entry.name)});
|
|
284
|
+
}
|
|
285
|
+
return invocations;
|
|
238
286
|
});
|
|
239
287
|
if (language === "javascript" || language === "typescript") {
|
|
240
|
-
const pattern = (e) =>
|
|
288
|
+
const pattern = (e) => model(e)?`^${regex(e.label)}$`:
|
|
289
|
+
`^${regex(e.label)}( example: .*| property| known failing| skipped| replay| search)?$`;
|
|
241
290
|
const files = [...new Set(entries.map((e) => language === "typescript"
|
|
242
291
|
? `dist/${without(e.file, ".ts")}.js` : e.file))];
|
|
243
|
-
const
|
|
292
|
+
const file = path.join(scratch, "node-events.jsonl");
|
|
293
|
+
const runId=randomUUID();
|
|
294
|
+
const matching = test => entries.filter(entry => new RegExp(pattern(entry)).test(test.name));
|
|
244
295
|
// parallel: test files run at the same time too.
|
|
245
296
|
const node = ["--test", ...(entries.some((e) => e.parallel) ? ["--test-concurrency=" + Math.max(2, (globalThis.navigator?.hardwareConcurrency ?? 2))] : []),
|
|
246
297
|
`--test-name-pattern=(${entries.map(pattern).join("|")})`,
|
|
247
298
|
"--test-reporter=spec", "--test-reporter-destination=stdout",
|
|
248
|
-
|
|
299
|
+
`--test-reporter=${new URL('./node-events-reporter.mjs',import.meta.url).href}`,
|
|
300
|
+
`--test-reporter-destination=${file}`, ...files];
|
|
249
301
|
const run = { laws: entries, command: coverage ? "npx" : process.execPath,
|
|
250
302
|
args: coverage ? ["--no-install", "c8", "--reporter=text", `--reports-dir=${coverage}`, process.execPath, ...node] : node,
|
|
251
|
-
|
|
252
|
-
|
|
303
|
+
// A CLI launched from node:test must start an independent native run.
|
|
304
|
+
env:{LAWSPEC_NODE_RUN:runId,NODE_TEST_CONTEXT:undefined},report: { kind: "node-events", file, run:runId },
|
|
305
|
+
matches: matching, ran: test => test.status === 'passed' ? matching(test) : [] };
|
|
253
306
|
return language === "typescript"
|
|
254
307
|
? [{ laws: [], command: "npm", args: ["exec", "--", "tsc", "-p", "tsconfig.json"] }, run]
|
|
255
308
|
: [run];
|
|
@@ -258,7 +311,9 @@ export function invocations(target, entries, { offline = false, scratch = ".", c
|
|
|
258
311
|
return groupBy(entries, (e) => path.posix.dirname(e.file)).map(([directory, laws]) => ({
|
|
259
312
|
laws, command: "go",
|
|
260
313
|
args: ["test", "-json", "-count=1", ...(coverage ? ["-cover", `-coverprofile=${path.join(coverage, `go-${directory.replaceAll("/", "_") || "root"}.out`)}`] : []),
|
|
261
|
-
`./${directory}`, "-run",
|
|
314
|
+
`./${directory}`, "-run", laws.some(model)?
|
|
315
|
+
`^(${[...new Set(laws.map(e=>regex(e.name)+(model(e)?"$":"_")))].join("|")})`:
|
|
316
|
+
`^(${laws.map((e) => regex(e.name)).join("|")})_`],
|
|
262
317
|
report: { kind: "go-json" },
|
|
263
318
|
ran: (test) => laws.filter((e) => named(e).test(test.name)) }));
|
|
264
319
|
if (language === "java") {
|
|
@@ -266,9 +321,9 @@ export function invocations(target, entries, { offline = false, scratch = ".", c
|
|
|
266
321
|
return [{ laws: entries, command: target.maven || "mvn",
|
|
267
322
|
args: [...(offline ? ["-o"] : []), "-B", ...(coverage ? ["org.jacoco:jacoco-maven-plugin:prepare-agent"] : []), "test",
|
|
268
323
|
...(coverage ? ["org.jacoco:jacoco-maven-plugin:report"] : []),
|
|
269
|
-
`-Dtest=${byClass.map(([name, laws]) => `${name}#${laws.map((e) =>
|
|
324
|
+
`-Dtest=${byClass.map(([name, laws]) => `${name}#${[...new Set(laws.map((e) => model(e)?e.name:`${e.name}_*`))].join("+")}`).join(",")}`],
|
|
270
325
|
report: { kind: "junit", directory: "target/surefire-reports" },
|
|
271
|
-
ran: (test) => entries.filter((e) => test.classname === className(e.file, "src/test/java", ".java") && named(e).test(test.name)) }];
|
|
326
|
+
ran: (test) => entries.filter((e) => test.classname === (e.scope??className(e.file, "src/test/java", ".java")) && named(e).test(test.name)) }];
|
|
272
327
|
}
|
|
273
328
|
// Kotest names tests by string, which Gradle's method filters cannot
|
|
274
329
|
// select. Kotest's own filter selects them within each class: one pattern,
|
|
@@ -276,19 +331,62 @@ export function invocations(target, entries, { offline = false, scratch = ".", c
|
|
|
276
331
|
// patterns must all match, so alternatives go in one group).
|
|
277
332
|
if (language === "kotlin")
|
|
278
333
|
return groupBy(entries, (e) => e.file).map(([file, laws]) => {
|
|
279
|
-
const filter =
|
|
334
|
+
const filter = laws.some(model)?
|
|
335
|
+
`(${[...new Set(laws.map(e=>regex(e.name)+(model(e)?"":"_.*")))].join("|")})`:
|
|
336
|
+
`(${laws.map((e) => `${e.name}_`).join("|")})*`;
|
|
280
337
|
const name = className(file, "src/test/kotlin", ".kt");
|
|
281
338
|
return { laws, command: target.gradle || "gradle",
|
|
282
339
|
args: [...(offline ? ["--offline"] : []), "--console=plain", "test", ...(coverage ? ["koverXmlReport"] : []), "--rerun", "--tests", name],
|
|
283
340
|
env: { "kotest.filter.tests": filter, kotest_filter_tests: filter },
|
|
284
341
|
report: { kind: "junit", directory: "build/test-results/test" },
|
|
285
|
-
ran: (test) => laws.filter((e) => test.classname === name && named(e).test(test.name)) };
|
|
342
|
+
ran: (test) => laws.filter((e) => test.classname === (e.scope??name) && named(e).test(test.name)) };
|
|
286
343
|
});
|
|
344
|
+
// ScalaTest selects tests by substring (-z): each law's tests are named
|
|
345
|
+
// after it, then a kind after a separator no name contains. Its JUnit
|
|
346
|
+
// reporter writes one file per suite (-u).
|
|
347
|
+
if (language === "scala")
|
|
348
|
+
return groupBy(entries, (e) => e.file).map(([file, laws], n) => {
|
|
349
|
+
const name = className(file, "src/test/scala", ".scala");
|
|
350
|
+
const directory = path.join(scratch, `scalatest-${n}`);
|
|
351
|
+
// --coverage: Scala 3 instruments the code (scoverage's format).
|
|
352
|
+
// The tests themselves are not measured.
|
|
353
|
+
const testRoot = target.testDir || "src/test/scala";
|
|
354
|
+
const measured = coverage ? ["-O", `-coverage-out:${path.resolve(coverage, "data")}`,
|
|
355
|
+
"-O", `-coverage-exclude-files:.*/${testRoot.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}/.*`] : [];
|
|
356
|
+
return { laws, command: target.scala || "scala",
|
|
357
|
+
args: ["test", ".", ...(offline ? ["--power","--offline"] : []), ...measured, "--test-only", name, "--",
|
|
358
|
+
...[...new Map(laws.map(e=>[(model(e)?"exact:":"prefix:")+e.name,e])).values()]
|
|
359
|
+
.flatMap(e=>[model(e)?"-t":"-z",model(e)?e.name:`${e.name}_`]), "-u", directory],
|
|
360
|
+
report: { kind: "junit", directory: path.relative(root, directory) || "." },
|
|
361
|
+
ran: (test) => laws.filter((e) => test.classname === (e.scope??name) && named(e).test(test.name)) };
|
|
362
|
+
});
|
|
363
|
+
// A Clojure test is the law's words, a double dash and the kind of test
|
|
364
|
+
// (LawSpec.TestNames); the runner selects tests by namespace and prefix.
|
|
365
|
+
if (language === "clojure") {
|
|
366
|
+
const ns = (e) => e.scope??without(relativeTo(e.file, "test"), ".clj").replaceAll("/", ".").replaceAll("_", "-");
|
|
367
|
+
return [{ laws: entries, command: target.clojure || "clojure",
|
|
368
|
+
args: ["-M:test", ...[...new Map(entries.map(e=>[(model(e)?"exact:":"prefix:")+ns(e)+"/"+e.name,e])).values()]
|
|
369
|
+
.flatMap(e=>[model(e)?"--select-exact":"--select",`${ns(e)}/${e.name}${model(e)?"":"--"}`])],
|
|
370
|
+
report: { kind: "junit", directory: "target/test-results" },
|
|
371
|
+
ran: (test) => entries.filter((e) => test.classname === ns(e) &&
|
|
372
|
+
(model(e)?test.name===e.name:test.name.startsWith(`${e.name}--`))) }];
|
|
373
|
+
}
|
|
374
|
+
// A Spock feature is the law's words, a colon and the kind of test
|
|
375
|
+
// (LawSpec.TestNames), so "name: *" selects one law's features only.
|
|
376
|
+
if (language === "groovy") {
|
|
377
|
+
const name = (e) => className(e.file, "src/test/groovy", ".groovy");
|
|
378
|
+
return [{ laws: entries, command: target.gradle || "gradle",
|
|
379
|
+
args: [...(offline ? ["--offline"] : []), "--console=plain", "test", ...(coverage ? ["jacocoTestReport"] : []), "--rerun",
|
|
380
|
+
...[...new Set(entries.map(e=>`${e.scope??name(e)}.${e.name}${model(e)?"":": *"}`))].flatMap(name=>["--tests",name])],
|
|
381
|
+
report: { kind: "junit", directory: "build/test-results/test" },
|
|
382
|
+
ran: (test) => entries.filter((e) => test.classname === (e.scope??name(e)) &&
|
|
383
|
+
(model(e)?test.name===e.name:test.name.startsWith(`${e.name}: `))) }];
|
|
384
|
+
}
|
|
287
385
|
if (language === "rust")
|
|
288
386
|
return groupBy(entries, (e) => e.file).map(([file, laws]) => ({
|
|
289
387
|
laws, command: "cargo",
|
|
290
388
|
args: [...(coverage ? ["llvm-cov", "--no-report"] : []), "test", ...(offline ? ["--offline"] : []), "--test", path.posix.basename(file, ".rs"), "--", "--exact",
|
|
291
|
-
...laws.map((e) => e.name)],
|
|
389
|
+
...new Set(laws.map((e) => e.name))],
|
|
292
390
|
report: { kind: "lines", pattern: /^test (\S+) \.\.\. (ok|FAILED|ignored)/ },
|
|
293
391
|
ran: (test) => laws.filter((e) => test.name === e.name) }));
|
|
294
392
|
// xUnit v3 on Microsoft.Testing.Platform selects test methods with its
|
|
@@ -307,13 +405,30 @@ export function invocations(target, entries, { offline = false, scratch = ".", c
|
|
|
307
405
|
report: { kind: "junit", files: [path.join(results, report)] },
|
|
308
406
|
ran: (test) => entries.filter((e) => pattern(e).test(test.name)) }];
|
|
309
407
|
}
|
|
408
|
+
// Swift Testing selects tests by a regular expression over their ids
|
|
409
|
+
// (Module.Suite/function()), and writes its xUnit report next to the path
|
|
410
|
+
// given, with -swift-testing added. A law's tests are its unit's suite
|
|
411
|
+
// (named after the test file) and its name, then a kind (lawName_property).
|
|
412
|
+
if (language === "swift") {
|
|
413
|
+
const results = path.resolve(scratch);
|
|
414
|
+
const suite = (e) => path.posix.basename(e.file, ".swift");
|
|
415
|
+
const test = (e) => `${regex(suite(e))}/${regex(e.name)}(_[A-Za-z0-9]+)?\\(`;
|
|
416
|
+
return [{ laws: entries, command: target.swift || "swift",
|
|
417
|
+
args: ["test", ...(coverage ? ["--enable-code-coverage"] : []), ...entries.flatMap((e) => ["--filter", test(e)]),
|
|
418
|
+
"--xunit-output", path.join(results, "swift-lawspec.xml")],
|
|
419
|
+
report: { kind: "junit", files: [path.join(results, "swift-lawspec-swift-testing.xml")] },
|
|
420
|
+
ran: (result) => entries.filter((e) => result.classname?.split(".").pop() === suite(e) &&
|
|
421
|
+
new RegExp(`^${regex(e.name)}(_[A-Za-z0-9]+)?(\\(|$)`).test(result.name)) }];
|
|
422
|
+
}
|
|
310
423
|
if (language === "haskell") {
|
|
311
424
|
const module = (e) => without(relativeTo(e.file, "test"), "Spec.hs").replaceAll("/", ".");
|
|
312
|
-
const matches = entries.map((e) =>
|
|
425
|
+
const matches = [...new Set(entries.map((e) => model(e)?
|
|
426
|
+
`/${e.scope??module(e)}/${e.unit} models/${e.name}/`:`${module(e)}/${e.name}_`))];
|
|
313
427
|
return [{ laws: entries, command: "stack",
|
|
314
|
-
args: ["--no-terminal", "test", ...(coverage ? ["--coverage"] : []), "--test-arguments",
|
|
428
|
+
args: ["--no-terminal", "test", ...(coverage ? ["--coverage"] : []), "--test-arguments",
|
|
429
|
+
matches.map((m) => `--match ${m.includes(" ")?JSON.stringify(m):m}`).join(" ")],
|
|
315
430
|
report: { kind: "hspec" },
|
|
316
|
-
ran: (test) => entries.filter((e) => test.classname === module(e) && named(e).test(test.name)) }];
|
|
431
|
+
ran: (test) => entries.filter((e) => test.classname === (e.scope??module(e)) && named(e).test(test.name)) }];
|
|
317
432
|
}
|
|
318
433
|
throw new Error(`lawspec test does not support ${language}`);
|
|
319
434
|
}
|
|
@@ -329,10 +444,14 @@ export const coverageTools = {
|
|
|
329
444
|
go: { tool: "go test -cover", install: "(built in)" },
|
|
330
445
|
java: { tool: "JaCoCo", install: "(resolved by Maven as org.jacoco:jacoco-maven-plugin)" },
|
|
331
446
|
kotlin: { tool: "Kover", install: "add id(\"org.jetbrains.kotlinx.kover\") to the plugins of build.gradle.kts" },
|
|
447
|
+
clojure: { tool: "cloverage", install: "add cloverage to a :coverage alias in deps.edn" },
|
|
448
|
+
groovy: { tool: "JaCoCo", install: "add id 'jacoco' to the plugins of build.gradle" },
|
|
332
449
|
rust: { tool: "cargo-llvm-cov", install: "cargo install cargo-llvm-cov" },
|
|
333
450
|
haskell: { tool: "hpc", install: "(built into GHC; stack test --coverage)" },
|
|
334
451
|
fsharp: { tool: "Microsoft code coverage", install: "add the Microsoft.Testing.Extensions.CodeCoverage package to the test project" },
|
|
335
452
|
csharp: { tool: "Microsoft code coverage", install: "add the Microsoft.Testing.Extensions.CodeCoverage package to the test project" },
|
|
453
|
+
scala: { tool: "scoverage", install: "(built into Scala 3; Scala CLI fetches the scoverage reporter)" },
|
|
454
|
+
swift: { tool: "llvm-cov", install: "(built into the Swift toolchain; swift test --enable-code-coverage)" },
|
|
336
455
|
};
|
|
337
456
|
|
|
338
457
|
// Laws selected by tag: every --tag, and none of --exclude-tag.
|
|
@@ -426,6 +545,20 @@ export async function harnessStatistics(directory) {
|
|
|
426
545
|
// The tests a run executed, as {name, classname}, from the runner's report or
|
|
427
546
|
// output. Skipped tests are not counted.
|
|
428
547
|
export async function executedTests(report, output, root, since) {
|
|
548
|
+
if(report?.kind==='node-events') {
|
|
549
|
+
const raw=await readFile(path.resolve(root,report.file),'utf8').catch(()=>'');
|
|
550
|
+
let rows;
|
|
551
|
+
try {rows=raw.trim().split('\n').map(line=>JSON.parse(line));}catch{return [];}
|
|
552
|
+
if(rows.length<2||rows[0]?.event!=='start'||rows.at(-1)?.event!=='end'||
|
|
553
|
+
rows.some(row=>row?.version!==1||row?.run!==report.run)||
|
|
554
|
+
rows.at(-1).count!==rows.length-2) return [];
|
|
555
|
+
const tests=rows.slice(1,-1);
|
|
556
|
+
if(tests.some(row=>row?.event!=='test'||typeof row.name!=='string'||typeof row.classname!=='string'||
|
|
557
|
+
!['passed','failed','skipped'].includes(row.status)||
|
|
558
|
+
(row.time!==undefined&&(!Number.isFinite(row.time)||row.time<0))||
|
|
559
|
+
(row.failure!==undefined&&typeof row.failure!=='string')))return [];
|
|
560
|
+
return tests;
|
|
561
|
+
}
|
|
429
562
|
if (report?.kind === "beam-events") {
|
|
430
563
|
// A native listener seals the invocation after its final event. Missing,
|
|
431
564
|
// stale, malformed or interrupted reports are not execution evidence.
|
|
@@ -444,11 +577,25 @@ export async function executedTests(report, output, root, since) {
|
|
|
444
577
|
const files = report.files ?? await reportFiles(path.join(root, report.directory), since);
|
|
445
578
|
const tests = [];
|
|
446
579
|
for (const file of files) {
|
|
447
|
-
const
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
580
|
+
const location=path.resolve(root,file);
|
|
581
|
+
const info=await stat(location).catch(()=>null);
|
|
582
|
+
if(!info||info.mtimeMs<since)continue;
|
|
583
|
+
const xml=await readFile(location,"utf8").catch(()=>"");
|
|
584
|
+
const attributes=opening=>Object.fromEntries([...opening.matchAll(/\s([A-Za-z_:][\w:.-]*)\s*=\s*(?:"([^"]*)"|'([^']*)')/g)]
|
|
585
|
+
.map(match=>[match[1],unescapeXml(match[2]??match[3])]));
|
|
586
|
+
for(const element of junitElements(xml,["testcase"])){
|
|
587
|
+
const values=attributes(element.opening);
|
|
588
|
+
const native=junitElements(element.xml,["failure","error","skipped"]);
|
|
589
|
+
const failure=native.filter(element=>element.name!=="skipped");
|
|
590
|
+
const status=failure.length?"failed":native.length?"skipped":"passed";
|
|
591
|
+
const detail=element=>[attributes(element.opening).message,
|
|
592
|
+
unescapeXml(element.xml.slice(element.opening.length).replace(/<\/(failure|error|skipped)>\s*$/,"")
|
|
593
|
+
.replace(/<!\[CDATA\[([\s\S]*?)\]\]>/g,(_,text)=>text))].filter(Boolean).join("\n");
|
|
594
|
+
const time=values.time===undefined?undefined:Number(values.time);
|
|
595
|
+
tests.push({name:(values.name??"").replace(/\(\)$/, ""),classname:values.classname??"",status,
|
|
596
|
+
...(Number.isFinite(time)&&time>=0?{time}:{}),
|
|
597
|
+
...(failure.length?{failure:failure.map(detail).join("\n")}:
|
|
598
|
+
status==="skipped"?{reason:native.map(detail).join("\n")}: {})});
|
|
452
599
|
}
|
|
453
600
|
}
|
|
454
601
|
return tests;
|
|
@@ -472,7 +619,8 @@ export async function executedTests(report, output, root, since) {
|
|
|
472
619
|
let module = "";
|
|
473
620
|
for (const line of output.split("\n")) {
|
|
474
621
|
if (/^\S/.test(line) && !/^(Finished|Failures|Randomized|\d+ examples?)/.test(line)) module = line.trim();
|
|
475
|
-
const example = line.match(/^\s+(law\S*?):?(?:\s.*)?\s\[([✔✘])\]\s*$/)
|
|
622
|
+
const example = line.match(/^\s+(law\S*?):?(?:\s.*)?\s\[([✔✘])\]\s*$/) ??
|
|
623
|
+
line.match(/^\s+(model .+?|supervision)\s\[([✔✘])\]\s*$/);
|
|
476
624
|
if (example) tests.push({ name: example[1], classname: module, status: example[2] === "✔" ? "passed" : "failed" });
|
|
477
625
|
}
|
|
478
626
|
return tests;
|