Skip to content

Feature/validate #34

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Jun 13, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
cleanup output text ui
Signed-off-by: shmck <shawn.j.mckay@gmail.com>
  • Loading branch information
ShMcK committed Jun 13, 2020
commit 2fc111324fcdd12037012723f95733cd9aa357e0
3 changes: 1 addition & 2 deletions src/utils/exec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,14 @@ export function createCommandRunner(cwd: string) {
let errors = [];
for (const command of commands) {
try {
console.log(`> ${command}`);
console.log(`--> ${command}`);
let cwdDir = cwd;
if (dir) {
cwdDir = path.join(cwd, dir);
}
const { stdout, stderr } = await createExec(cwdDir)(command);

console.warn(stderr);
console.log(stdout);
} catch (e) {
console.error(`Command failed: "${command}"`);
console.warn(e.message);
Expand Down
33 changes: 19 additions & 14 deletions src/validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,15 @@ async function validate(args: string[]) {
const runTest = createTestRunner(tmpDir, skeleton.config.testRunner);

// setup
console.info("* Setup");
if (commits.INIT) {
// load commits
console.info("Loading setup commits...");
console.info("-- Loading commits...");
await cherryPick(commits.INIT);

// run commands
if (skeleton.config?.testRunner?.setup?.commands) {
console.info("Running setup commands...");
console.info("-- Running commands...");

await runCommands(
skeleton.config?.testRunner?.setup?.commands,
Expand All @@ -76,30 +77,32 @@ async function validate(args: string[]) {
}

for (const level of skeleton.levels) {
console.info(`* ${level.id}`);
if (level?.setup) {
// load commits
if (commits[`${level.id}`]) {
console.log(`Loading ${level.id} commits...`);
console.log(`-- Loading commits...`);
await cherryPick(commits[level.id]);
}
// run commands
if (level.setup?.commands) {
console.log(`Running ${level.id} commands...`);
console.log(`-- Running commands...`);
await runCommands(level.setup.commands);
}
}
// steps
if (level.steps) {
for (const step of level.steps) {
console.info(`** ${step.id}`);
// load commits
const stepSetupCommits = commits[`${step.id}Q`];
if (stepSetupCommits) {
console.info(`Loading ${step.id} setup commits...`);
console.info(`--- Loading setup commits...`);
await cherryPick(stepSetupCommits);
}
// run commands
if (step.setup.commands) {
console.info(`Running ${step.id} setup commands...`);
console.info(`--- Running setup commands...`);
await runCommands(step.setup.commands);
}

Expand All @@ -109,47 +112,49 @@ async function validate(args: string[]) {
// ignore running tests on steps with no solution
if (hasSolution) {
// run test
console.info("Running setup test");
console.info("--- Running setup test...");
// expect fail
const { stdout, stderr } = await runTest();
if (stdout) {
console.error(
`Expected ${step.id} setup tests to fail, but passed`
`--- Expected ${step.id} setup tests to fail, but passed`
);
// log tests
console.log(stdout);
}
}

if (stepSolutionCommits) {
console.info(`Loading ${step.id} solution commits...`);
console.info(`--- Loading solution commits...`);
await cherryPick(stepSolutionCommits);
}

// run commands
if (step?.solution?.commands) {
console.info(`Running ${step.id} solution commands...`);
console.info(`--- Running solution commands...`);
await runCommands(step.solution.commands);
}

if (hasSolution) {
// run test
console.info("Running solution test");
console.info("--- Running solution test...");
// expect pass
const { stdout, stderr } = await runTest();
if (stderr) {
console.error(
`Expected ${step.id} solution tests to pass, but failed`
`--- Expected ${step.id} solution tests to pass, but failed`
);
// log tests
console.log(stderr);
}
}
}
}
}

// log level/step
// on error, show level/step & error message
console.info(`\n✔ Success!`);
} catch (e) {
console.error("\n✘ Fail!");
console.error(e.message);
} finally {
// cleanup
Expand Down