lang: Add getenv function

$x = getenv("NAME")
    $y = defaultenv("NOTEXIST", "defaultvalue")
    $z = hasenv("NAME")
    $a = env()
    $b = maplookup($a, "NAME", "defaultvalue")
This commit is contained in:
Johan Bloemberg
2018-02-22 14:52:21 +01:00
parent a785a43ef3
commit f33f84d2f2
4 changed files with 144 additions and 0 deletions

21
test/shell/env0.sh Executable file
View File

@@ -0,0 +1,21 @@
#!/bin/bash -e
set -o errexit
set -o pipefail
. ../util.sh
# these values represent environment variable values below or defaults set in test/shell/env0.mcl
regex="123,,:123,321,:true,false:123"
tmpdir="$($mktemp --tmpdir -d tmp.XXX)"
env TMPDIR="${tmpdir}" TEST=123 EMPTY="" $timeout -sKILL 60s "$MGMT" run --tmp-prefix --converged-timeout=5 --lang env0.mcl
e=$?
egrep "$regex" "$tmpdir/environ" || fail_test "Could not match '$(cat "$tmpdir/environ")' in '$tmpdir/environ' to '$regex'."
# cleanup if everything went well
rm -r "$tmpdir"
exit $e