lawspec 0.22.0 → 0.24.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 +358 -2
- package/README.md +3 -3
- package/bin/lawspec.mjs +95 -14
- package/build.json +314 -120
- package/compatibility.json +29 -0
- package/core.wasm +2 -2
- package/doctor.mjs +119 -1
- package/examples/native-payments/clojure/lawspec.json +51 -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 +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/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/groovy/lawspec.json +165 -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/scala/lawspec.json +165 -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 +154 -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/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/index.d.ts +40 -1
- package/package.json +2 -2
- package/scala-coverage.mjs +56 -0
- package/templates.mjs +107 -3
- package/test-command.mjs +105 -4
package/templates.mjs
CHANGED
|
@@ -12,7 +12,13 @@ export const targets = [
|
|
|
12
12
|
"rust",
|
|
13
13
|
"erlang",
|
|
14
14
|
"elixir",
|
|
15
|
-
"gleam"
|
|
15
|
+
"gleam",
|
|
16
|
+
"fsharp",
|
|
17
|
+
"csharp",
|
|
18
|
+
"scala",
|
|
19
|
+
"groovy",
|
|
20
|
+
"clojure",
|
|
21
|
+
"swift"
|
|
16
22
|
];
|
|
17
23
|
export const targetLabels = [
|
|
18
24
|
[
|
|
@@ -58,6 +64,30 @@ export const targetLabels = [
|
|
|
58
64
|
[
|
|
59
65
|
"gleam",
|
|
60
66
|
"Gleam"
|
|
67
|
+
],
|
|
68
|
+
[
|
|
69
|
+
"fsharp",
|
|
70
|
+
"F#"
|
|
71
|
+
],
|
|
72
|
+
[
|
|
73
|
+
"csharp",
|
|
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"
|
|
61
91
|
]
|
|
62
92
|
];
|
|
63
93
|
|
|
@@ -72,7 +102,13 @@ export const commands = {
|
|
|
72
102
|
"rust": "cargo test",
|
|
73
103
|
"erlang": "rebar3 eunit",
|
|
74
104
|
"elixir": "mix test",
|
|
75
|
-
"gleam": "gleam test"
|
|
105
|
+
"gleam": "gleam test",
|
|
106
|
+
"fsharp": "dotnet test",
|
|
107
|
+
"csharp": "dotnet test",
|
|
108
|
+
"scala": "scala test .",
|
|
109
|
+
"groovy": "gradle test",
|
|
110
|
+
"clojure": "clojure -M:test",
|
|
111
|
+
"swift": "swift test"
|
|
76
112
|
};
|
|
77
113
|
|
|
78
114
|
export const setup = {
|
|
@@ -86,7 +122,13 @@ export const setup = {
|
|
|
86
122
|
"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.",
|
|
87
123
|
"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.",
|
|
88
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.",
|
|
89
|
-
"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."
|
|
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.",
|
|
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.",
|
|
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."
|
|
90
132
|
};
|
|
91
133
|
|
|
92
134
|
// Each target's build files in the readable and the compact (minified) layout.
|
|
@@ -198,6 +240,68 @@ const scaffolds = {
|
|
|
198
240
|
"test-support/src/.gitkeep": "",
|
|
199
241
|
"test/lawspec_example_test.gleam": "@external(erlang, \"lawspec_beam_test_run\", \"gleam_main\")\npub fn main() -> Nil\n"
|
|
200
242
|
}
|
|
243
|
+
},
|
|
244
|
+
"fsharp": {
|
|
245
|
+
"readable": {
|
|
246
|
+
"global.json": "{ \"test\": { \"runner\": \"Microsoft.Testing.Platform\" } }\n",
|
|
247
|
+
"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",
|
|
248
|
+
"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",
|
|
249
|
+
"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"
|
|
250
|
+
},
|
|
251
|
+
"compact": {
|
|
252
|
+
"global.json": "{ \"test\": { \"runner\": \"Microsoft.Testing.Platform\" } }\n",
|
|
253
|
+
"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",
|
|
254
|
+
"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",
|
|
255
|
+
"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"
|
|
256
|
+
}
|
|
257
|
+
},
|
|
258
|
+
"csharp": {
|
|
259
|
+
"readable": {
|
|
260
|
+
"global.json": "{ \"test\": { \"runner\": \"Microsoft.Testing.Platform\" } }\n",
|
|
261
|
+
"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",
|
|
262
|
+
"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",
|
|
263
|
+
"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"
|
|
264
|
+
},
|
|
265
|
+
"compact": {
|
|
266
|
+
"global.json": "{ \"test\": { \"runner\": \"Microsoft.Testing.Platform\" } }\n",
|
|
267
|
+
"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",
|
|
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",
|
|
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"
|
|
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\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'] } } }\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
|
+
}
|
|
201
305
|
}
|
|
202
306
|
};
|
|
203
307
|
|
package/test-command.mjs
CHANGED
|
@@ -14,13 +14,15 @@ 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", "_build", "deps", ".elixir_ls", "__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
|
+
".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
|
-
"rebar.config", "rebar.config.script", "rebar.lock", "mix.exs", "mix.lock", "gleam.toml", "manifest.toml"
|
|
24
|
+
"rebar.config", "rebar.config.script", "rebar.lock", "mix.exs", "mix.lock", "gleam.toml", "manifest.toml",
|
|
25
|
+
"global.json", "Directory.Build.props", "Directory.Packages.props", "NuGet.config", "project.scala", "Package.swift", "Package.resolved"];
|
|
24
26
|
|
|
25
27
|
const digest = (value) => createHash("sha256").update(value).digest("hex");
|
|
26
28
|
// The crypto builder owns these outputs. Inputs and other priv/ assets still
|
|
@@ -76,12 +78,16 @@ export async function recordedDigest(folder) {
|
|
|
76
78
|
}
|
|
77
79
|
|
|
78
80
|
// The result key of each law in a target's test manifest.
|
|
79
|
-
|
|
81
|
+
// A law an environment attestation touches is keyed by how its dependencies
|
|
82
|
+
// were wired too, so a run against other endpoints, or the real dependency
|
|
83
|
+
// in place of a stand-in, runs it again; other laws' keys are unchanged.
|
|
84
|
+
export function lawKeys({ build, target, machineBits, minify, tests, files, environment, project, attested = new Map() }) {
|
|
80
85
|
const contents = new Map(files.map((file) => [file.path, file.content]));
|
|
81
86
|
const configuration = JSON.stringify({ ...target, root: undefined });
|
|
82
87
|
return new Map(tests.map((entry) => [entry.law, digest(JSON.stringify([
|
|
83
88
|
build, configuration, machineBits, minify, entry.key, digest(contents.get(entry.file) ?? ""),
|
|
84
89
|
environment, entry.callsAdapters ? project : null,
|
|
90
|
+
...(attested.has(entry.law) ? [attested.get(entry.law)] : []),
|
|
85
91
|
]))]));
|
|
86
92
|
}
|
|
87
93
|
|
|
@@ -151,9 +157,30 @@ export function benchmarkInvocations(target, entries, { offline = false } = {})
|
|
|
151
157
|
args: [...(offline ? ["--offline"] : []), "--console=plain", "test", "--rerun", "--tests", className(file, "src/test/kotlin", ".kt")],
|
|
152
158
|
env: { "kotest.filter.tests": filter, kotest_filter_tests: filter } };
|
|
153
159
|
});
|
|
160
|
+
// The Clojure runner selects tests by namespace and name prefix.
|
|
161
|
+
if (language === "clojure") {
|
|
162
|
+
const ns = (file) => without(relativeTo(file, "test"), ".clj").replaceAll("/", ".").replaceAll("_", "-");
|
|
163
|
+
return [{ command: target.clojure || "clojure",
|
|
164
|
+
args: ["-M:test", ...entries.flatMap((e) => ["--select", `${ns(e.file)}/${e.name}`])] }];
|
|
165
|
+
}
|
|
166
|
+
// Spock names each feature in words; Gradle's filters select it by name.
|
|
167
|
+
if (language === "groovy")
|
|
168
|
+
return [{ command: target.gradle || "gradle",
|
|
169
|
+
args: [...(offline ? ["--offline"] : []), "--console=plain", "test", "--rerun",
|
|
170
|
+
...entries.flatMap((e) => ["--tests", `${className(e.file, "src/test/groovy", ".groovy")}.${e.name}`])] }];
|
|
154
171
|
if (language === "rust")
|
|
155
172
|
return groupBy(entries, (e) => e.file).map(([file, marks]) => ({ command: "cargo",
|
|
156
173
|
args: ["test", ...(offline ? ["--offline"] : []), "--test", path.posix.basename(file, ".rs"), "--", "--exact", "--nocapture", ...marks.map((e) => e.name)] }));
|
|
174
|
+
if (language === "fsharp" || language === "csharp")
|
|
175
|
+
return [{ command: "dotnet", args: ["test", ...entries.flatMap((e) => ["--filter-query", `/*/*/*/${e.name}`])] }];
|
|
176
|
+
if (language === "scala")
|
|
177
|
+
return groupBy(entries, (e) => e.file).map(([file, marks]) => ({ command: target.scala || "scala",
|
|
178
|
+
args: ["test", ".", ...(offline ? ["--offline"] : []), "--test-only", className(file, "src/test/scala", ".scala"), "--",
|
|
179
|
+
...marks.flatMap((e) => ["-z", e.name])] }));
|
|
180
|
+
// Swift Testing selects tests by a regular expression over their ids
|
|
181
|
+
// (Module.Suite/function()), one --filter per benchmark, OR'd.
|
|
182
|
+
if (language === "swift")
|
|
183
|
+
return [{ command: target.swift || "swift", args: ["test", ...entries.flatMap((e) => ["--filter", `/${regex(e.name)}\\(`])] }];
|
|
157
184
|
if (language === "haskell") {
|
|
158
185
|
const module = (e) => without(relativeTo(e.file, "test"), "Spec.hs").replaceAll("/", ".");
|
|
159
186
|
// hspec matches by substring, and a benchmark's name has spaces, so each
|
|
@@ -277,6 +304,43 @@ export function invocations(target, entries, { offline = false, scratch = ".", c
|
|
|
277
304
|
report: { kind: "junit", directory: "build/test-results/test" },
|
|
278
305
|
ran: (test) => laws.filter((e) => test.classname === name && named(e).test(test.name)) };
|
|
279
306
|
});
|
|
307
|
+
// ScalaTest selects tests by substring (-z): each law's tests are named
|
|
308
|
+
// after it, then a kind after a separator no name contains. Its JUnit
|
|
309
|
+
// reporter writes one file per suite (-u).
|
|
310
|
+
if (language === "scala")
|
|
311
|
+
return groupBy(entries, (e) => e.file).map(([file, laws], n) => {
|
|
312
|
+
const name = className(file, "src/test/scala", ".scala");
|
|
313
|
+
const directory = path.join(scratch, `scalatest-${n}`);
|
|
314
|
+
// --coverage: Scala 3 instruments the code (scoverage's format).
|
|
315
|
+
// The tests themselves are not measured.
|
|
316
|
+
const testRoot = target.testDir || "src/test/scala";
|
|
317
|
+
const measured = coverage ? ["-O", `-coverage-out:${path.resolve(coverage, "data")}`,
|
|
318
|
+
"-O", `-coverage-exclude-files:.*/${testRoot.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}/.*`] : [];
|
|
319
|
+
return { laws, command: target.scala || "scala",
|
|
320
|
+
args: ["test", ".", ...(offline ? ["--offline"] : []), ...measured, "--test-only", name, "--",
|
|
321
|
+
...laws.flatMap((e) => ["-z", `${e.name}_`]), "-u", directory],
|
|
322
|
+
report: { kind: "junit", directory: path.relative(root, directory) || "." },
|
|
323
|
+
ran: (test) => laws.filter((e) => test.classname === name && named(e).test(test.name)) };
|
|
324
|
+
});
|
|
325
|
+
// A Clojure test is the law's words, a double dash and the kind of test
|
|
326
|
+
// (LawSpec.TestNames); the runner selects tests by namespace and prefix.
|
|
327
|
+
if (language === "clojure") {
|
|
328
|
+
const ns = (e) => without(relativeTo(e.file, "test"), ".clj").replaceAll("/", ".").replaceAll("_", "-");
|
|
329
|
+
return [{ laws: entries, command: target.clojure || "clojure",
|
|
330
|
+
args: ["-M:test", ...entries.flatMap((e) => ["--select", `${ns(e)}/${e.name}--`])],
|
|
331
|
+
report: { kind: "junit", directory: "target/test-results" },
|
|
332
|
+
ran: (test) => entries.filter((e) => test.classname === ns(e) && test.name.startsWith(`${e.name}--`)) }];
|
|
333
|
+
}
|
|
334
|
+
// A Spock feature is the law's words, a colon and the kind of test
|
|
335
|
+
// (LawSpec.TestNames), so "name: *" selects one law's features only.
|
|
336
|
+
if (language === "groovy") {
|
|
337
|
+
const name = (e) => className(e.file, "src/test/groovy", ".groovy");
|
|
338
|
+
return [{ laws: entries, command: target.gradle || "gradle",
|
|
339
|
+
args: [...(offline ? ["--offline"] : []), "--console=plain", "test", ...(coverage ? ["jacocoTestReport"] : []), "--rerun",
|
|
340
|
+
...entries.flatMap((e) => ["--tests", `${name(e)}.${e.name}: *`])],
|
|
341
|
+
report: { kind: "junit", directory: "build/test-results/test" },
|
|
342
|
+
ran: (test) => entries.filter((e) => test.classname === name(e) && test.name.startsWith(`${e.name}: `)) }];
|
|
343
|
+
}
|
|
280
344
|
if (language === "rust")
|
|
281
345
|
return groupBy(entries, (e) => e.file).map(([file, laws]) => ({
|
|
282
346
|
laws, command: "cargo",
|
|
@@ -284,6 +348,37 @@ export function invocations(target, entries, { offline = false, scratch = ".", c
|
|
|
284
348
|
...laws.map((e) => e.name)],
|
|
285
349
|
report: { kind: "lines", pattern: /^test (\S+) \.\.\. (ok|FAILED|ignored)/ },
|
|
286
350
|
ran: (test) => laws.filter((e) => test.name === e.name) }));
|
|
351
|
+
// xUnit v3 on Microsoft.Testing.Platform selects test methods with its
|
|
352
|
+
// query filter (assembly/namespace/class/method, one per law, OR'd), and
|
|
353
|
+
// reports each test by its display name: the law's label, then its kind.
|
|
354
|
+
if (language === "fsharp" || language === "csharp") {
|
|
355
|
+
const report = "lawspec-junit.xml";
|
|
356
|
+
const results = path.resolve(scratch, "dotnet-results");
|
|
357
|
+
const kinds = "example \\d+: .*|boundary|statistics|property|search|replay|skipped|known failing";
|
|
358
|
+
const pattern = (e) => new RegExp(`^${regex(e.label)}( (${kinds}))?$`);
|
|
359
|
+
const measured = coverage ? path.resolve(coverage, "dotnet.cobertura.xml") : null;
|
|
360
|
+
return [{ laws: entries, command: "dotnet",
|
|
361
|
+
args: ["test", ...entries.flatMap((e) => ["--filter-query", `/*/*/*/${e.name}_*`, "--filter-query", `/*/*/*/${e.name}`]),
|
|
362
|
+
"--report-xunit-junit", "--report-xunit-junit-filename", report, "--results-directory", results,
|
|
363
|
+
...(measured ? ["--coverage", "--coverage-output-format", "cobertura", "--coverage-output", measured] : [])],
|
|
364
|
+
report: { kind: "junit", files: [path.join(results, report)] },
|
|
365
|
+
ran: (test) => entries.filter((e) => pattern(e).test(test.name)) }];
|
|
366
|
+
}
|
|
367
|
+
// Swift Testing selects tests by a regular expression over their ids
|
|
368
|
+
// (Module.Suite/function()), and writes its xUnit report next to the path
|
|
369
|
+
// given, with -swift-testing added. A law's tests are its unit's suite
|
|
370
|
+
// (named after the test file) and its name, then a kind (lawName_property).
|
|
371
|
+
if (language === "swift") {
|
|
372
|
+
const results = path.resolve(scratch);
|
|
373
|
+
const suite = (e) => path.posix.basename(e.file, ".swift");
|
|
374
|
+
const test = (e) => `${regex(suite(e))}/${regex(e.name)}(_[A-Za-z0-9]+)?\\(`;
|
|
375
|
+
return [{ laws: entries, command: target.swift || "swift",
|
|
376
|
+
args: ["test", ...(coverage ? ["--enable-code-coverage"] : []), ...entries.flatMap((e) => ["--filter", test(e)]),
|
|
377
|
+
"--xunit-output", path.join(results, "swift-lawspec.xml")],
|
|
378
|
+
report: { kind: "junit", files: [path.join(results, "swift-lawspec-swift-testing.xml")] },
|
|
379
|
+
ran: (result) => entries.filter((e) => result.classname?.split(".").pop() === suite(e) &&
|
|
380
|
+
new RegExp(`^${regex(e.name)}(_[A-Za-z0-9]+)?(\\(|$)`).test(result.name)) }];
|
|
381
|
+
}
|
|
287
382
|
if (language === "haskell") {
|
|
288
383
|
const module = (e) => without(relativeTo(e.file, "test"), "Spec.hs").replaceAll("/", ".");
|
|
289
384
|
const matches = entries.map((e) => `${module(e)}/${e.name}_`);
|
|
@@ -306,8 +401,14 @@ export const coverageTools = {
|
|
|
306
401
|
go: { tool: "go test -cover", install: "(built in)" },
|
|
307
402
|
java: { tool: "JaCoCo", install: "(resolved by Maven as org.jacoco:jacoco-maven-plugin)" },
|
|
308
403
|
kotlin: { tool: "Kover", install: "add id(\"org.jetbrains.kotlinx.kover\") to the plugins of build.gradle.kts" },
|
|
404
|
+
clojure: { tool: "cloverage", install: "add cloverage to a :coverage alias in deps.edn" },
|
|
405
|
+
groovy: { tool: "JaCoCo", install: "add id 'jacoco' to the plugins of build.gradle" },
|
|
309
406
|
rust: { tool: "cargo-llvm-cov", install: "cargo install cargo-llvm-cov" },
|
|
310
407
|
haskell: { tool: "hpc", install: "(built into GHC; stack test --coverage)" },
|
|
408
|
+
fsharp: { tool: "Microsoft code coverage", install: "add the Microsoft.Testing.Extensions.CodeCoverage package to the test project" },
|
|
409
|
+
csharp: { tool: "Microsoft code coverage", install: "add the Microsoft.Testing.Extensions.CodeCoverage package to the test project" },
|
|
410
|
+
scala: { tool: "scoverage", install: "(built into Scala 3; Scala CLI fetches the scoverage reporter)" },
|
|
411
|
+
swift: { tool: "llvm-cov", install: "(built into the Swift toolchain; swift test --enable-code-coverage)" },
|
|
311
412
|
};
|
|
312
413
|
|
|
313
414
|
// Laws selected by tag: every --tag, and none of --exclude-tag.
|