Skip to content

Commit

Permalink
Use testProp for tests with fc.pre
Browse files Browse the repository at this point in the history
Possible due to the bump to `(at)fast-check/ava` v1.2.0
  • Loading branch information
ericcornelissen committed Nov 22, 2023
1 parent b5a4ef3 commit 348dc50
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 65 deletions.
53 changes: 26 additions & 27 deletions test/unit/executables/resolve.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,33 +96,32 @@ testProp("env.PATH and env.Path are missing", [arbitrary.env()], (t, env) => {
);
});

test("env.PATH is polluted", (t) => {
fc.assert(
fc.property(
arbitrary.env({ keys: ["PATH", "Path"] }),
fc.constantFrom("PATH", "Path"),
fc.string(),
(env, pathName, prototypePath) => {
fc.pre(env.PATH !== prototypePath && env.Path !== prototypePath);

t.context.deps.which.resetHistory();

env = Object.assign(Object.create({ [pathName]: prototypePath }), env);

const { executable } = t.context;
const args = { env, executable };

resolveExecutable(args, t.context.deps);
t.is(t.context.deps.which.callCount, 1);
t.false(
t.context.deps.which.calledWithExactly(sinon.match.any, {
path: prototypePath,
}),
);
},
),
);
});
testProp(
"env.PATH is polluted",
[
arbitrary.env({ keys: ["PATH", "Path"] }),
fc.constantFrom("PATH", "Path"),
fc.string(),
],
(t, env, pathName, prototypePath) => {
fc.pre(env.PATH !== prototypePath && env.Path !== prototypePath);

t.context.deps.which.resetHistory();

env = Object.assign(Object.create({ [pathName]: prototypePath }), env);

const { executable } = t.context;
const args = { env, executable };

resolveExecutable(args, t.context.deps);
t.is(t.context.deps.which.callCount, 1);
t.false(
t.context.deps.which.calledWithExactly(sinon.match.any, {
path: prototypePath,
}),
);
},
);

test("the executable cannot be resolved", (t) => {
const { env, executable } = t.context;
Expand Down
42 changes: 20 additions & 22 deletions test/unit/platforms/get-helpers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*/

import { testProp } from "@fast-check/ava";
import test from "ava";
import * as fc from "fast-check";

import { arbitrary, constants } from "./_.js";
Expand Down Expand Up @@ -72,24 +71,23 @@ for (const osType of winOsTypes) {
);
}

test("env.OSTYPE is polluted", (t) => {
fc.assert(
fc.property(
arbitrary.env({ keys: ["OSTYPE"] }),
fc.constantFrom(...winOsTypes),
fc.constantFrom(...unixPlatforms),
(env, prototypeOstype, platform) => {
fc.pre(![...winOsTypes].includes(env.OSTYPE));

env = Object.assign(Object.create({ OSTYPE: prototypeOstype }), env);

const result = getHelpersByPlatform({
env,
platform,
});

t.deepEqual(result, unix);
},
),
);
});
testProp(
"env.OSTYPE is polluted",
[
arbitrary.env({ keys: ["OSTYPE"] }),
fc.constantFrom(...winOsTypes),
fc.constantFrom(...unixPlatforms),
],
(t, env, prototypeOstype, platform) => {
fc.pre(![...winOsTypes].includes(env.OSTYPE));

env = Object.assign(Object.create({ OSTYPE: prototypeOstype }), env);

const result = getHelpersByPlatform({
env,
platform,
});

t.deepEqual(result, unix);
},
);
28 changes: 12 additions & 16 deletions test/unit/win/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,22 +55,18 @@ testProp(
},
);

test("the default shell when %COMSPEC% is polluted", (t) => {
fc.assert(
fc.property(
arbitrary.env({ keys: ["ComSpec"] }),
fc.string(),
(env, prototypeComSpec) => {
fc.pre(env.ComSpec !== prototypeComSpec);

env = Object.assign(Object.create({ ComSpec: prototypeComSpec }), env);

const result = win.getDefaultShell({ env });
t.not(result, prototypeComSpec);
},
),
);
});
testProp(
"the default shell when %COMSPEC% is polluted",
[arbitrary.env({ keys: ["ComSpec"] }), fc.string()],
(t, env, prototypeComSpec) => {
fc.pre(env.ComSpec !== prototypeComSpec);

env = Object.assign(Object.create({ ComSpec: prototypeComSpec }), env);

const result = win.getDefaultShell({ env });
t.not(result, prototypeComSpec);
},
);

test("escape function for no shell", (t) => {
const actual = win.getEscapeFunction(noShell);
Expand Down

0 comments on commit 348dc50

Please sign in to comment.