RosettaCodeData/Task/Assertions/AWK/assertions.awk

22 lines
571 B
Awk
Raw Permalink Normal View History

2023-07-01 11:58:00 -04:00
BEGIN {
2026-04-30 12:34:36 -04:00
meaning = 6 * 7
assert(meaning == 42, "Integer mathematics failed")
assert(meaning == 42)
meaning = strtonum("42 also known as forty-two")
assert(meaning == 42, "Built-in function failed")
meaning = "42"
assert(meaning == 42, "Dynamic type conversion failed")
meaning = 6 * 9
assert(meaning == 42, "Ford Prefect's experiment failed")
print "That's all folks"
exit
2023-07-01 11:58:00 -04:00
}
# Errormsg is optional, displayed if assertion fails
function assert(cond, errormsg){
2026-04-30 12:34:36 -04:00
if (!cond) {
if (errormsg != "") print errormsg
exit 1
}
2023-07-01 11:58:00 -04:00
}