Debian Codegraph @

test/units/TEST-81-GENERATORS.environment-d-generator.sh

raw symbols SCIP
1 #!/usr/bin/envscip-shell filesystem . . `/usr/bin/env`. bash
2 # SPDX-License-Identifier: LGPL-2.1-or-later
3 # shellcheck disable=SC2235
4 set -eux
5 set -o pipefail
6
7 # shellcheck source=test/units/generator-utils.sh
8 . "$(dirnamescip-shell system . . dirname. "$0")/generator-utils.sh"
9
10 GENERATOR_BIN="/usr/lib/systemd/user-environment-generators/30-systemd-environment-d-generatorscip-shell filesystem . . `/usr/lib/systemd/user-environment-generators/30-systemd-environment-d-generator`."
11 CONFIG_FILE="/run/environment.d/99-test.confscip-shell filesystem . . `/run/environment.d/99-test.conf`."
12 OUT_FILE="$(mktempscip-shell system . . mktemp.)"
13
14 at_exitscip-shell shell systemd 261~rc4-1 at_exit().() {
15 set +e
16 rmscip-shell system . . rm. -frv "${CONFIG_FILE:?}" "${OUT_FILE:?}"
17 systemctl -M [email protected] --user daemon-reload
18 }
19
20 trap at_exit EXIT
21
22 testscip-shell system . . test. -x "${GENERATOR_BIN:?}"
23 mkdirscip-shell system . . mkdir. -p /run/environment.d/scip-shell filesystem . . `/run/environment.d/`.
24
25 catscip-shell system . . cat. >"$CONFIG_FILE" <<EOF
26
27 \t\n\t
28 3
29 =
30 =
31 INVALID
32 ALSO_INVALID=
33 EMPTY_INVALID=""
34 3_INVALID=foo
35 xxxx xx xxxxxx
36 # This is a comment
37 $(printfscip-shell system . . printf. "%.0sx" {0..4096})=
38 SIMPLE=foo
39 REF=\$SIMPLE
40 ALSO_REF=\${SIMPLE}
41 DEFAULT="\${NONEXISTENT:-default value}"
42 ALTERNATE="\${SIMPLE:+alternate value}"
43 LIST=foo,bar,baz
44 SIMPLE=redefined
45 UNASSIGNED=\$FOO_BAR_BAZ
46 VERY_LONG="very $(printfscip-shell system . . printf. "%.0sx" {0..4096})= long string"
47 EOF
48
49 # Source env assignments from a file and check them - do this in a subshell
50 # to not pollute the test environment
51 check_environmentscip-shell shell systemd 261~rc4-1 check_environment().() {(
52 # shellcheck source=/dev/null
53 source "${1:?}"
54
55 [[ "$SIMPLE" == "redefined" ]]
56 [[ "$REF" == "foo" ]]
57 [[ "$ALSO_REF" == "foo" ]]
58 [[ "$DEFAULT" == "default value" ]]
59 [[ "$ALTERNATE" == "alternate value" ]]
60 [[ "$LIST" == "foo,bar,baz" ]]
61 [[ "$VERY_LONG" =~ ^very\ ]]
62 [[ "$VERY_LONG" =~ \ long\ string$ ]]
63 [[ -z "$UNASSIGNED" ]]
64 [[ ! -v INVALID ]]
65 [[ ! -v ALSO_INVALID ]]
66 [[ ! -v EMPTY_INVALID ]]
67 [[ ! -v 3_INVALID ]]
68 )}
69
70 # Check the output by directly calling the generator
71 "$GENERATOR_BIN" | teescip-shell system . . tee. "$OUT_FILE"
72 check_environmentscip-shell shell systemd 261~rc4-1 check_environment(). "$OUT_FILE"
73 : >"$OUT_FILE"
74
75 # Check if the generator is correctly called in a user session
76 systemctl -M [email protected] --user daemon-reload
77 systemctl -M [email protected] --user show-environment | teescip-shell system . . tee. "$OUT_FILE"
78 check_environmentscip-shell shell systemd 261~rc4-1 check_environment(). "$OUT_FILE"
79
80 (! "$GENERATOR_BIN" foo)