@amritk/nish-x86_64-linux 0.46.0 → 0.47.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/std/testing.ts CHANGED
@@ -125,6 +125,12 @@ const testingFirstDifferentLine = (actual: string[], expected: string[]): i32 =>
125
125
  return actualLength === expectedLength ? -1 : shorter
126
126
  }
127
127
 
128
+ /** The largest `i32`, where a tally stops rather than wraps. */
129
+ const TESTING_I32_MAX: i32 = 2147483647
130
+
131
+ /** `n` plus one, or `n` when it is already the largest `i32`. */
132
+ const testingCount = (n: i32): i32 => (n < TESTING_I32_MAX ? n + 1 : n)
133
+
128
134
  /**
129
135
  * One run of checks, and the tally it reports.
130
136
  *
@@ -137,7 +143,8 @@ export class Suite {
137
143
  private name: string
138
144
  // These three have initializers because the constructor does not assign them,
139
145
  // and every field holds a value once it returns. `name` does not, and an
140
- // initializer there would only be a store the constructor overwrites.
146
+ // initializer there would only be a store the constructor overwrites. Each
147
+ // stops at the largest `i32` (`testingCount`).
141
148
  private passed: i32 = 0
142
149
  private failed: i32 = 0
143
150
  private skipped: i32 = 0
@@ -167,7 +174,7 @@ export class Suite {
167
174
  * @returns `true`, so a check of its own shape can answer what this answers.
168
175
  */
169
176
  pass(name: string): boolean {
170
- this.passed += 1
177
+ this.passed = testingCount(this.passed)
171
178
  console.log(`PASS ${name}`)
172
179
  return true
173
180
  }
@@ -182,7 +189,7 @@ export class Suite {
182
189
  * @returns `false`, so a check of its own shape can answer what this answers.
183
190
  */
184
191
  fail(name: string, detail: string): boolean {
185
- this.failed += 1
192
+ this.failed = testingCount(this.failed)
186
193
  this.failures.push(name)
187
194
  console.log(`FAIL ${name}`)
188
195
  if (toI32(detail.length) > 0) {
@@ -200,7 +207,7 @@ export class Suite {
200
207
  * @param reason why it did not run, printed in parentheses after the name.
201
208
  */
202
209
  skip(name: string, reason: string): void {
203
- this.skipped += 1
210
+ this.skipped = testingCount(this.skipped)
204
211
  console.log(`SKIP ${name} (${reason})`)
205
212
  }
206
213
 
@@ -378,9 +385,9 @@ export class Suite {
378
385
  if (toI32(needle.length) === 0) {
379
386
  continue
380
387
  }
381
- looked += 1
388
+ looked = testingCount(looked)
382
389
  if (toI32(haystack.indexOf(needle)) < 0) {
383
- missing += 1
390
+ missing = testingCount(missing)
384
391
  if (toI32(first.length) === 0) {
385
392
  first = needle
386
393
  }
@@ -421,7 +428,7 @@ export class Suite {
421
428
  }
422
429
  const wanted = at < toI32(expected.length) ? `"${expected[at]}"` : "<end of input>"
423
430
  const saw = at < toI32(actual.length) ? `"${actual[at]}"` : "<end of input>"
424
- return this.fail(name, `line ${at + 1}: expected ${wanted}, got ${saw}`)
431
+ return this.fail(name, `line ${toI64(at) + 1}: expected ${wanted}, got ${saw}`)
425
432
  }
426
433
 
427
434
  /**