Skip to content

Commit

Permalink
condensed logs
Browse files Browse the repository at this point in the history
  • Loading branch information
AjaniBilby committed May 29, 2024
1 parent 344ccb9 commit 63440bc
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
31 changes: 21 additions & 10 deletions source/test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/// <reference lib="deno.ns" />

import * as duration from "https://deno.land/[email protected]/fmt/duration.ts";
import * as colors from "https://deno.land/[email protected]/fmt/colors.ts";

import { resolve } from "https://deno.land/[email protected]/path/mod.ts";
Expand All @@ -8,6 +9,11 @@ import TestCase from "~/compiler/test-case.ts";
import Package from "~/compiler/package.ts";
import Project from "~/compiler/project.ts";

function Duration(start: number, end: number) {
if (start === end) return "0ms";
return duration.format(end-start, { ignoreZero: true })
}

export async function Test() {
// Determine all of the files to test
const targets = Deno.args.length > 1
Expand Down Expand Up @@ -35,7 +41,7 @@ export async function Test() {

const index = new Array<TestCase>();

console.log("Compilation");
console.log("Compiling...");
const compStart = Date.now();
for (const path of files.values()) {
const file = mainPck.import(path);
Expand All @@ -50,7 +56,11 @@ export async function Test() {
const compEnd = Date.now();

if (project.failed) Deno.exit(1);
console.log(` Found and compiled ${index.length} test cases ${colors.gray(`(${compEnd-compStart}ms)`)}`)
console.log(`\x1b[1A\r`
+ `Compiled`
+ ` ${colors.cyan(index.length.toString())} unit tests`
+ ` ${colors.gray(`(${Duration(compStart, compEnd)})`)}\n`
);


// Run all of the tests
Expand All @@ -66,7 +76,7 @@ export async function Test() {

if (prev !== test.file.name) {
prev = test.file.name;
console.log("\n"+colors.gray(prev.replaceAll('\\', '/')));
console.log(colors.gray(prev.replaceAll('\\', '/')));
}

const func = exports[`test${i}`];
Expand All @@ -77,18 +87,19 @@ export async function Test() {
const unitStart = Date.now();
const result = func();
const unitEnd = Date.now();
console.log(` - ${result ? colors.green("ok") : colors.red("FAIL")}`
+ ` ${test.name}`
+ ` ${colors.gray(`(${unitEnd-unitStart}ms)`)}`
console.log(`${result ? colors.green(" ok") : colors.red("ERR")}`
+ ` ${test.name}`
+ ` ${colors.gray(`(${Duration(unitStart, unitEnd)})`)}`
);
if (!result) fails++;
}
const execEnd = Date.now();

console.log(`\n ${fails == 0 ? colors.green("ok") : colors.red("FAIL")}`
+ ` | ${index.length-fails} passed`
+ ` | ${fails} failed`
+ colors.gray(` (${execEnd-execStart}ms)`)
console.log(`\n${colors.gray("Final Results")}\n`
+ `${fails == 0 ? colors.green(" ok") : colors.red("ERR")}`
+ ` │ ${colors.cyan((index.length-fails).toString())} passed`
+ ` ${colors.cyan((fails).toString())} failed`
+ colors.gray(` (${Duration(execStart, execEnd)})`)
);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/numeric.test.sa
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
test "Order of operations: Remainder" {
test "Order of Operations: Remainder" {
if ( 10.0 - ( 3.0 / 2.0 ) - 8.0 != 10.0 - 3.0 / 2.0 - 8.0 ) {
return false;
};
Expand Down

0 comments on commit 63440bc

Please sign in to comment.