lawspec 0.23.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.
@@ -0,0 +1,154 @@
1
+ {
2
+ "version": 1,
3
+ "sources": [
4
+ "laws"
5
+ ],
6
+ "machineBits": 64,
7
+ "targets": [
8
+ {
9
+ "language": "swift",
10
+ "root": ".",
11
+ "nativeBindings": {
12
+ "types": [
13
+ {
14
+ "type": "example.payments::type::Currency",
15
+ "native": [
16
+ "PaymentsDomain",
17
+ "CurrencyCode"
18
+ ],
19
+ "constructors": [
20
+ {
21
+ "constructor": "USD",
22
+ "native": [
23
+ "PaymentsDomain",
24
+ "CurrencyCode",
25
+ "dollars"
26
+ ],
27
+ "style": "unit",
28
+ "fields": []
29
+ },
30
+ {
31
+ "constructor": "EUR",
32
+ "native": [
33
+ "PaymentsDomain",
34
+ "CurrencyCode",
35
+ "euros"
36
+ ],
37
+ "style": "unit",
38
+ "fields": []
39
+ },
40
+ {
41
+ "constructor": "GBP",
42
+ "native": [
43
+ "PaymentsDomain",
44
+ "CurrencyCode",
45
+ "pounds"
46
+ ],
47
+ "style": "unit",
48
+ "fields": []
49
+ }
50
+ ]
51
+ },
52
+ {
53
+ "type": "example.payments::type::Money",
54
+ "native": [
55
+ "PaymentsDomain",
56
+ "Price"
57
+ ],
58
+ "constructors": [
59
+ {
60
+ "constructor": "Money",
61
+ "native": [
62
+ "PaymentsDomain",
63
+ "Price"
64
+ ],
65
+ "style": "record",
66
+ "fields": [
67
+ {
68
+ "field": "amount",
69
+ "native": "major"
70
+ },
71
+ {
72
+ "field": "currency",
73
+ "native": "unit"
74
+ }
75
+ ]
76
+ }
77
+ ]
78
+ },
79
+ {
80
+ "type": "example.payments::type::Payment",
81
+ "native": [
82
+ "PaymentsDomain",
83
+ "PaymentStatus"
84
+ ],
85
+ "constructors": [
86
+ {
87
+ "constructor": "Paid",
88
+ "native": [
89
+ "PaymentsDomain",
90
+ "PaymentStatus",
91
+ "settled"
92
+ ],
93
+ "style": "variant",
94
+ "fields": [
95
+ {
96
+ "field": "value",
97
+ "native": "price"
98
+ }
99
+ ]
100
+ },
101
+ {
102
+ "constructor": "Declined",
103
+ "native": [
104
+ "PaymentsDomain",
105
+ "PaymentStatus",
106
+ "rejected"
107
+ ],
108
+ "style": "variant",
109
+ "fields": [
110
+ {
111
+ "field": "reason",
112
+ "native": "explanation"
113
+ }
114
+ ]
115
+ }
116
+ ]
117
+ }
118
+ ],
119
+ "functions": [
120
+ {
121
+ "declaration": "example.payments::addFee",
122
+ "native": [
123
+ "PaymentsDomain",
124
+ "applyFee"
125
+ ]
126
+ },
127
+ {
128
+ "declaration": "example.payments::roundTrip",
129
+ "native": [
130
+ "PaymentsDomain",
131
+ "restore"
132
+ ]
133
+ },
134
+ {
135
+ "declaration": "example.payments::archive",
136
+ "native": [
137
+ "PaymentsDomain",
138
+ "store"
139
+ ]
140
+ }
141
+ ],
142
+ "generators": [
143
+ {
144
+ "type": "example.payments::type::Money",
145
+ "factory": [
146
+ "PaymentGenerators",
147
+ "prices"
148
+ ]
149
+ }
150
+ ]
151
+ }
152
+ }
153
+ ]
154
+ }
@@ -0,0 +1,35 @@
1
+ // Application types, independent of generated LawSpec domain declarations.
2
+ import LawSpecRuntime
3
+
4
+ public enum PaymentsDomain {
5
+ public enum CurrencyCode: Sendable {
6
+ case dollars
7
+ case euros
8
+ case pounds
9
+ }
10
+
11
+ public struct Price: Sendable {
12
+ public var major: ExactDecimal
13
+ public var unit: CurrencyCode
14
+
15
+ public init(major: ExactDecimal, unit: CurrencyCode) {
16
+ self.major = major
17
+ self.unit = unit
18
+ }
19
+ }
20
+
21
+ public enum PaymentStatus: Sendable {
22
+ case settled(price: Price)
23
+ case rejected(explanation: String)
24
+ }
25
+
26
+ private static let fee = ExactDecimal(coefficient: 2, exponent: -1)
27
+
28
+ public static func applyFee(_ price: Price) -> Price {
29
+ Price(major: price.major + fee, unit: price.unit)
30
+ }
31
+
32
+ public static func restore(_ payment: PaymentStatus) -> PaymentStatus { payment }
33
+
34
+ public static func store(_ payments: PersistentList<PaymentStatus?>) -> PersistentList<PaymentStatus?> { payments }
35
+ }
@@ -0,0 +1,12 @@
1
+ // Prices the application considers representative: 1.00 to 2.00 euros.
2
+ import App
3
+ import LawSpecRuntime
4
+ import LawSpecTesting
5
+
6
+ enum PaymentGenerators {
7
+ static func prices() -> Gen<PaymentsDomain.Price> {
8
+ Gens.range(100, 200).map { cents in
9
+ PaymentsDomain.Price(major: ExactDecimal(coefficient: BigInt(cents), exponent: -2), unit: .euros)
10
+ }
11
+ }
12
+ }
package/index.d.ts CHANGED
@@ -12,7 +12,11 @@ export type Target =
12
12
  'elixir' |
