## Bash language validator tests.
import std/[unittest, strutils, strformat]
import ../src/validatrix
import test_common
proc checkValid(result: ValidationResult, context: string = "") =
if result.errors.len > 0:
var msg = &"Expected valid, got {result.errors.len} error(s)"
if context.len > 0: msg.add(&" [{context}]")
for e in result.errors: msg.add(&"\n [{e.code}] {e.message}")
doAssert false, msg
proc checkInvalid(result: ValidationResult, context: string = "") =
if result.errors.len == 0:
doAssert false, &"Expected errors, got none [{context}]"
suite "Bash Validator":
test "valid Bash code":
let result = validateSource(BashGoodCode, flavor = lfBash)
checkValid(result)
test "invalid Bash code returns errors":
let result = validateSource(BashBadCode, flavor = lfBash)
checkInvalid(result)
test "valid .sh file":
let result = validateFile("tests/fixtures/bash/valid.sh")
checkValid(result)
test "invalid .sh file returns errors":
let result = validateFile("tests/fixtures/bash/invalid.sh")
check result.errors.len > 0
test "detectFlavor detects Bash from shebang":
check $detectFlavor(BashGoodCode) == "bash"
test "inspectSource returns JSON":
let json = inspectSource(BashGoodCode, flavor = lfBash)
check json.kind == JObject
check "flavor" in json