-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: More AST generators. Simplified logger by removing `dummySrcInf…
…o` in the output
- Loading branch information
Showing
4 changed files
with
134 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,61 @@ | ||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
const coverage = require("@tact-lang/coverage"); | ||
const fc = require("fast-check"); | ||
|
||
module.exports = async () => { | ||
if (process.env.COVERAGE === "true") { | ||
coverage.beginCoverage(); | ||
} | ||
}; | ||
|
||
function sanitizeObject( | ||
obj, | ||
options = { | ||
excludeKeys: [], | ||
valueTransformers: {}, | ||
}, | ||
) { | ||
const { excludeKeys, valueTransformers } = options; | ||
|
||
if (Array.isArray(obj)) { | ||
return obj.map((item) => sanitizeObject(item, options)); | ||
} else if (obj !== null && typeof obj === "object") { | ||
const newObj = {}; | ||
for (const [key, value] of Object.entries(obj)) { | ||
if (!excludeKeys.includes(key)) { | ||
const transformer = valueTransformers[key]; | ||
newObj[key] = transformer | ||
? transformer(value) | ||
: sanitizeObject(value, options); | ||
} | ||
} | ||
return newObj; | ||
} | ||
return obj; | ||
} | ||
|
||
fc.configureGlobal({ | ||
reporter: (log) => { | ||
if (log.failed) { | ||
const sanitizedCounterexample = sanitizeObject(log.counterexample, { | ||
excludeKeys: ["id", "loc"], | ||
valueTransformers: { | ||
value: (val) => | ||
typeof val === "bigint" ? val.toString() : val, | ||
}, | ||
}); | ||
|
||
const errorMessage = ` | ||
=== | ||
Property failed after ${log.numRuns} tests | ||
Seed: ${log.seed} | ||
Path: ${log.counterexamplePath} | ||
Counterexample: ${JSON.stringify(sanitizedCounterexample, null, 0)} | ||
Errors: ${log.error ? log.error : "Unknown error"} | ||
=== | ||
`; | ||
|
||
throw new Error(errorMessage); | ||
} | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters