lawspec 0.21.0 → 0.23.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 +322 -2
- package/README.md +3 -3
- package/beam-coverage.mjs +160 -0
- package/beam-doctor.mjs +306 -0
- package/bin/lawspec.mjs +150 -41
- package/build.json +359 -101
- package/compatibility.json +25 -0
- package/core.wasm +2 -2
- package/doctor.mjs +29 -2
- package/examples/native-payments/csharp/lawspec.json +51 -0
- package/examples/native-payments/csharp/src/Domain/Payments.cs +19 -0
- package/examples/native-payments/csharp/tests/Native/PaymentGenerators.cs +14 -0
- package/examples/native-payments/elixir/lawspec.json +149 -0
- package/examples/native-payments/elixir/lib/payments_domain.ex +54 -0
- package/examples/native-payments/elixir/test/support/payment_generators.ex +9 -0
- package/examples/native-payments/erlang/include/payments_domain.hrl +2 -0
- package/examples/native-payments/erlang/lawspec.json +148 -0
- package/examples/native-payments/erlang/src/payments_domain.erl +21 -0
- package/examples/native-payments/erlang/test/payment_generators.erl +10 -0
- package/examples/native-payments/fsharp/lawspec.json +167 -0
- package/examples/native-payments/fsharp/src/Native/Types/PaymentsDomain.fs +23 -0
- package/examples/native-payments/fsharp/tests/Native/PaymentGenerators.fs +11 -0
- package/examples/native-payments/gleam/lawspec.json +149 -0
- package/examples/native-payments/gleam/prepare.mjs +48 -0
- package/examples/native-payments/gleam/src/payments_domain.gleam +32 -0
- package/examples/native-payments/gleam/test/payment_generators.gleam +13 -0
- package/examples/specs/collections.lawspec +44 -0
- package/examples/specs/composition.lawspec +110 -0
- package/examples/specs/contracts.lawspec +124 -0
- package/examples/specs/generation.lawspec +11 -0
- package/examples/specs/records.lawspec +191 -0
- package/examples/specs/records_inner.lawspec +10 -0
- package/examples/specs/sequences.lawspec +86 -0
- package/failure-database.mjs +46 -0
- package/index.d.ts +45 -1
- package/native-examples.mjs +7 -2
- package/package.json +2 -2
- package/templates.mjs +134 -3
- package/test-command.mjs +188 -17
package/templates.mjs
CHANGED
|
@@ -9,8 +9,67 @@ export const targets = [
|
|
|
9
9
|
"go",
|
|
10
10
|
"haskell",
|
|
11
11
|
"kotlin",
|
|
12
|
-
"rust"
|
|
12
|
+
"rust",
|
|
13
|
+
"erlang",
|
|
14
|
+
"elixir",
|
|
15
|
+
"gleam",
|
|
16
|
+
"fsharp",
|
|
17
|
+
"csharp"
|
|
13
18
|
];
|
|
19
|
+
export const targetLabels = [
|
|
20
|
+
[
|
|
21
|
+
"java",
|
|
22
|
+
"Java"
|
|
23
|
+
],
|
|
24
|
+
[
|
|
25
|
+
"python",
|
|
26
|
+
"Python"
|
|
27
|
+
],
|
|
28
|
+
[
|
|
29
|
+
"javascript",
|
|
30
|
+
"JavaScript"
|
|
31
|
+
],
|
|
32
|
+
[
|
|
33
|
+
"typescript",
|
|
34
|
+
"TypeScript"
|
|
35
|
+
],
|
|
36
|
+
[
|
|
37
|
+
"go",
|
|
38
|
+
"Go"
|
|
39
|
+
],
|
|
40
|
+
[
|
|
41
|
+
"haskell",
|
|
42
|
+
"Haskell"
|
|
43
|
+
],
|
|
44
|
+
[
|
|
45
|
+
"kotlin",
|
|
46
|
+
"Kotlin"
|
|
47
|
+
],
|
|
48
|
+
[
|
|
49
|
+
"rust",
|
|
50
|
+
"Rust"
|
|
51
|
+
],
|
|
52
|
+
[
|
|
53
|
+
"erlang",
|
|
54
|
+
"Erlang"
|
|
55
|
+
],
|
|
56
|
+
[
|
|
57
|
+
"elixir",
|
|
58
|
+
"Elixir"
|
|
59
|
+
],
|
|
60
|
+
[
|
|
61
|
+
"gleam",
|
|
62
|
+
"Gleam"
|
|
63
|
+
],
|
|
64
|
+
[
|
|
65
|
+
"fsharp",
|
|
66
|
+
"F#"
|
|
67
|
+
],
|
|
68
|
+
[
|
|
69
|
+
"csharp",
|
|
70
|
+
"C#"
|
|
71
|
+
]
|
|
72
|
+
];
|
|
14
73
|
|
|
15
74
|
export const commands = {
|
|
16
75
|
"java": "mvn test",
|
|
@@ -20,7 +79,12 @@ export const commands = {
|
|
|
20
79
|
"go": "go test ./...",
|
|
21
80
|
"haskell": "stack test",
|
|
22
81
|
"kotlin": "gradle test",
|
|
23
|
-
"rust": "cargo test"
|
|
82
|
+
"rust": "cargo test",
|
|
83
|
+
"erlang": "rebar3 eunit",
|
|
84
|
+
"elixir": "mix test",
|
|
85
|
+
"gleam": "gleam test",
|
|
86
|
+
"fsharp": "dotnet test",
|
|
87
|
+
"csharp": "dotnet test"
|
|
24
88
|
};
|
|
25
89
|
|
|
26
90
|
export const setup = {
|
|
@@ -31,7 +95,12 @@ export const setup = {
|
|
|
31
95
|
"go": "Use Go 1.25+ and go get pgregory.net/rapid@v1.2.0 (and github.com/cloudflare/circl@v1.6.5 for a program that imports lawspec.crypto or lawspec.network), then go mod download.",
|
|
32
96
|
"haskell": "Use Stack with lts-24.58, directory and time as dependencies (and, for a program that imports lawspec.crypto, lawspec.network or lawspec.randomness, extra-deps crypton-1.1.5, ram-0.22.1, mlkem-0.2.3.0 and mldsa-0.1.1.0 as dependencies too), and test dependencies hspec, hedgehog, hspec-hedgehog, hspec-discover, and a test/Spec.hs using hspec-discover. Run stack build --test --no-run-tests.",
|
|
33
97
|
"kotlin": "Use JDK 25, Gradle 9.3.0, Kotlin plugin 2.3.21, JVM target 25, Kotest 5.9.1 (runner, assertions, property), and useJUnitPlatform(); a program that imports lawspec.crypto or lawspec.network also needs Bouncy Castle bcprov-jdk18on 1.86. Run gradle testClasses.",
|
|
34
|
-
"rust": "Use Rust 1.85+ with edition 2024, Proptest 1.11.0, num-bigint 0.4.8, num-rational 0.4.2, num-complex 0.4.6 and num-traits 0.2.19; a program that imports lawspec.crypto, lawspec.network or lawspec.randomness also needs sha3 0.12.0, shake 0.1.0, ml-kem 0.3.2, ml-dsa 0.1.1, slh-dsa 0.2.0-rc.5, aes-gcm 0.11.1 and getrandom 0.4.3. Run cargo test."
|
|
98
|
+
"rust": "Use Rust 1.85+ with edition 2024, Proptest 1.11.0, num-bigint 0.4.8, num-rational 0.4.2, num-complex 0.4.6 and num-traits 0.2.19; a program that imports lawspec.crypto, lawspec.network or lawspec.randomness also needs sha3 0.12.0, shake 0.1.0, ml-kem 0.3.2, ml-dsa 0.1.1, slh-dsa 0.2.0-rc.5, aes-gcm 0.11.1 and getrandom 0.4.3. Run cargo test.",
|
|
99
|
+
"erlang": "Use Erlang/OTP 29, Rebar3 3.27.1 and PropEr 1.5.0 as a Hex dependency in the test profile. Configure {eunit_opts, [{print_depth, 100}, {report, {lawspec_beam_report, []}}]}. Run rebar3 as test compile to prepare dependencies, then rebar3 eunit. Custom test directories must be in extra_src_dirs. 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.",
|
|
100
|
+
"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
|
+
"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
|
+
"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."
|
|
35
104
|
};
|
|
36
105
|
|
|
37
106
|
// Each target's build files in the readable and the compact (minified) layout.
|
|
@@ -109,6 +178,68 @@ const scaffolds = {
|
|
|
109
178
|
"src/lib.rs": "// Application library. LawSpec maintains the included module declarations.\ninclude!(\"lawspec_modules.rs\");\n",
|
|
110
179
|
"Cargo.toml": "[package]\nname = \"lawspec-example\"\nversion = \"0.1.0\"\nedition = \"2024\"\nrust-version = \"1.85\"\npublish = false\n\n[dependencies]\nnum-bigint = \"=0.4.8\"\nnum-rational = \"=0.4.2\"\nnum-complex = \"=0.4.6\"\nnum-traits = \"=0.2.19\"\n\n[dev-dependencies]\nproptest = \"=1.11.0\"\n"
|
|
111
180
|
}
|
|
181
|
+
},
|
|
182
|
+
"erlang": {
|
|
183
|
+
"readable": {
|
|
184
|
+
"rebar.config": "{erl_opts, [debug_info]}.\n{eunit_opts, [{print_depth, 100}, {report, {lawspec_beam_report, []}}]}.\n{profiles, [{test, [{deps, [{proper, \"1.5.0\"}]}]}]}.\n",
|
|
185
|
+
"src/lawspec_example.app.src": "{application, lawspec_example, [\n {description, \"LawSpec example\"},\n {vsn, \"0.1.0\"},\n {modules, []},\n {registered, []},\n {applications, [kernel, stdlib]}\n]}.\n"
|
|
186
|
+
},
|
|
187
|
+
"compact": {
|
|
188
|
+
"rebar.config": "{erl_opts, [debug_info]}.\n{eunit_opts, [{print_depth, 100}, {report, {lawspec_beam_report, []}}]}.\n{profiles, [{test, [{deps, [{proper, \"1.5.0\"}]}]}]}.\n",
|
|
189
|
+
"src/lawspec_example.app.src": "{application, lawspec_example, [\n {description, \"LawSpec example\"},\n {vsn, \"0.1.0\"},\n {modules, []},\n {registered, []},\n {applications, [kernel, stdlib]}\n]}.\n"
|
|
190
|
+
}
|
|
191
|
+
},
|
|
192
|
+
"elixir": {
|
|
193
|
+
"readable": {
|
|
194
|
+
"mix.exs": "defmodule LawSpecExample.MixProject do\n use Mix.Project\n\n def project do\n [app: :lawspec_example, version: \"0.1.0\", elixir: \"~> 1.20\",\n erlc_paths: [\"src\"] ++ test_paths(), elixirc_paths: [\"lib\"] ++ test_paths(),\n deps: [{:stream_data, \"== 1.4.0\", only: :test}]]\n end\n\n defp test_paths, do: if(Mix.env() == :test, do: [\"test/support\"], else: [])\n\n def application do\n [extra_applications: [:logger]]\n end\nend\n",
|
|
195
|
+
"test/test_helper.exs": "case System.get_env(\"LAWSPEC_SEED\") do\n nil -> ExUnit.start()\n seed -> ExUnit.start(seed: String.to_integer(seed))\nend\nif Code.ensure_loaded?(LawSpec.Beam.ExUnitFormatter) do\n ExUnit.configure(formatters: Enum.uniq(ExUnit.configuration()[:formatters] ++ [LawSpec.Beam.ExUnitFormatter]))\nend\nif Code.ensure_loaded?(:lawspec_beam_resources) do\n :lawspec_beam_resources.configure_suite(Process.whereis(ExUnit.Server))\n ExUnit.after_suite(fn _ -> :lawspec_beam_resources.stop_suite() end)\nend\n"
|
|
196
|
+
},
|
|
197
|
+
"compact": {
|
|
198
|
+
"mix.exs": "defmodule LawSpecExample.MixProject do\n use Mix.Project\n\n def project do\n [app: :lawspec_example, version: \"0.1.0\", elixir: \"~> 1.20\",\n erlc_paths: [\"src\"] ++ test_paths(), elixirc_paths: [\"lib\"] ++ test_paths(),\n deps: [{:stream_data, \"== 1.4.0\", only: :test}]]\n end\n\n defp test_paths, do: if(Mix.env() == :test, do: [\"test/support\"], else: [])\n\n def application do\n [extra_applications: [:logger]]\n end\nend\n",
|
|
199
|
+
"test/test_helper.exs": "case System.get_env(\"LAWSPEC_SEED\") do\n nil -> ExUnit.start()\n seed -> ExUnit.start(seed: String.to_integer(seed))\nend\nif Code.ensure_loaded?(LawSpec.Beam.ExUnitFormatter) do\n ExUnit.configure(formatters: Enum.uniq(ExUnit.configuration()[:formatters] ++ [LawSpec.Beam.ExUnitFormatter]))\nend\nif Code.ensure_loaded?(:lawspec_beam_resources) do\n :lawspec_beam_resources.configure_suite(Process.whereis(ExUnit.Server))\n ExUnit.after_suite(fn _ -> :lawspec_beam_resources.stop_suite() end)\nend\n"
|
|
200
|
+
}
|
|
201
|
+
},
|
|
202
|
+
"gleam": {
|
|
203
|
+
"readable": {
|
|
204
|
+
"gleam.toml": "name = \"lawspec_example\"\nversion = \"0.1.0\"\ngleam = \">= 1.18.0\"\ntarget = \"erlang\"\n\n[dependencies]\ngleam_stdlib = \"== 1.0.5\"\n\n[dev-dependencies]\ngleeunit = \"== 1.11.0\"\nqcheck = \"== 1.0.5\"\nlawspec_test_support = { path = \"./test-support\" }\n",
|
|
205
|
+
"test-support/gleam.toml": "# Generated test helpers are a development-only dependency.\nname = \"lawspec_test_support\"\nversion = \"0.1.0\"\ntarget = \"erlang\"\n\n[dependencies]\nqcheck = \"== 1.0.5\"\n",
|
|
206
|
+
"test-support/src/.gitkeep": "",
|
|
207
|
+
"test/lawspec_example_test.gleam": "@external(erlang, \"lawspec_beam_test_run\", \"gleam_main\")\npub fn main() -> Nil\n"
|
|
208
|
+
},
|
|
209
|
+
"compact": {
|
|
210
|
+
"gleam.toml": "name = \"lawspec_example\"\nversion = \"0.1.0\"\ngleam = \">= 1.18.0\"\ntarget = \"erlang\"\n\n[dependencies]\ngleam_stdlib = \"== 1.0.5\"\n\n[dev-dependencies]\ngleeunit = \"== 1.11.0\"\nqcheck = \"== 1.0.5\"\nlawspec_test_support = { path = \"./test-support\" }\n",
|
|
211
|
+
"test-support/gleam.toml": "# Generated test helpers are a development-only dependency.\nname = \"lawspec_test_support\"\nversion = \"0.1.0\"\ntarget = \"erlang\"\n\n[dependencies]\nqcheck = \"== 1.0.5\"\n",
|
|
212
|
+
"test-support/src/.gitkeep": "",
|
|
213
|
+
"test/lawspec_example_test.gleam": "@external(erlang, \"lawspec_beam_test_run\", \"gleam_main\")\npub fn main() -> Nil\n"
|
|
214
|
+
}
|
|
215
|
+
},
|
|
216
|
+
"fsharp": {
|
|
217
|
+
"readable": {
|
|
218
|
+
"global.json": "{ \"test\": { \"runner\": \"Microsoft.Testing.Platform\" } }\n",
|
|
219
|
+
"Example.slnx": "<Solution>\n <Project Path=\"src/Example.fsproj\" />\n <Project Path=\"tests/Example.Tests.fsproj\" />\n <Project Path=\"lawspec/LawSpec.Runtime/LawSpec.Runtime.fsproj\" />\n <Project Path=\"lawspec/LawSpec.Testing/LawSpec.Testing.fsproj\" />\n</Solution>\n",
|
|
220
|
+
"src/Example.fsproj": "<Project Sdk=\"Microsoft.NET.Sdk\">\n <PropertyGroup>\n <TargetFramework>net10.0</TargetFramework>\n <RootNamespace>Example</RootNamespace>\n </PropertyGroup>\n <Import Project=\"LawSpec.Sources.props\" />\n <ItemGroup>\n <ProjectReference Include=\"../lawspec/LawSpec.Runtime/LawSpec.Runtime.fsproj\" />\n </ItemGroup>\n</Project>\n",
|
|
221
|
+
"tests/Example.Tests.fsproj": "<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 </PropertyGroup>\n <Import Project=\"LawSpec.Tests.props\" />\n <ItemGroup>\n <ProjectReference Include=\"../src/Example.fsproj\" />\n <ProjectReference Include=\"../lawspec/LawSpec.Testing/LawSpec.Testing.fsproj\" />\n <PackageReference Include=\"xunit.v3\" Version=\"4.0.2\" />\n </ItemGroup>\n</Project>\n"
|
|
222
|
+
},
|
|
223
|
+
"compact": {
|
|
224
|
+
"global.json": "{ \"test\": { \"runner\": \"Microsoft.Testing.Platform\" } }\n",
|
|
225
|
+
"Example.slnx": "<Solution>\n<Project Path=\"src/Example.fsproj\" />\n<Project Path=\"tests/Example.Tests.fsproj\" />\n<Project Path=\"lawspec/LawSpec.Runtime/LawSpec.Runtime.fsproj\" />\n<Project Path=\"lawspec/LawSpec.Testing/LawSpec.Testing.fsproj\" />\n</Solution>\n",
|
|
226
|
+
"src/Example.fsproj": "<Project Sdk=\"Microsoft.NET.Sdk\">\n<PropertyGroup>\n<TargetFramework>net10.0</TargetFramework>\n<RootNamespace>Example</RootNamespace>\n</PropertyGroup>\n<Import Project=\"LawSpec.Sources.props\" />\n<ItemGroup>\n<ProjectReference Include=\"../lawspec/LawSpec.Runtime/LawSpec.Runtime.fsproj\" />\n</ItemGroup>\n</Project>\n",
|
|
227
|
+
"tests/Example.Tests.fsproj": "<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</PropertyGroup>\n<Import Project=\"LawSpec.Tests.props\" />\n<ItemGroup>\n<ProjectReference Include=\"../src/Example.fsproj\" />\n<ProjectReference Include=\"../lawspec/LawSpec.Testing/LawSpec.Testing.fsproj\" />\n<PackageReference Include=\"xunit.v3\" Version=\"4.0.2\" />\n</ItemGroup>\n</Project>\n"
|
|
228
|
+
}
|
|
229
|
+
},
|
|
230
|
+
"csharp": {
|
|
231
|
+
"readable": {
|
|
232
|
+
"global.json": "{ \"test\": { \"runner\": \"Microsoft.Testing.Platform\" } }\n",
|
|
233
|
+
"Example.slnx": "<Solution>\n <Project Path=\"src/Example.csproj\" />\n <Project Path=\"tests/Example.Tests.csproj\" />\n <Project Path=\"lawspec/LawSpec.Runtime/LawSpec.Runtime.fsproj\" />\n <Project Path=\"lawspec/LawSpec.Testing/LawSpec.Testing.fsproj\" />\n <Project Path=\"lawspec/LawSpec.Model/LawSpec.Model.fsproj\" />\n</Solution>\n",
|
|
234
|
+
"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",
|
|
235
|
+
"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"
|
|
236
|
+
},
|
|
237
|
+
"compact": {
|
|
238
|
+
"global.json": "{ \"test\": { \"runner\": \"Microsoft.Testing.Platform\" } }\n",
|
|
239
|
+
"Example.slnx": "<Solution>\n<Project Path=\"src/Example.csproj\" />\n<Project Path=\"tests/Example.Tests.csproj\" />\n<Project Path=\"lawspec/LawSpec.Runtime/LawSpec.Runtime.fsproj\" />\n<Project Path=\"lawspec/LawSpec.Testing/LawSpec.Testing.fsproj\" />\n<Project Path=\"lawspec/LawSpec.Model/LawSpec.Model.fsproj\" />\n</Solution>\n",
|
|
240
|
+
"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
|
+
"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
|
+
}
|
|
112
243
|
}
|
|
113
244
|
};
|
|
114
245
|
|
package/test-command.mjs
CHANGED
|
@@ -9,19 +9,24 @@
|
|
|
9
9
|
// a law that calls adapters, every file in the target project that LawSpec
|
|
10
10
|
// did not generate. A passing run records each law's key and seed; a law runs
|
|
11
11
|
// again when its key changes or with --fresh.
|
|
12
|
-
import { createHash } from "node:crypto";
|
|
12
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
13
13
|
import { readdir, readFile, stat } from "node:fs/promises";
|
|
14
14
|
import path from "node:path";
|
|
15
15
|
|
|
16
16
|
// Folders that hold dependencies, build output or caches, not code under test.
|
|
17
|
-
const skipped = new Set([".git", ".lawspec", "node_modules", "dist", "build", "target", "out", ".gradle",
|
|
18
|
-
".stack-work", "__pycache__", ".hypothesis", ".pytest_cache", ".venv", "venv", ".idea", ".vscode"]);
|
|
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"]);
|
|
19
19
|
// Build and lock files, which choose the toolchain and dependencies.
|
|
20
20
|
const environmentFiles = ["package.json", "package-lock.json", "tsconfig.json", "pyproject.toml", "go.mod",
|
|
21
21
|
"go.sum", "pom.xml", "build.gradle", "build.gradle.kts", "settings.gradle", "settings.gradle.kts",
|
|
22
|
-
"Cargo.toml", "Cargo.lock", "stack.yaml", "stack.yaml.lock", "package.yaml"
|
|
22
|
+
"Cargo.toml", "Cargo.lock", "stack.yaml", "stack.yaml.lock", "package.yaml",
|
|
23
|
+
"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"];
|
|
23
25
|
|
|
24
26
|
const digest = (value) => createHash("sha256").update(value).digest("hex");
|
|
27
|
+
// The crypto builder owns these outputs. Inputs and other priv/ assets still
|
|
28
|
+
// contribute to the adapter digest; rebuilding the NIF cannot invalidate a pass.
|
|
29
|
+
const cryptoBuildOutput = (file) => /^priv\/lawspec_crypto_native\.(?:so|dll)(?:\.build|\.\d+\.tmp)?$/.test(file);
|
|
25
30
|
|
|
26
31
|
// Every file in a project that LawSpec did not generate, by content.
|
|
27
32
|
export async function projectDigest(root, generated) {
|
|
@@ -33,7 +38,7 @@ export async function projectDigest(root, generated) {
|
|
|
33
38
|
const relative = folder ? `${folder}/${entry.name}` : entry.name;
|
|
34
39
|
if (entry.isDirectory()) {
|
|
35
40
|
if (!skipped.has(entry.name) && !relative.endsWith("testdata/rapid")) await walk(relative);
|
|
36
|
-
} else if (entry.isFile() && !generated.has(relative)) {
|
|
41
|
+
} else if (entry.isFile() && !generated.has(relative) && !cryptoBuildOutput(relative)) {
|
|
37
42
|
hash.update(relative + "\0").update(await readFile(path.join(root, relative))).update("\0");
|
|
38
43
|
}
|
|
39
44
|
}
|
|
@@ -43,7 +48,10 @@ export async function projectDigest(root, generated) {
|
|
|
43
48
|
}
|
|
44
49
|
|
|
45
50
|
export async function environmentDigest(root, report) {
|
|
46
|
-
|
|
51
|
+
// Coverage locations describe build output; native tools can discover more
|
|
52
|
+
// output directories after the first run. Build configuration is hashed below.
|
|
53
|
+
const {coverage: _coverage, ...toolchain} = report ?? {};
|
|
54
|
+
const parts = [JSON.stringify(report ? toolchain : null)];
|
|
47
55
|
const names = (await readdir(root)).filter((name) => environmentFiles.includes(name) || name.endsWith(".cabal")).sort();
|
|
48
56
|
for (const name of names) parts.push(name, await readFile(path.join(root, name), "utf8"));
|
|
49
57
|
return digest(JSON.stringify(parts));
|
|
@@ -69,12 +77,16 @@ export async function recordedDigest(folder) {
|
|
|
69
77
|
}
|
|
70
78
|
|
|
71
79
|
// The result key of each law in a target's test manifest.
|
|
72
|
-
|
|
80
|
+
// A law an environment attestation touches is keyed by how its dependencies
|
|
81
|
+
// were wired too, so a run against other endpoints, or the real dependency
|
|
82
|
+
// in place of a stand-in, runs it again; other laws' keys are unchanged.
|
|
83
|
+
export function lawKeys({ build, target, machineBits, minify, tests, files, environment, project, attested = new Map() }) {
|
|
73
84
|
const contents = new Map(files.map((file) => [file.path, file.content]));
|
|
74
85
|
const configuration = JSON.stringify({ ...target, root: undefined });
|
|
75
86
|
return new Map(tests.map((entry) => [entry.law, digest(JSON.stringify([
|
|
76
87
|
build, configuration, machineBits, minify, entry.key, digest(contents.get(entry.file) ?? ""),
|
|
77
88
|
environment, entry.callsAdapters ? project : null,
|
|
89
|
+
...(attested.has(entry.law) ? [attested.get(entry.law)] : []),
|
|
78
90
|
]))]));
|
|
79
91
|
}
|
|
80
92
|
|
|
@@ -86,6 +98,14 @@ const groupBy = (entries, key) => {
|
|
|
86
98
|
return [...groups.entries()];
|
|
87
99
|
};
|
|
88
100
|
|
|
101
|
+
// Rebar and Mix run their configured compile hooks. Gleam has no corresponding
|
|
102
|
+
// hook, so build its generated crypto bridge before starting a native test VM.
|
|
103
|
+
export function preparationInvocations(target, files) {
|
|
104
|
+
return target.language === "gleam" && files.some((file) => file.path === "priv/lawspec_crypto_native.c")
|
|
105
|
+
? [{command: "escript", args: ["lawspec_crypto_build.escript"]}]
|
|
106
|
+
: [];
|
|
107
|
+
}
|
|
108
|
+
|
|
89
109
|
// The native invocations that run the harness's benchmarks (lawspec test
|
|
90
110
|
// --benchmarks): each target's test command, selecting the tests that
|
|
91
111
|
// measure them by the names the manifest gives (entry.name). Benchmarks are
|
|
@@ -100,6 +120,18 @@ export function benchmarkInvocations(target, entries, { offline = false } = {})
|
|
|
100
120
|
return file.startsWith(directory + "/") ? file.slice(directory.length + 1) : file;
|
|
101
121
|
};
|
|
102
122
|
const className = (file, defaultDir, extension) => without(relativeTo(file, defaultDir), extension).replaceAll("/", ".");
|
|
123
|
+
if (language === "erlang")
|
|
124
|
+
return entries.map((entry) => ({ command: "rebar3", args: ["eunit", "--generator",
|
|
125
|
+
`${path.posix.basename(entry.file, ".erl")}:${entry.name}_cases`] }));
|
|
126
|
+
if (language === "elixir")
|
|
127
|
+
return groupBy(entries, (entry) => entry.file).map(([file, marks]) => ({ command: "mix",
|
|
128
|
+
args: ["test", file, ...marks.flatMap((entry) => ["--only", `lawspec:${entry.name}`])] }));
|
|
129
|
+
if (language === "gleam")
|
|
130
|
+
return [{ command: "gleam", args: ["test", "--target", "erlang"], env: {
|
|
131
|
+
LAWSPEC_BEAM_BENCHMARKS: JSON.stringify(entries.map((entry) => ({
|
|
132
|
+
module: path.posix.basename(entry.file, ".gleam"), function: `${entry.name}__case_0_test`
|
|
133
|
+
})))
|
|
134
|
+
} }];
|
|
103
135
|
if (language === "python")
|
|
104
136
|
return groupBy(entries, (e) => e.file).map(([file, marks]) => ({ command: target.python || "python3",
|
|
105
137
|
args: ["-m", "pytest", "-q", "-s", file, "-k", marks.map((e) => e.name).join(" or ")] }));
|
|
@@ -127,6 +159,8 @@ export function benchmarkInvocations(target, entries, { offline = false } = {})
|
|
|
127
159
|
if (language === "rust")
|
|
128
160
|
return groupBy(entries, (e) => e.file).map(([file, marks]) => ({ command: "cargo",
|
|
129
161
|
args: ["test", ...(offline ? ["--offline"] : []), "--test", path.posix.basename(file, ".rs"), "--", "--exact", "--nocapture", ...marks.map((e) => e.name)] }));
|
|
162
|
+
if (language === "fsharp" || language === "csharp")
|
|
163
|
+
return [{ command: "dotnet", args: ["test", ...entries.flatMap((e) => ["--filter-query", `/*/*/*/${e.name}`])] }];
|
|
130
164
|
if (language === "haskell") {
|
|
131
165
|
const module = (e) => without(relativeTo(e.file, "test"), "Spec.hs").replaceAll("/", ".");
|
|
132
166
|
// hspec matches by substring, and a benchmark's name has spaces, so each
|
|
@@ -143,7 +177,9 @@ export function benchmarkInvocations(target, entries, { offline = false } = {})
|
|
|
143
177
|
// LawSpec.TestNames), then a kind after a separator no name contains, so one
|
|
144
178
|
// law's name never selects another's. `scratch` is a folder for reports;
|
|
145
179
|
// `coverage` asks each runner to measure coverage too (see coverageSetup).
|
|
146
|
-
export function invocations(target, entries, { offline = false, scratch = ".", coverage = null, xdist = false
|
|
180
|
+
export function invocations(target, entries, { offline = false, scratch = ".", coverage = null, xdist = false,
|
|
181
|
+
root = process.cwd(), coverageConfig } = {}) {
|
|
182
|
+
if (!entries.length) return [];
|
|
147
183
|
const language = target.language;
|
|
148
184
|
const testDir = target.testDir;
|
|
149
185
|
const relativeTo = (file, defaultDir) => {
|
|
@@ -152,6 +188,42 @@ export function invocations(target, entries, { offline = false, scratch = ".", c
|
|
|
152
188
|
};
|
|
153
189
|
const named = (entry) => new RegExp(`^${regex(entry.name)}_`);
|
|
154
190
|
const className = (file, defaultDir, extension) => without(relativeTo(file, defaultDir), extension).replaceAll("/", ".");
|
|
191
|
+
if (["erlang", "elixir", "gleam"].includes(language)) {
|
|
192
|
+
const run = randomUUID();
|
|
193
|
+
const file = path.join(scratch, `beam-${run}.jsonl`);
|
|
194
|
+
const identity = (entry) => `${entry.unit}::${entry.name}`;
|
|
195
|
+
const env = { LAWSPEC_BEAM_REPORT: file, LAWSPEC_BEAM_RUN: run };
|
|
196
|
+
const measured = coverage ? {run, file: path.resolve(coverage, "runs", `${run}.coverdata`),
|
|
197
|
+
...(language === "elixir" ? {beamDirectory: coverageConfig?.compilePath} : {}),
|
|
198
|
+
...(language === "erlang" ? {tool: "rebar3"} : {}),
|
|
199
|
+
...(language === "gleam" ? {metadata: path.resolve(coverage, "runs", `${run}.json`)} : {})} : null;
|
|
200
|
+
let command, args;
|
|
201
|
+
if (language === "elixir") {
|
|
202
|
+
command = "mix";
|
|
203
|
+
args = ["test", ...new Set(entries.map((entry) => entry.file)),
|
|
204
|
+
...entries.flatMap((entry) => ["--only", `lawspec_identity:${identity(entry)}`])];
|
|
205
|
+
if (measured) {
|
|
206
|
+
if (coverageConfig?.tool !== "Mix.Tasks.Test.Coverage" || !coverageConfig.output || !coverageConfig.compilePath)
|
|
207
|
+
throw new Error("BEAM coverage requires Mix.Tasks.Test.Coverage and its effective output directory from lawspec doctor");
|
|
208
|
+
args.push("--cover", "--export-coverage",
|
|
209
|
+
path.relative(path.resolve(root, coverageConfig.output), without(measured.file, ".coverdata")));
|
|
210
|
+
}
|
|
211
|
+
if (offline) env.HEX_OFFLINE = "1";
|
|
212
|
+
} else {
|
|
213
|
+
env.LAWSPEC_BEAM_LAWS = JSON.stringify(entries.map(({unit, name}) => ({unit, name})));
|
|
214
|
+
if (language === "erlang") {
|
|
215
|
+
command = "rebar3";
|
|
216
|
+
args = ["eunit", "--generator", "lawspec_generated_tests:lawspec_test_"];
|
|
217
|
+
if (measured) args.push("--cover", "--cover_export_name", without(measured.file, ".coverdata"));
|
|
218
|
+
} else {
|
|
219
|
+
command = "gleam";
|
|
220
|
+
args = ["test", "--target", "erlang"];
|
|
221
|
+
if (measured) env.LAWSPEC_BEAM_COVERAGE = JSON.stringify(measured);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
return [{ laws: entries, command, args, env, ...(measured ? {coverage: measured} : {}), report: {kind: "beam-events", file, run},
|
|
225
|
+
ran: (test) => test.status === "passed" ? entries.filter((entry) => test.identity === identity(entry)) : [] }];
|
|
226
|
+
}
|
|
155
227
|
if (language === "python")
|
|
156
228
|
return groupBy(entries, (e) => e.file).map(([file, laws], n) => {
|
|
157
229
|
const report = path.join(scratch, `pytest-${n}.xml`);
|
|
@@ -219,6 +291,22 @@ export function invocations(target, entries, { offline = false, scratch = ".", c
|
|
|
219
291
|
...laws.map((e) => e.name)],
|
|
220
292
|
report: { kind: "lines", pattern: /^test (\S+) \.\.\. (ok|FAILED|ignored)/ },
|
|
221
293
|
ran: (test) => laws.filter((e) => test.name === e.name) }));
|
|
294
|
+
// xUnit v3 on Microsoft.Testing.Platform selects test methods with its
|
|
295
|
+
// query filter (assembly/namespace/class/method, one per law, OR'd), and
|
|
296
|
+
// reports each test by its display name: the law's label, then its kind.
|
|
297
|
+
if (language === "fsharp" || language === "csharp") {
|
|
298
|
+
const report = "lawspec-junit.xml";
|
|
299
|
+
const results = path.resolve(scratch, "dotnet-results");
|
|
300
|
+
const kinds = "example \\d+: .*|boundary|statistics|property|search|replay|skipped|known failing";
|
|
301
|
+
const pattern = (e) => new RegExp(`^${regex(e.label)}( (${kinds}))?$`);
|
|
302
|
+
const measured = coverage ? path.resolve(coverage, "dotnet.cobertura.xml") : null;
|
|
303
|
+
return [{ laws: entries, command: "dotnet",
|
|
304
|
+
args: ["test", ...entries.flatMap((e) => ["--filter-query", `/*/*/*/${e.name}_*`, "--filter-query", `/*/*/*/${e.name}`]),
|
|
305
|
+
"--report-xunit-junit", "--report-xunit-junit-filename", report, "--results-directory", results,
|
|
306
|
+
...(measured ? ["--coverage", "--coverage-output-format", "cobertura", "--coverage-output", measured] : [])],
|
|
307
|
+
report: { kind: "junit", files: [path.join(results, report)] },
|
|
308
|
+
ran: (test) => entries.filter((e) => pattern(e).test(test.name)) }];
|
|
309
|
+
}
|
|
222
310
|
if (language === "haskell") {
|
|
223
311
|
const module = (e) => without(relativeTo(e.file, "test"), "Spec.hs").replaceAll("/", ".");
|
|
224
312
|
const matches = entries.map((e) => `${module(e)}/${e.name}_`);
|
|
@@ -232,6 +320,9 @@ export function invocations(target, entries, { offline = false, scratch = ".", c
|
|
|
232
320
|
|
|
233
321
|
// What --coverage needs on each target, and how to say it is missing.
|
|
234
322
|
export const coverageTools = {
|
|
323
|
+
erlang: { tool: "OTP cover", install: "install Erlang/OTP with the tools application" },
|
|
324
|
+
elixir: { tool: "OTP cover", install: "install Erlang/OTP with the tools application" },
|
|
325
|
+
gleam: { tool: "OTP cover", install: "install Erlang/OTP with the tools application" },
|
|
235
326
|
python: { tool: "coverage.py", check: ["-c", "import coverage"], install: "python -m pip install coverage" },
|
|
236
327
|
javascript: { tool: "c8", install: "npm install --save-dev c8" },
|
|
237
328
|
typescript: { tool: "c8", install: "npm install --save-dev c8" },
|
|
@@ -240,6 +331,8 @@ export const coverageTools = {
|
|
|
240
331
|
kotlin: { tool: "Kover", install: "add id(\"org.jetbrains.kotlinx.kover\") to the plugins of build.gradle.kts" },
|
|
241
332
|
rust: { tool: "cargo-llvm-cov", install: "cargo install cargo-llvm-cov" },
|
|
242
333
|
haskell: { tool: "hpc", install: "(built into GHC; stack test --coverage)" },
|
|
334
|
+
fsharp: { tool: "Microsoft code coverage", install: "add the Microsoft.Testing.Extensions.CodeCoverage package to the test project" },
|
|
335
|
+
csharp: { tool: "Microsoft code coverage", install: "add the Microsoft.Testing.Extensions.CodeCoverage package to the test project" },
|
|
243
336
|
};
|
|
244
337
|
|
|
245
338
|
// Laws selected by tag: every --tag, and none of --exclude-tag.
|
|
@@ -248,18 +341,73 @@ export function selectByTags(entries, include = [], exclude = []) {
|
|
|
248
341
|
!exclude.some((t) => (e.tags ?? []).includes(t)));
|
|
249
342
|
}
|
|
250
343
|
|
|
344
|
+
// A recorded failure takes precedence over any older passing cache entry,
|
|
345
|
+
// including when an adapter is repaired by restoring its previous contents.
|
|
346
|
+
export function testsToRun(entries, keys, previous, failures, {fresh = false, coverage = false, updateRecorded = false} = {}) {
|
|
347
|
+
return entries.filter((entry) => fresh || coverage || updateRecorded || failures[entry.law] ||
|
|
348
|
+
previous[entry.law]?.key !== keys.get(entry.law));
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
// Read complete outer elements, preserving nested suites and native payloads.
|
|
352
|
+
// Comments and CDATA can contain apparent XML tags; they are never elements.
|
|
353
|
+
function junitElements(xml, names) {
|
|
354
|
+
const elements = [];
|
|
355
|
+
let current;
|
|
356
|
+
const tags = /<!--[\s\S]*?-->|<!\[CDATA\[[\s\S]*?\]\]>|<\?[\s\S]*?\?>|<(\/?)([A-Za-z_][\w:.-]*)(?:[^"'<>]|"[^"]*"|'[^']*')*>/g;
|
|
357
|
+
for (const tag of xml.matchAll(tags)) {
|
|
358
|
+
const [, closing, name] = tag;
|
|
359
|
+
if (!name || !names.includes(name)) continue;
|
|
360
|
+
const empty = /\/\s*>$/.test(tag[0]);
|
|
361
|
+
if (!current) {
|
|
362
|
+
if (closing) continue;
|
|
363
|
+
current = {name, start: tag.index, opening: tag[0], depth: 0};
|
|
364
|
+
}
|
|
365
|
+
if (name !== current.name) continue;
|
|
366
|
+
current.depth += closing ? -1 : empty ? 0 : 1;
|
|
367
|
+
if (current.depth === 0) {
|
|
368
|
+
elements.push({...current, xml: xml.slice(current.start, tag.index + tag[0].length)});
|
|
369
|
+
current = undefined;
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
return elements;
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
function junitCounts(cases) {
|
|
376
|
+
const statuses = cases.map(test => new Set(junitElements(test.xml, ["failure", "error", "skipped"]).map(e => e.name)));
|
|
377
|
+
return {tests: cases.length, ...Object.fromEntries(["failure", "error", "skipped"].map(name =>
|
|
378
|
+
[name === "skipped" ? name : `${name}s`, statuses.filter(status => status.has(name)).length]))};
|
|
379
|
+
}
|
|
380
|
+
|
|
251
381
|
// One JUnit report from every target's: each target's suites, renamed with
|
|
252
382
|
// the target, in one <testsuites>.
|
|
253
383
|
export function mergeJunit(reports) {
|
|
254
384
|
const suites = [];
|
|
385
|
+
const totals = {tests: 0, failures: 0, errors: 0, skipped: 0};
|
|
255
386
|
for (const { target, xml } of reports) {
|
|
256
|
-
const
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
387
|
+
const elements = junitElements(xml, ["testsuite", "testcase"]);
|
|
388
|
+
const found = elements.filter(e => e.name === "testsuite");
|
|
389
|
+
// Node's native JUnit reporter puts top-level tests directly in testsuites.
|
|
390
|
+
// Keep those cases (and their native failure payloads) instead of silently
|
|
391
|
+
// dropping them because they have no intervening testsuite element.
|
|
392
|
+
const loose = elements.filter(e => e.name === "testcase");
|
|
393
|
+
if (loose.length) {
|
|
394
|
+
const opening = `<testsuite name="native" ${Object.entries(junitCounts(loose)).map(([key, value]) => `${key}="${value}"`).join(" ")}>`;
|
|
395
|
+
found.push({opening, xml: opening + "\n" + loose.map(e => e.xml).join("\n") + "\n</testsuite>"});
|
|
396
|
+
}
|
|
397
|
+
for (const suite of found) {
|
|
398
|
+
const attributes = [...suite.opening.matchAll(/\s([A-Za-z_:][\w:.-]*)\s*=\s*(?:"([^"]*)"|'([^']*)')/g)];
|
|
399
|
+
const values = Object.fromEntries(attributes.map(match => [match[1], match[2] ?? match[3]]));
|
|
400
|
+
const counts = junitCounts(junitElements(suite.xml, ["testcase"]));
|
|
401
|
+
for (const key of Object.keys(totals))
|
|
402
|
+
totals[key] += /^\d+$/.test(values[key] ?? "") ? Number(values[key]) : counts[key];
|
|
403
|
+
const name = attributes.find(match => match[1] === "name");
|
|
404
|
+
const opening = name
|
|
405
|
+
? suite.opening.slice(0, name.index) + ` name="${escapeXml(target)}: ${values.name.replaceAll('"', '"')}"` + suite.opening.slice(name.index + name[0].length)
|
|
406
|
+
: suite.opening.replace(/^<testsuite\b/, `<testsuite name="${escapeXml(target)}"`);
|
|
407
|
+
suites.push(opening + suite.xml.slice(suite.opening.length));
|
|
408
|
+
}
|
|
260
409
|
}
|
|
261
|
-
|
|
262
|
-
return `<?xml version="1.0" encoding="UTF-8"?>\n<testsuites tests="${count("tests")}" failures="${count("failures")}" errors="${count("errors")}" skipped="${count("skipped")}">\n` +
|
|
410
|
+
return `<?xml version="1.0" encoding="UTF-8"?>\n<testsuites tests="${totals.tests}" failures="${totals.failures}" errors="${totals.errors}" skipped="${totals.skipped}">\n` +
|
|
263
411
|
suites.join("\n") + "\n</testsuites>\n";
|
|
264
412
|
}
|
|
265
413
|
|
|
@@ -278,6 +426,20 @@ export async function harnessStatistics(directory) {
|
|
|
278
426
|
// The tests a run executed, as {name, classname}, from the runner's report or
|
|
279
427
|
// output. Skipped tests are not counted.
|
|
280
428
|
export async function executedTests(report, output, root, since) {
|
|
429
|
+
if (report?.kind === "beam-events") {
|
|
430
|
+
// A native listener seals the invocation after its final event. Missing,
|
|
431
|
+
// stale, malformed or interrupted reports are not execution evidence.
|
|
432
|
+
const raw = await readFile(path.resolve(root, report.file), "utf8").catch(() => "");
|
|
433
|
+
let rows;
|
|
434
|
+
try { rows = raw.trim().split("\n").map((line) => JSON.parse(line)); } catch { return []; }
|
|
435
|
+
if (rows.length < 2 || rows[0]?.event !== "start" || rows.at(-1)?.event !== "end" ||
|
|
436
|
+
rows.some((row) => row?.run !== report.run)) return [];
|
|
437
|
+
const tests = rows.slice(1, -1);
|
|
438
|
+
if (tests.some((row) => row.event !== "test" || !["passed", "failed"].includes(row.status) ||
|
|
439
|
+
typeof row.name !== "string" || typeof row.classname !== "string" || typeof row.identity !== "string" ||
|
|
440
|
+
!Number.isFinite(row.time) || row.time < 0)) return [];
|
|
441
|
+
return tests;
|
|
442
|
+
}
|
|
281
443
|
if (report?.kind === "junit") {
|
|
282
444
|
const files = report.files ?? await reportFiles(path.join(root, report.directory), since);
|
|
283
445
|
const tests = [];
|
|
@@ -321,9 +483,18 @@ export async function executedTests(report, output, root, since) {
|
|
|
321
483
|
// JUnit XML for a runner that writes none, from the tests it printed.
|
|
322
484
|
export function junitFromTests(tests) {
|
|
323
485
|
const failures = tests.filter((t) => t.status === "failed").length;
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
486
|
+
const skipped = tests.filter((t) => t.status === "skipped").length;
|
|
487
|
+
// A BEAM scheduler wraps native functions from several units. Its module
|
|
488
|
+
// is not the declaring class: retain the unit from the validated identity.
|
|
489
|
+
const classname = (test) => {
|
|
490
|
+
const separator = typeof test.identity === "string" ? test.identity.lastIndexOf("::") : -1;
|
|
491
|
+
return separator > 0 ? test.identity.slice(0, separator) : test.classname ?? "";
|
|
492
|
+
};
|
|
493
|
+
return `<testsuite name="lawspec" tests="${tests.length}" failures="${failures}"${skipped ? ` skipped="${skipped}"` : ""}>\n` +
|
|
494
|
+
tests.map((t) => ` <testcase classname="${escapeXml(classname(t))}" name="${escapeXml(t.name)}"` +
|
|
495
|
+
(Number.isFinite(t.time) ? ` time="${t.time}"` : "") +
|
|
496
|
+
(t.status === "failed" ? `><failure message="${escapeXml(t.failure ?? "failed")}"/></testcase>` :
|
|
497
|
+
t.status === "skipped" ? `><skipped message="${escapeXml(t.reason ?? "skipped")}"/></testcase>` : "/>")).join("\n") + "\n</testsuite>";
|
|
327
498
|
}
|
|
328
499
|
|
|
329
500
|
async function reportFiles(directory, since) {
|