Add getOptionalInput and getRequiredInput

This commit is contained in:
Robert Brignull 2020-09-15 18:42:23 +01:00
parent d88fa5cef6
commit c1cee53da5
18 changed files with 111 additions and 61 deletions

27
lib/util.test.js generated
View file

@ -24,11 +24,12 @@ ava_1.default("getToolNames", (t) => {
});
ava_1.default("getMemoryFlag() should return the correct --ram flag", (t) => {
const totalMem = Math.floor(os.totalmem() / (1024 * 1024));
const tests = {
"": `--ram=${totalMem - 256}`,
"512": "--ram=512",
};
for (const [input, expectedFlag] of Object.entries(tests)) {
const tests = [
[undefined, `--ram=${totalMem - 256}`],
["", `--ram=${totalMem - 256}`],
["512", "--ram=512"],
];
for (const [input, expectedFlag] of tests) {
const flag = util.getMemoryFlag(input);
t.deepEqual(flag, expectedFlag);
}
@ -48,13 +49,15 @@ ava_1.default("getAddSnippetsFlag() should return the correct flag", (t) => {
});
ava_1.default("getThreadsFlag() should return the correct --threads flag", (t) => {
const numCpus = os.cpus().length;
const tests = {
"0": "--threads=0",
"1": "--threads=1",
[`${numCpus + 1}`]: `--threads=${numCpus}`,
[`${-numCpus - 1}`]: `--threads=${-numCpus}`,
};
for (const [input, expectedFlag] of Object.entries(tests)) {
const tests = [
["0", "--threads=0"],
["1", "--threads=1"],
[undefined, `--threads=${numCpus}`],
["", `--threads=${numCpus}`],
[`${numCpus + 1}`, `--threads=${numCpus}`],
[`${-numCpus - 1}`, `--threads=${-numCpus}`],
];
for (const [input, expectedFlag] of tests) {
const flag = util.getThreadsFlag(input, logging_1.getRunnerLogger(true));
t.deepEqual(flag, expectedFlag);
}