Add shell plugin model tests
This commit is contained in:
@@ -0,0 +1,80 @@
|
||||
#!/bin/bash
|
||||
|
||||
if [[ ${BASH_SOURCE[0]} == "$0" ]]; then
|
||||
echo "source test/shell.d/base-test.sh from a shell test; do not run it directly" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
ROOT=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/../.." && pwd)
|
||||
SHELL_TEST_DIR="$ROOT/test/shell.d"
|
||||
|
||||
export ROOT
|
||||
|
||||
pass() {
|
||||
printf 'ok - %s\n' "$1"
|
||||
}
|
||||
|
||||
fail() {
|
||||
local description="$1"
|
||||
local detail="${2:-}"
|
||||
|
||||
[[ -n $detail ]] && printf '%s\n' "$detail" >&2
|
||||
printf 'not ok - %s\n' "$description" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
require_command() {
|
||||
local command="$1"
|
||||
|
||||
command -v "$command" >/dev/null || fail "required command is available: $command"
|
||||
}
|
||||
|
||||
run_node_test() {
|
||||
require_command node
|
||||
|
||||
{
|
||||
cat <<'JS_PRELUDE'
|
||||
const path = require('path')
|
||||
const root = process.env.ROOT
|
||||
|
||||
function fail(description, detail) {
|
||||
if (detail) console.error(detail)
|
||||
console.error(`not ok - ${description}`)
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
function pass(description) {
|
||||
console.log(`ok - ${description}`)
|
||||
}
|
||||
|
||||
function assert(condition, description, detail) {
|
||||
if (!condition) fail(description, detail)
|
||||
pass(description)
|
||||
}
|
||||
|
||||
function assertEqual(actual, expected, description) {
|
||||
assert(
|
||||
actual === expected,
|
||||
description,
|
||||
`expected: ${expected}\nactual: ${actual}`
|
||||
)
|
||||
}
|
||||
|
||||
function assertDeepEqual(actual, expected, description) {
|
||||
const actualJson = JSON.stringify(actual)
|
||||
const expectedJson = JSON.stringify(expected)
|
||||
assert(
|
||||
actualJson === expectedJson,
|
||||
description,
|
||||
`expected: ${expectedJson}\nactual: ${actualJson}`
|
||||
)
|
||||
}
|
||||
|
||||
function requireFromRoot(relativePath) {
|
||||
return require(path.join(root, relativePath))
|
||||
}
|
||||
|
||||
JS_PRELUDE
|
||||
cat
|
||||
} | node
|
||||
}
|
||||
Reference in New Issue
Block a user