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:
19
test/shell/env0.mcl
Normal file
19
test/shell/env0.mcl
Normal file
@@ -0,0 +1,19 @@
|
||||
$tmpdir = defaultenv("TMPDIR", "/tmp")
|
||||
|
||||
$x = getenv("TEST")
|
||||
$y = getenv("DOESNOTEXIST")
|
||||
$z = getenv("EMPTY")
|
||||
|
||||
$a = defaultenv("TEST", "321")
|
||||
$b = defaultenv("DOESNOTEXIST", "321")
|
||||
$c = defaultenv("EMPTY", "456")
|
||||
|
||||
$t = hasenv("TEST")
|
||||
$f = hasenv("DOESNOTEXIST")
|
||||
|
||||
$env = env()
|
||||
$m = maplookup($env, "TEST", "321")
|
||||
|
||||
file "${tmpdir}/environ" {
|
||||
content => printf("%s,%s,%s:%s,%s,%s:%t,%t:%s", $x, $y, $z, $a, $b, $c, $t, $f, $m),
|
||||
}
|
||||
21
test/shell/env0.sh
Executable file
21
test/shell/env0.sh
Executable 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
|
||||
Reference in New Issue
Block a user