Skip to content

Commit

Permalink
Show seed by default
Browse files Browse the repository at this point in the history
add quiet flat
  • Loading branch information
bdemann committed Dec 21, 2023
1 parent 9893218 commit 1eced15
Showing 1 changed file with 54 additions and 39 deletions.
93 changes: 54 additions & 39 deletions property_tests/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,60 +12,75 @@ export type Named<T> = {

export { getActor } from './get_actor';

export function runPropTests(canisterArb: fc.Arbitrary<Canister>) {
fc.assert(
fc.asyncProperty(canisterArb, async (canister) => {
if (!existsSync('src')) {
mkdirSync('src');
}

writeFileSync('src/index.ts', canister.sourceCode);

execSync(`npx prettier --write src`, {
stdio: 'inherit'
});
export async function runPropTests(canisterArb: fc.Arbitrary<Canister>) {
try {
await fc.assert(
fc.asyncProperty(canisterArb, async (canister) => {
if (!existsSync('src')) {
mkdirSync('src');
}

execSync(`dfx canister uninstall-code canister || true`, {
stdio: 'inherit'
});
writeFileSync('src/index.ts', canister.sourceCode);

for (let i = 0; i < canister.tests.length; i++) {
execSync(`dfx deploy canister`, {
execSync(`npx prettier --write src`, {
stdio: 'inherit'
});

execSync(`dfx generate canister`, {
execSync(`dfx canister uninstall-code canister || true`, {
stdio: 'inherit'
});

const tests = canister.tests[i];

const result = await runTests(
tests,
process.env.AZLE_PROPTEST_VERBOSE !== 'true'
);
for (let i = 0; i < canister.tests.length; i++) {
execSync(`dfx deploy canister`, {
stdio: 'inherit'
});

execSync(
`node_modules/.bin/tsc --noEmit --skipLibCheck --target es2020 --strict --moduleResolution node --allowJs`,
{
execSync(`dfx generate canister`, {
stdio: 'inherit'
}
);
});

clearUniquePrimitiveArb();
const tests = canister.tests[i];

if (result === false) {
return false;
const result = await runTests(
tests,
process.env.AZLE_PROPTEST_QUIET === 'true'
);

execSync(
`node_modules/.bin/tsc --noEmit --skipLibCheck --target es2020 --strict --moduleResolution node --allowJs`,
{
stdio: 'inherit'
}
);

clearUniquePrimitiveArb();

if (result === false) {
return false;
}
}
}

return true;
}),
{
numRuns: Number(process.env.AZLE_PROPTEST_NUM_RUNS ?? 1),
endOnFailure: true // TODO This essentially disables shrinking. We don't know how to do shrinking well yet
return true;
}),
{
numRuns: Number(process.env.AZLE_PROPTEST_NUM_RUNS ?? 1),
endOnFailure: true // TODO This essentially disables shrinking. We don't know how to do shrinking well yet
}
);
} catch (error) {
if (process.env.AZLE_PROPTEST_VERBOSE !== 'true') {
// Customize the error message to exclude counter example
if (error instanceof Error) {
const errorLines = error.message.split('\n');
const newError = [
...errorLines.slice(0, 2),
...errorLines.slice(errorLines.length - 4)
].join('\n');
error.message = newError;
}
}
);
throw error;
}
}

export const defaultArrayConstraints = {
Expand Down

0 comments on commit 1eced15

Please sign in to comment.