13
13
  'gleam' |
14
14
  'fsharp' |
15
- 'csharp';
15
+ 'csharp' |
16
+ 'scala' |
17
+ 'groovy' |
18
+ 'clojure' |
19
+ 'swift';
16
20
 
17
21
  export interface Source {
18
22
  path: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lawspec",
3
- "version": "0.23.0",
3
+ "version": "0.24.0",
4
4
  "description": "State the law once. Check it everywhere.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -0,0 +1,56 @@
1
+ // Generated from templates/npm/scala-coverage.mjs by lawspec-dev generate. Do not edit.
2
+ // lawspec test --coverage on Scala: Scala 3 instruments the code itself
3
+ // (-coverage-out, in scoverage's format) and the scoverage reporter, which
4
+ // Scala CLI fetches, writes Cobertura, scoverage XML and HTML reports.
5
+ import {mkdir, readdir, writeFile} from "node:fs/promises";
6
+ import {spawn} from "node:child_process";
7
+ import path from "node:path";
8
+
9
+ export const scoverageReporter = "2.5.2";
10
+
11
+ // The report script, run by Scala CLI on its own (not as part of the project).
12
+ const reportScript = [
13
+ "//> using scala 3.9.0",
14
+ `//> using dep org.scoverage::scalac-scoverage-reporter:${scoverageReporter}`,
15
+ "//> using javaOpt --sun-misc-unsafe-memory-access=allow",
16
+ "import java.io.File",
17
+ "import scoverage.reporter.{CoberturaXmlWriter, IOUtils, ScoverageHtmlWriter, ScoverageXmlWriter}",
18
+ "import scoverage.serialize.Serializer",
19
+ "",
20
+ "@main def report(data: String, sources: String, output: String): Unit = {",
21
+ " val dataDir = File(data)",
22
+ " val root = File(sources)",
23
+ " val coverage = Serializer.deserialize(Serializer.coverageFile(dataDir), root)",
24
+ " coverage.apply(IOUtils.invoked(IOUtils.findMeasurementFiles(dataDir).toIndexedSeq))",
25
+ " val out = File(output)",
26
+ " out.mkdirs()",
27
+ " CoberturaXmlWriter(Seq(root), out, None).write(coverage)",
28
+ " ScoverageXmlWriter(Seq(root), out, false, None).write(coverage)",
29
+ " ScoverageHtmlWriter(Seq(root), out, None).write(coverage)",
30
+ " println(f\"Statement coverage: ${coverage.statementCoveragePercent}%.2f%%\")",
31
+ "}",
32
+ ""].join("\n");
33
+
34
+ // Where the instrumented runs write their data, under the coverage directory.
35
+ export function scalaCoverageData(directory) {
36
+ return path.join(directory, "data");
37
+ }
38
+
39
+ // Writes the reports into directory from the runs' data; false when no run
40
+ // was measured.
41
+ export async function collectScalaCoverage({root, directory, command = "scala", offline = false}) {
42
+ const data = scalaCoverageData(directory);
43
+ const files = await readdir(data).catch(() => []);
44
+ if (!files.includes("scoverage.coverage")) return false;
45
+ const script = path.join(directory, "reporter", "Report.scala");
46
+ await mkdir(path.dirname(script), {recursive: true});
47
+ await writeFile(script, reportScript);
48
+ const args = ["run", ...(offline ? ["--offline"] : []), script, "--", data, root, path.join(directory, "report")];
49
+ const status = await new Promise((resolve, reject) => {
50
+ const child = spawn(command, args, {cwd: path.dirname(script), stdio: ["ignore", "inherit", "inherit"]});
51
+ child.on("error", reject);
52
+ child.on("close", resolve);
53
+ });
54
+ if (status !== 0) throw new Error(`the scoverage reporter failed (${command} ${args.join(" ")})`);
55
+ return true;
56
+ }
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\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
+ }
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
@@ -156,11 +157,30 @@ export function benchmarkInvocations(target, entries, { offline = false } = {})
156
157
  args: [...(offline ? ["--offline"] : []), "--console=plain", "test", "--rerun", "--tests", className(file, "src/test/kotlin", ".kt")],
