1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-06-01 10:08:10 +00:00

LibJS: Add a very basic test runner (shell script) + some tests

This commit is contained in:
Andreas Kling 2020-03-25 14:26:31 +01:00
parent a94a150df0
commit 45488401b1
5 changed files with 93 additions and 0 deletions

View file

@ -0,0 +1,11 @@
function assert(x) { if (!x) throw 1; }
try {
var o = {};
o.foo = 1;
assert(o.hasOwnProperty("foo") === true);
assert(o.hasOwnProperty("bar") === false);
console.log("PASS");
} catch (e) {
console.log("FAIL: " + e);
}

View file

@ -0,0 +1,19 @@
function assert(x) { if (!x) throw 1; }
try {
var s = "foobar"
assert(typeof s === "string");
assert(s.length === 6);
assert(s.charAt(0) === 'f');
assert(s.charAt(1) === 'o');
assert(s.charAt(2) === 'o');
assert(s.charAt(3) === 'b');
assert(s.charAt(4) === 'a');
assert(s.charAt(5) === 'r');
assert(s.charAt(6) === '');
console.log("PASS");
} catch (e) {
console.log("FAIL: " + e);
}

View file

@ -0,0 +1,23 @@
function assert(x) { if (!x) throw 1; }
try {
var a = [1, 2, 3];
assert(typeof a === "object");
assert(a.length === 3);
assert(a[0] === 1);
assert(a[1] === 2);
assert(a[2] === 3);
a[1] = 5;
assert(a[1] === 5);
assert(a.length === 3);
a.push(7);
assert(a[3] === 7);
assert(a.length === 4);
console.log("PASS");
} catch (e) {
console.log("FAIL: " + e);
}

View file

@ -0,0 +1,14 @@
function assert(x) { if (!x) throw 1; }
try {
assert(typeof "foo" === "string");
assert(!(typeof "foo" !== "string"));
assert(typeof (1 + 2) === "number");
assert(typeof {} === "object");
assert(typeof null === "object");
assert(typeof undefined === "undefined");
console.log("PASS");
} catch (e) {
console.log("FAIL: " + e);
}

26
Libraries/LibJS/Tests/run-tests Executable file
View file

@ -0,0 +1,26 @@
#!/bin/bash
if [ "`uname`" = "SerenityOS" ]; then
js_program=/bin/js
else
[ -z "$js_program" ] && js_program="$SERENITY_ROOT/Meta/Lagom/build/js"
fi
pass_count=0
fail_count=0
count=0
for f in *.js; do
echo -n $f:
result=`$js_program $f`
if [ "$result" = "PASS" ]; then
let pass_count++
echo -e "\033[32;1mPASS\033[0m"
else
echo -e "\033[31;1mFAIL\033[0m"
let fail_count++
fi
let count++
done
echo -e "Ran $count tests, Passed: \033[32;1m$pass_count\033[0m, Failed: \033[31;1m$fail_count\033[0m"