lawspec 0.22.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 +258 -2
- package/README.md +3 -3
- package/bin/lawspec.mjs +81 -12
- package/build.json +165 -101
- package/compatibility.json +8 -0
- package/core.wasm +2 -2
- package/doctor.mjs +22 -1
- 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/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 +36 -1
- package/package.json +2 -2
- package/templates.mjs +45 -3
- package/test-command.mjs +28 -3
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
unit example.records
|
|
2
|
+
|
|
3
|
+
import example.records.inner as inner
|
|
4
|
+
|
|
5
|
+
-- Records: a type with one constructor has fields that code reads by name
|
|
6
|
+
-- (account.balance) and replaces by name (account with balance = 0).
|
|
7
|
+
|
|
8
|
+
type Account is
|
|
9
|
+
Account
|
|
10
|
+
owner :: Text
|
|
11
|
+
balance :: Int64
|
|
12
|
+
holds :: List Int64
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
type Ledger is
|
|
16
|
+
Ledger
|
|
17
|
+
account :: Account
|
|
18
|
+
entries :: Int32
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
definition deposit (a :: Account) (amount :: Int64 where amount >= 0 && amount <= 1000000) :: Account is
|
|
22
|
+
if a.balance >= 0 && a.balance <= 1000000000 then a with balance = prelude.Int64 (a.balance + amount) else a
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
definition rename (l :: Ledger) (name :: Text) :: Ledger is
|
|
26
|
+
l with account = (l.account with owner = name), entries = 0
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
law `a deposit adds to the balance` is
|
|
30
|
+
definition is
|
|
31
|
+
`for all` (owner :: Text) (start :: Int64 where start >= 0 && start <= 1000000000) (amount :: Int64 where amount >= 0 && amount <= 1000000) .
|
|
32
|
+
(deposit (Account owner start []) amount).balance = start + amount
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
law `a deposit keeps the owner and holds` is
|
|
37
|
+
definition is
|
|
38
|
+
`for all` (a :: Account) (amount :: Int64 where amount >= 0 && amount <= 1000000) .
|
|
39
|
+
(deposit a amount).owner = a.owner and (deposit a amount).holds = a.holds
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
law `renaming reads back` is
|
|
44
|
+
definition is
|
|
45
|
+
`for all` (l :: Ledger) (name :: Text) . (rename l name).account.owner = name and (rename l name).entries = 0
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
-- A definition may fail without any ability, and another may attempt it.
|
|
50
|
+
type Refusal is | Overdrawn | Unfunded end
|
|
51
|
+
|
|
52
|
+
definition withdraw (a :: Account) (amount :: Int64) :: Account fails with Refusal is
|
|
53
|
+
if amount < 0 then raise Unfunded else
|
|
54
|
+
if amount > a.balance then raise Overdrawn else a with balance = prelude.Int64 (a.balance - amount)
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
definition settled (a :: Account) (amount :: Int64) :: Either Refusal Int64 is
|
|
58
|
+
match prelude.attempt (withdraw a amount) with
|
|
59
|
+
| Left refusal -> Left refusal
|
|
60
|
+
| Right after -> Right after.balance
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
law `a withdrawal within the balance leaves the rest` is
|
|
65
|
+
definition is
|
|
66
|
+
`for all` (owner :: Text) (start :: Int64 where start >= 0) (amount :: Int64 where amount >= 0 && amount <= start) .
|
|
67
|
+
settled (Account owner start []) amount = Right (prelude.Int64 (start - amount))
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
law `a withdrawal beyond the balance is refused` is
|
|
72
|
+
definition is
|
|
73
|
+
`for all` (owner :: Text) (start :: Int64 where start >= 0 && start < 1000) (amount :: Int64 where amount >= 1000) .
|
|
74
|
+
settled (Account owner start []) amount = Left Overdrawn and settled (Account owner start []) (0 - amount) = Left Unfunded
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
-- A refinement through a definition still guides generation: sample
|
|
79
|
+
-- names come from the pattern, so the law does not starve its filter.
|
|
80
|
+
definition validOwner (name :: Text) :: Bool is
|
|
81
|
+
prelude.length name == 9 && name matches regex "acct-[0-9]{4}"
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
law `a renamed ledger keeps a valid owner` is
|
|
85
|
+
definition is
|
|
86
|
+
`for all` (l :: Ledger) (name :: Text where validOwner name) . validOwner (rename l name).account.owner
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
-- A literal takes its type from where it is used: 0 is an Int64 here.
|
|
91
|
+
definition opening (a :: Maybe Account) :: Int64 is
|
|
92
|
+
let start = (match a with | Nothing -> 0 | Just account -> account.balance end) in
|
|
93
|
+
if start < 0 then 0 else start
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
law `an absent account opens at zero` is
|
|
97
|
+
definition is opening Nothing = 0 end
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
-- Recursion on an integer that moves toward a bound is total.
|
|
101
|
+
definition countdown (n :: Natural) :: List Natural is
|
|
102
|
+
if n == 0 then [] else Cons n (countdown (n - 1))
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
definition evensBelow (i :: Int32) (n :: Int32) :: List Int32 is
|
|
106
|
+
if i >= n || i < 0 then [] else
|
|
107
|
+
(if prelude.rem i 2 == 0 then Cons i (evensBelow (prelude.Int32 (i + 1)) n) else evensBelow (prelude.Int32 (i + 1)) n)
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
law `a countdown has n items` is
|
|
111
|
+
definition is `for all` (n :: Natural where n <= 50) . prelude.length (countdown n) = n end
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
law `the evens below n are half of the range` is
|
|
115
|
+
definition is
|
|
116
|
+
`for all` (n :: Int32 where n >= 0 && n <= 40) .
|
|
117
|
+
prelude.length (evensBelow 0 n) = prelude.quot (n + 1) 2
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
law `range counts from the first up to the last` is
|
|
122
|
+
definition is
|
|
123
|
+
`for all` (n :: Int32 where n >= 0 && n <= 40) . prelude.length (prelude.range 0 n) = n
|
|
124
|
+
end
|
|
125
|
+
example `three` is
|
|
126
|
+
n = 3
|
|
127
|
+
expect prelude.range 0 n = [0, 1, 2]
|
|
128
|
+
end
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
-- The prover keeps what guards say about calls, lengths and remainders.
|
|
132
|
+
definition clip (xs :: List Int32) :: Int32 is
|
|
133
|
+
if prelude.length xs <= 100 then prelude.Int32 (prelude.length xs) else 100
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
definition owner (p :: Int32) (k :: Int32) :: Int32 is
|
|
137
|
+
if k >= 1 && p >= 0 then prelude.Int32 (prelude.rem p k) else 0
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
law `a clipped length is at most 100` is
|
|
141
|
+
definition is `for all` (xs :: List Int32) . (clip xs <= 100 && clip xs >= 0) = true end
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
law `an owner is one of the k` is
|
|
145
|
+
definition is
|
|
146
|
+
`for all` (p :: Int32 where p >= 0) (k :: Int32 where k >= 1 && k <= 64) . (owner p k >= 0 && owner p k < k) = true
|
|
147
|
+
end
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
-- Arithmetic into a bounded type, by name.
|
|
151
|
+
definition nextEpoch (e :: Int16) :: Int16 is prelude.wrapping (e + 1) end
|
|
152
|
+
definition topUp (level :: UInt8) :: UInt8 is prelude.saturating (level + 10) end
|
|
153
|
+
definition total (a :: Int32) (b :: Int32) :: Maybe Int32 is prelude.bounded (a + b) end
|
|
154
|
+
|
|
155
|
+
law `epochs wrap around` is
|
|
156
|
+
definition is
|
|
157
|
+
`for all` (e :: Int16) . nextEpoch e = (if e == Int16.max then Int16.min else prelude.Int16 (e + 1))
|
|
158
|
+
end
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
law `a top up stops at the top` is
|
|
162
|
+
definition is
|
|
163
|
+
`for all` (level :: UInt8) . topUp level = (if level >= 245 then 255 else prelude.UInt8 (level + 10))
|
|
164
|
+
end
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
law `a total that overflows is Nothing` is
|
|
168
|
+
definition is
|
|
169
|
+
`for all` (a :: Int32) (b :: Int32) .
|
|
170
|
+
total a b = (if a + b > Int32.max || a + b < Int32.min then Nothing else Just (prelude.Int32 (a + b)))
|
|
171
|
+
end
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
-- A refinement shapes generation: texts a regex must match are drawn from
|
|
175
|
+
-- the regex, through the definition that says so, not filtered from any
|
|
176
|
+
-- text.
|
|
177
|
+
definition validTopic (name :: Text) :: Bool is
|
|
178
|
+
let n = prelude.length name in
|
|
179
|
+
n >= 1 && n <= 249 && name != "." && name != ".." && name matches regex "[a-zA-Z0-9._-]+"
|
|
180
|
+
end
|
|
181
|
+
|
|
182
|
+
law `a valid topic name keeps to its characters` is
|
|
183
|
+
definition is
|
|
184
|
+
`for all` (t :: Text where validTopic t) (n :: Int32 where n >= 1 && n <= 64) .
|
|
185
|
+
(prelude.length t >= 1 && prelude.length t <= 249 && n <= 64) = true
|
|
186
|
+
end
|
|
187
|
+
end
|
|
188
|
+
|
|
189
|
+
law `a unit may sit above its package's other units` is
|
|
190
|
+
definition is `for all` (x :: Int32) . inner.doubled x = x + x end
|
|
191
|
+
end
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
unit example.records.inner
|
|
2
|
+
|
|
3
|
+
-- A unit inside another unit's name: on Python, example.records is then its
|
|
4
|
+
-- package's __init__.py, and this unit is example/records/inner.py.
|
|
5
|
+
|
|
6
|
+
definition doubled (x :: Int32) :: Integer is x * 2 end
|
|
7
|
+
|
|
8
|
+
law `doubling is even` is
|
|
9
|
+
definition is `for all` (x :: Int32) . prelude.rem (doubled x) 2 = 0 end
|
|
10
|
+
end
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
unit example.sequences
|
|
2
|
+
|
|
3
|
+
-- Text, Bytes and List are sequences: joined with ++, sliced, and read by
|
|
4
|
+
-- index. Bytes give their octets, and Text its UTF-8 encoding.
|
|
5
|
+
|
|
6
|
+
-- A record key's hash: FNV-1a over the key's octets, in 32 bits.
|
|
7
|
+
definition fnv (octets :: List UInt8) (hash :: UInt32) :: UInt32 is
|
|
8
|
+
match octets with
|
|
9
|
+
| Nil -> hash
|
|
10
|
+
| Cons o rest -> fnv rest (prelude.wrapping ((xorByte hash o) * 16777619))
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
-- hash xor o, for an octet o, by its low eight bits.
|
|
15
|
+
definition xorByte (hash :: UInt32) (o :: UInt8) :: Integer is
|
|
16
|
+
let low = prelude.rem hash 256 in
|
|
17
|
+
hash - low + xorBits low o 128
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
definition xorBits (a :: Integer) (b :: Integer) (bit :: Integer) :: Integer is
|
|
21
|
+
if bit <= 0 || a < 0 || b < 0 then 0 else
|
|
22
|
+
(if prelude.quot a bit != prelude.quot b bit then bit else 0)
|
|
23
|
+
+ xorBits (prelude.rem a bit) (prelude.rem b bit) (prelude.quot bit 2)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
definition keyHash (key :: Bytes) :: UInt32 is fnv (prelude.octets key) 2166136261 end
|
|
27
|
+
|
|
28
|
+
definition partitionFor (key :: Bytes) (n :: Int32) :: Int32 is
|
|
29
|
+
if n >= 1 then prelude.Int32 (prelude.rem (keyHash key) n) else 0
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
law `a key's partition exists` is
|
|
33
|
+
definition is
|
|
34
|
+
`for all` (key :: Bytes) (n :: Int32 where n >= 1 && n <= 64) .
|
|
35
|
+
(partitionFor key n >= 0 && partitionFor key n < n) = true
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
law `the hash follows FNV-1a` is
|
|
40
|
+
definition is keyHash (prelude.utf8 "a") = 3826002220 and keyHash (prelude.utf8 "") = 2166136261 end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
-- Member ids, made by the coordinator from a client id and a counter.
|
|
44
|
+
definition memberId (client :: Text) (n :: Int32) :: Text is client ++ "-" ++ prelude.textOf n end
|
|
45
|
+
|
|
46
|
+
law `a member id starts with its client` is
|
|
47
|
+
definition is
|
|
48
|
+
`for all` (client :: Text) (n :: Int32) . memberId client n starts with client
|
|
49
|
+
end
|
|
50
|
+
example `the third` is
|
|
51
|
+
client = "consumer"
|
|
52
|
+
n = 3
|
|
53
|
+
expect memberId client n = "consumer-3"
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
law `joining text adds lengths` is
|
|
58
|
+
definition is
|
|
59
|
+
`for all` (a :: Text) (b :: Text) . prelude.length (a ++ b) = prelude.length a + prelude.length b
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
law `octets and bytes round trip` is
|
|
64
|
+
definition is `for all` (b :: Bytes) . prelude.bytesOf (prelude.octets b) = b end
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
law `a slice is a part` is
|
|
68
|
+
definition is
|
|
69
|
+
`for all` (xs :: List Int32) (k :: Int32 where k >= 0 && k <= 10) .
|
|
70
|
+
prelude.take k xs ++ prelude.drop k xs = xs
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
law `at reads the item an index names` is
|
|
75
|
+
definition is
|
|
76
|
+
`for all` (x :: Int32) (xs :: List Int32) . prelude.at 0 (Cons x xs) = Just x and prelude.at (prelude.length xs + 1) (Cons x xs) = Nothing
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
law `texts join with a separator` is
|
|
81
|
+
definition is prelude.join ", " ["a", "b", "c"] = "a, b, c" and prelude.slice 1 3 "kafka" = "af" end
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
law `utf8 encodes code points` is
|
|
85
|
+
definition is prelude.utf8 "é" = prelude.bytesOf [195, 169] and prelude.length (prelude.utf8 "é") = 2 end
|
|
86
|
+
end
|
package/index.d.ts
CHANGED
|
@@ -10,7 +10,9 @@ export type Target =
|
|
|
10
10
|
'rust' |
|
|
11
11
|
'erlang' |
|
|
12
12
|
'elixir' |
|
|
13
|
-
'gleam'
|
|
13
|
+
'gleam' |
|
|
14
|
+
'fsharp' |
|
|
15
|
+
'csharp';
|
|
14
16
|
|
|
15
17
|
export interface Source {
|
|
16
18
|
path: string;
|
|
@@ -240,6 +242,37 @@ export interface ObligationEvidence {
|
|
|
240
242
|
status: DischargeStatus;
|
|
241
243
|
reason: string;
|
|
242
244
|
claim: Expr | null;
|
|
245
|
+
environment?: string;
|
|
246
|
+
environmentRun?: AttestedRun;
|
|
247
|
+
against?: AttestedDependency[];
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
export interface AttestedRun {
|
|
251
|
+
id: string;
|
|
252
|
+
startedAt: string;
|
|
253
|
+
recordedAt: string;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
export interface AttestedStandIn {
|
|
257
|
+
identity: string;
|
|
258
|
+
version: string;
|
|
259
|
+
conformance: string;
|
|
260
|
+
historyDigest?: string;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
export interface AttestedDependency {
|
|
264
|
+
dependency: string;
|
|
265
|
+
endpoint: string;
|
|
266
|
+
reached: boolean;
|
|
267
|
+
kind: 'real' | 'stand-in';
|
|
268
|
+
standIn?: AttestedStandIn;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
export interface AttestationView {
|
|
272
|
+
environment: string;
|
|
273
|
+
run: AttestedRun;
|
|
274
|
+
producer?: PackageVersion;
|
|
275
|
+
dependencies: (AttestedDependency & {obligations: string[]})[];
|
|
243
276
|
}
|
|
244
277
|
|
|
245
278
|
export interface PackageVersion {
|
|
@@ -271,6 +304,7 @@ export interface CheckRequest {
|
|
|
271
304
|
dependencies?: Record<string, string>;
|
|
272
305
|
packages?: Package[];
|
|
273
306
|
cacheDirectory?: string;
|
|
307
|
+
attestation?: unknown;
|
|
274
308
|
}
|
|
275
309
|
|
|
276
310
|
export interface GenerationRequest extends CheckRequest {
|
|
@@ -294,6 +328,7 @@ export interface Result {
|
|
|
294
328
|
expansions?: string[];
|
|
295
329
|
files?: Artifact[];
|
|
296
330
|
evidence?: ObligationEvidence[];
|
|
331
|
+
attestation?: AttestationView;
|
|
297
332
|
packages?: PackageView[];
|
|
298
333
|
project?: {package?: PackageVersion; dependencies: Record<string, string>;};
|
|
299
334
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lawspec",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.23.0",
|
|
4
4
|
"description": "State the law once. Check it everywhere.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"examples"
|
|
36
36
|
],
|
|
37
37
|
"scripts": {
|
|
38
|
-
"prepack": "
|
|
38
|
+
"prepack": "for f in README.md CHANGELOG.md; do cmp -s ../$f $f || { cp ../$f .$f.$$ && mv -f .$f.$$ $f; }; done",
|
|
39
39
|
"test": "node --test test/*.test.mjs"
|
|
40
40
|
}
|
|
41
41
|
}
|
package/templates.mjs
CHANGED
|
@@ -12,7 +12,9 @@ export const targets = [
|
|
|
12
12
|
"rust",
|
|
13
13
|
"erlang",
|
|
14
14
|
"elixir",
|
|
15
|
-
"gleam"
|
|
15
|
+
"gleam",
|
|
16
|
+
"fsharp",
|
|
17
|
+
"csharp"
|
|
16
18
|
];
|
|
17
19
|
export const targetLabels = [
|
|
18
20
|
[
|
|
@@ -58,6 +60,14 @@ export const targetLabels = [
|
|
|
58
60
|
[
|
|
59
61
|
"gleam",
|
|
60
62
|
"Gleam"
|
|
63
|
+
],
|
|
64
|
+
[
|
|
65
|
+
"fsharp",
|
|
66
|
+
"F#"
|
|
67
|
+
],
|
|
68
|
+
[
|
|
69
|
+
"csharp",
|
|
70
|
+
"C#"
|
|
61
71
|
]
|
|
62
72
|
];
|
|
63
73
|
|
|
@@ -72,7 +82,9 @@ export const commands = {
|
|
|
72
82
|
"rust": "cargo test",
|
|
73
83
|
"erlang": "rebar3 eunit",
|
|
74
84
|
"elixir": "mix test",
|
|
75
|
-
"gleam": "gleam test"
|
|
85
|
+
"gleam": "gleam test",
|
|
86
|
+
"fsharp": "dotnet test",
|
|
87
|
+
"csharp": "dotnet test"
|
|
76
88
|
};
|
|
77
89
|
|
|
78
90
|
export const setup = {
|
|
@@ -86,7 +98,9 @@ export const setup = {
|
|
|
86
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.",
|
|
87
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.",
|
|
88
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.",
|
|
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."
|
|
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."
|
|
90
104
|
};
|
|
91
105
|
|
|
92
106
|
// Each target's build files in the readable and the compact (minified) layout.
|
|
@@ -198,6 +212,34 @@ const scaffolds = {
|
|
|
198
212
|
"test-support/src/.gitkeep": "",
|
|
199
213
|
"test/lawspec_example_test.gleam": "@external(erlang, \"lawspec_beam_test_run\", \"gleam_main\")\npub fn main() -> Nil\n"
|
|
200
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
|
+
}
|
|
201
243
|
}
|
|
202
244
|
};
|
|
203
245
|
|
package/test-command.mjs
CHANGED
|
@@ -14,13 +14,14 @@ 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",
|
|
17
|
+
const skipped = new Set([".git", ".lawspec", "node_modules", "dist", "build", "target", "out", ".gradle", "bin", "obj", "TestResults",
|
|
18
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
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"
|
|
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"];
|
|
24
25
|
|
|
25
26
|
const digest = (value) => createHash("sha256").update(value).digest("hex");
|
|
26
27
|
// The crypto builder owns these outputs. Inputs and other priv/ assets still
|
|
@@ -76,12 +77,16 @@ export async function recordedDigest(folder) {
|
|
|
76
77
|
}
|
|
77
78
|
|
|
78
79
|
// The result key of each law in a target's test manifest.
|
|
79
|
-
|
|
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() }) {
|
|
80
84
|
const contents = new Map(files.map((file) => [file.path, file.content]));
|
|
81
85
|
const configuration = JSON.stringify({ ...target, root: undefined });
|
|
82
86
|
return new Map(tests.map((entry) => [entry.law, digest(JSON.stringify([
|
|
83
87
|
build, configuration, machineBits, minify, entry.key, digest(contents.get(entry.file) ?? ""),
|
|
84
88
|
environment, entry.callsAdapters ? project : null,
|
|
89
|
+
...(attested.has(entry.law) ? [attested.get(entry.law)] : []),
|
|
85
90
|
]))]));
|
|
86
91
|
}
|
|
87
92
|
|
|
@@ -154,6 +159,8 @@ export function benchmarkInvocations(target, entries, { offline = false } = {})
|
|
|
154
159
|
if (language === "rust")
|
|
155
160
|
return groupBy(entries, (e) => e.file).map(([file, marks]) => ({ command: "cargo",
|
|
156
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}`])] }];
|
|
157
164
|
if (language === "haskell") {
|
|
158
165
|
const module = (e) => without(relativeTo(e.file, "test"), "Spec.hs").replaceAll("/", ".");
|
|
159
166
|
// hspec matches by substring, and a benchmark's name has spaces, so each
|
|
@@ -284,6 +291,22 @@ export function invocations(target, entries, { offline = false, scratch = ".", c
|
|
|
284
291
|
...laws.map((e) => e.name)],
|
|
285
292
|
report: { kind: "lines", pattern: /^test (\S+) \.\.\. (ok|FAILED|ignored)/ },
|
|
286
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
|
+
}
|
|
287
310
|
if (language === "haskell") {
|
|
288
311
|
const module = (e) => without(relativeTo(e.file, "test"), "Spec.hs").replaceAll("/", ".");
|
|
289
312
|
const matches = entries.map((e) => `${module(e)}/${e.name}_`);
|
|
@@ -308,6 +331,8 @@ export const coverageTools = {
|
|
|
308
331
|
kotlin: { tool: "Kover", install: "add id(\"org.jetbrains.kotlinx.kover\") to the plugins of build.gradle.kts" },
|
|
309
332
|
rust: { tool: "cargo-llvm-cov", install: "cargo install cargo-llvm-cov" },
|
|
310
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" },
|
|
311
336
|
};
|
|
312
337
|
|
|
313
338
|
// Laws selected by tag: every --tag, and none of --exclude-tag.
|