157
158
  env: { "kotest.filter.tests": filter, kotest_filter_tests: filter } };
158
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}`])] }];
159
171
  if (language === "rust")
160
172
  return groupBy(entries, (e) => e.file).map(([file, marks]) => ({ command: "cargo",
161
173
  args: ["test", ...(offline ? ["--offline"] : []), "--test", path.posix.basename(file, ".rs"), "--", "--exact", "--nocapture", ...marks.map((e) => e.name)] }));
162
174
  if (language === "fsharp" || language === "csharp")
163
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)}\\(`])] }];
164
184
  if (language === "haskell") {
165
185
  const module = (e) => without(relativeTo(e.file, "test"), "Spec.hs").replaceAll("/", ".");
166
186
  // hspec matches by substring, and a benchmark's name has spaces, so each
@@ -284,6 +304,43 @@ export function invocations(target, entries, { offline = false, scratch = ".", c
284
304
  report: { kind: "junit", directory: "build/test-results/test" },
285
305
  ran: (test) => laws.filter((e) => test.classname === name && named(e).test(test.name)) };
286
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
+ }
287
344
  if (language === "rust")
288
345
  return groupBy(entries, (e) => e.file).map(([file, laws]) => ({
289
346
  laws, command: "cargo",
@@ -307,6 +364,21 @@ export function invocations(target, entries, { offline = false, scratch = ".", c
307
364
  report: { kind: "junit", files: [path.join(results, report)] },
308
365
  ran: (test) => entries.filter((e) => pattern(e).test(test.name)) }];
309
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
+ }
310
382
  if (language === "haskell") {
311
383
  const module = (e) => without(relativeTo(e.file, "test"), "Spec.hs").replaceAll("/", ".");
312
384
  const matches = entries.map((e) => `${module(e)}/${e.name}_`);
@@ -329,10 +401,14 @@ export const coverageTools = {
329
401
  go: { tool: "go test -cover", install: "(built in)" },
330
402
  java: { tool: "JaCoCo", install: "(resolved by Maven as org.jacoco:jacoco-maven-plugin)" },
331
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" },
332
406
  rust: { tool: "cargo-llvm-cov", install: "cargo install cargo-llvm-cov" },
333
407
  haskell: { tool: "hpc", install: "(built into GHC; stack test --coverage)" },
334
408
  fsharp: { tool: "Microsoft code coverage", install: "add the Microsoft.Testing.Extensions.CodeCoverage package to the test project" },
335
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)" },
336
412
  };
337
413
 
338
414
  // Laws selected by tag: every --tag, and none of --exclude-tag.