diff options
author | Sergey Poznyakoff <gray@gnu.org> | 2019-06-02 07:40:11 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org> | 2019-06-02 08:03:16 +0300 |
commit | cc298a11a131b162f291d6ee27ba1d7598a1b6c4 (patch) | |
tree | 4d82a9a5da05fbfdce0c9bf03e605ecf00baa07a /tests | |
parent | 1f28935841a69aa8be7eb2e88f580df9c95206d2 (diff) | |
download | pies-cc298a11a131b162f291d6ee27ba1d7598a1b6c4.tar.gz pies-cc298a11a131b162f291d6ee27ba1d7598a1b6c4.tar.bz2 |
New configuration statement for manipulating the environment.
The "env" statement is now a compound statement. It can contain four
substatements: "clear" to clear the environment, "keep" to retain
certain variable while clearing it, "set" to set a variable, and
"unset" to unset a variable or variables.
Both "keep" and "unset" can take globbing pattern as their argument,
in which case they affect all variable matching that pattern.
The value part in the "set" statement is subject to variable expansion,
e.g.
set "MANPATH=$MANPATH${MANPATH:+:}/usr/local/man"
The support for the old one-line syntax of "env" is retained for
backward compatibility.
This commit also fixes redirection to a file: new data are appended
to the file, instead of overwriting it.
* lib/Makefile.am: Add new files.
* lib/envop.c: New file.
* lib/envop.h: New file.
* lib/wildmatch.c: New file.
* src/comp.c (component_free): Update.
* src/pies.c (argv_free): New function.
(parse_legacy_env): New function.
(_cb_env): Remove.
(cb_env_section_parser): New function.
(cb_env_keywords): New keywords for the "env" block statement:
clear, keep, set, unset.
(component_keywords): New compount statement: env.
Old usage retained for backward compatibility.
* src/pies.h: Include "envop.h"
(component)<env>: Remove.
<envop>: New field.
* src/prog.h (prog)<env>: New field.
* src/progman.c (redirect_to_file): Position to the end of file.
(DEBUG_ENVIRON): Remove macro.
(debug_environ): New function.
(environ_setup): Remove.
(prog_sockenv): Use environ_set to modify local copy of environment.
(prog_start_prologue): Use environ_create + envop_exec to create and
modify the environment.
(prog_execute): Set environment to prog-local copy.
* tests/.gitignore: Build envtest
* tests/Makefile.am: Add new tests.
* tests/testsuite.at: Add environment tests.
* tests/envop.at: New file.
* tests/envtest.c: New file.
* tests/env.at: New file.
* tests/redirect.at: Check first two lines of the output file.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/.gitignore | 1 | ||||
-rw-r--r-- | tests/Makefile.am | 11 | ||||
-rw-r--r-- | tests/env.at | 65 | ||||
-rw-r--r-- | tests/envop.at | 101 | ||||
-rw-r--r-- | tests/envtest.c | 209 | ||||
-rw-r--r-- | tests/redirect.at | 2 | ||||
-rw-r--r-- | tests/testsuite.at | 3 |
7 files changed, 391 insertions, 1 deletions
diff --git a/tests/.gitignore b/tests/.gitignore index 93f8f46..276645a 100644 --- a/tests/.gitignore +++ b/tests/.gitignore | |||
@@ -1,5 +1,6 @@ | |||
1 | atconfig | 1 | atconfig |
2 | atlocal | 2 | atlocal |
3 | envtest | ||
3 | package.m4 | 4 | package.m4 |
4 | testsuite | 5 | testsuite |
5 | testsuite.dir | 6 | testsuite.dir |
diff --git a/tests/Makefile.am b/tests/Makefile.am index 39899c8..419818b 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am | |||
@@ -48,6 +48,8 @@ TESTSUITE_AT = \ | |||
48 | testsuite.at\ | 48 | testsuite.at\ |
49 | control.at\ | 49 | control.at\ |
50 | cyclic.at\ | 50 | cyclic.at\ |
51 | env.at\ | ||
52 | envop.at\ | ||
51 | respawn.at\ | 53 | respawn.at\ |
52 | redirect.at\ | 54 | redirect.at\ |
53 | ret-exec.at\ | 55 | ret-exec.at\ |
@@ -60,6 +62,15 @@ TESTSUITE_AT = \ | |||
60 | TESTSUITE = $(srcdir)/testsuite | 62 | TESTSUITE = $(srcdir)/testsuite |
61 | M4=m4 | 63 | M4=m4 |
62 | 64 | ||
65 | noinst_PROGRAMS = envtest | ||
66 | AM_CPPFLAGS = \ | ||
67 | -I$(top_srcdir)/lib\ | ||
68 | @GRECS_INCLUDES@ | ||
69 | |||
70 | LDADD = \ | ||
71 | ../lib/libpies.a\ | ||
72 | @GRECS_LDADD@ | ||
73 | |||
63 | AUTOTEST = $(AUTOM4TE) --language=autotest | 74 | AUTOTEST = $(AUTOM4TE) --language=autotest |
64 | $(TESTSUITE): package.m4 $(TESTSUITE_AT) | 75 | $(TESTSUITE): package.m4 $(TESTSUITE_AT) |
65 | $(AM_V_GEN)$(AUTOTEST) -I $(srcdir) testsuite.at -o $@.tmp | 76 | $(AM_V_GEN)$(AUTOTEST) -I $(srcdir) testsuite.at -o $@.tmp |
diff --git a/tests/env.at b/tests/env.at new file mode 100644 index 0000000..26fe866 --- /dev/null +++ b/tests/env.at | |||
@@ -0,0 +1,65 @@ | |||
1 | dnl ENVTEST(NAME,KW,ENV,OUT) | ||
2 | m4_pushdef([ENVTEST], | ||
3 | [AT_SETUP([$1]) | ||
4 | AT_KEYWORDS([env $2]) | ||
5 | AT_CHECK([ | ||
6 | PIES_XFAIL_CHECK | ||
7 | PIES_CONTROL_INIT | ||
8 | cat > envtest.conf <<_EOT | ||
9 | component envtest { | ||
10 | env { | ||
11 | $3 | ||
12 | } | ||
13 | command "$abs_builddir/envtest -clone"; | ||
14 | chdir $PWD; | ||
15 | stdout file "$PWD/log"; | ||
16 | return-code 0 { | ||
17 | action disable; | ||
18 | exec "piesctl --url unix:///$PWD/pies.ctl shutdown"; | ||
19 | } | ||
20 | } | ||
21 | _EOT | ||
22 | |||
23 | envtest -exec $abs_top_builddir/src/pies --foreground --stderr --config-file control.conf --config-file envtest.conf 2>errlog | ||
24 | cat log | ||
25 | ], | ||
26 | [0], | ||
27 | [$4]) | ||
28 | AT_CLEANUP]) | ||
29 | |||
30 | dnl ############################# | ||
31 | dnl Start tests | ||
32 | dnl ############################# | ||
33 | |||
34 | AT_BANNER([Environment statement]) | ||
35 | |||
36 | ENVTEST([clear],[clear],[clear yes;],[]) | ||
37 | |||
38 | ENVTEST([keep],[keep],[keep "LC_*";], | ||
39 | [LC_ALL="C" | ||
40 | LC_CTYPE="C" | ||
41 | LC_MESSAGES="C" | ||
42 | LC_NUMERIC="C" | ||
43 | ]) | ||
44 | |||
45 | ENVTEST([set],[set],[set "FOO=bar";], | ||
46 | [FOO="bar" | ||
47 | HOME="/home/user" | ||
48 | LC_ALL="C" | ||
49 | LC_CTYPE="C" | ||
50 | LC_MESSAGES="C" | ||
51 | LC_NUMERIC="C" | ||
52 | LOGIN="user" | ||
53 | PATH="/usr/local/bin:/usr/bin:/bin" | ||
54 | PIES_INSTANCE="pies" | ||
55 | PWD="/home" | ||
56 | USER="user" | ||
57 | ]) | ||
58 | |||
59 | ENVTEST([unset],[unset],[unset "LC_*"; unset PWD;], | ||
60 | [HOME="/home/user" | ||
61 | LOGIN="user" | ||
62 | PATH="/usr/local/bin:/usr/bin:/bin" | ||
63 | PIES_INSTANCE="pies" | ||
64 | USER="user" | ||
65 | ]) | ||
diff --git a/tests/envop.at b/tests/envop.at new file mode 100644 index 0000000..6f634fb --- /dev/null +++ b/tests/envop.at | |||
@@ -0,0 +1,101 @@ | |||
1 | # ENVTEST(name,kw,args,output) | ||
2 | m4_pushdef([ENVTEST], | ||
3 | [AT_SETUP([$1]) | ||
4 | AT_KEYWORDS([envop $2]) | ||
5 | AT_CHECK([envtest $3], | ||
6 | [0], | ||
7 | [$4]) | ||
8 | AT_CLEANUP | ||
9 | ]) | ||
10 | dnl ############################# | ||
11 | dnl Start tests | ||
12 | dnl ############################# | ||
13 | |||
14 | AT_BANNER([Environment modification framework]) | ||
15 | |||
16 | ENVTEST([default environment],[defenv],[], | ||
17 | [HOME="/home/user" | ||
18 | LC_ALL="C" | ||
19 | LC_CTYPE="C" | ||
20 | LC_MESSAGES="C" | ||
21 | LC_NUMERIC="C" | ||
22 | LOGIN="user" | ||
23 | PATH="/usr/local/bin:/usr/bin:/bin" | ||
24 | PWD="/home" | ||
25 | USER="user" | ||
26 | ]) | ||
27 | |||
28 | ENVTEST([clear],[clear],[-clear]) | ||
29 | |||
30 | ENVTEST([keep name],[keep],[-clear -keep HOME USER], | ||
31 | [HOME="/home/user" | ||
32 | USER="user" | ||
33 | ]) | ||
34 | |||
35 | ENVTEST([keep name=value],[keep],[-clear -keep USER=user], | ||
36 | [USER="user" | ||
37 | ]) | ||
38 | |||
39 | ENVTEST([keep name=value (mismatch)],[keep],[-clear -keep USER=gray]) | ||
40 | |||
41 | ENVTEST([keep wildcard],[keep],[-clear -keep 'LC_*'], | ||
42 | [LC_ALL="C" | ||
43 | LC_CTYPE="C" | ||
44 | LC_MESSAGES="C" | ||
45 | LC_NUMERIC="C" | ||
46 | ]) | ||
47 | |||
48 | ENVTEST([keep wildcard (2)],[keep],[-clear -keep 'LC_*A*'], | ||
49 | [LC_ALL="C" | ||
50 | LC_MESSAGES="C" | ||
51 | ]) | ||
52 | |||
53 | ENVTEST([keep wildcard (mismatch)],[keep],[-clear -keep 'LC_*A*R']) | ||
54 | |||
55 | ENVTEST([set],[set],[-set FOO=bar BAR=bar], | ||
56 | [BAR="bar" | ||
57 | FOO="bar" | ||
58 | HOME="/home/user" | ||
59 | LC_ALL="C" | ||
60 | LC_CTYPE="C" | ||
61 | LC_MESSAGES="C" | ||
62 | LC_NUMERIC="C" | ||
63 | LOGIN="user" | ||
64 | PATH="/usr/local/bin:/usr/bin:/bin" | ||
65 | PWD="/home" | ||
66 | USER="user" | ||
67 | ]) | ||
68 | |||
69 | ENVTEST([set (variable expansion)],[set],[-set 'PATH=${PATH}${PATH:+:}$HOME'], | ||
70 | [HOME="/home/user" | ||
71 | LC_ALL="C" | ||
72 | LC_CTYPE="C" | ||
73 | LC_MESSAGES="C" | ||
74 | LC_NUMERIC="C" | ||
75 | LOGIN="user" | ||
76 | PATH="/usr/local/bin:/usr/bin:/bin:/home/user" | ||
77 | PWD="/home" | ||
78 | USER="user" | ||
79 | ]) | ||
80 | |||
81 | ENVTEST([unset name],[unset],[-unset HOME], | ||
82 | [LC_ALL="C" | ||
83 | LC_CTYPE="C" | ||
84 | LC_MESSAGES="C" | ||
85 | LC_NUMERIC="C" | ||
86 | LOGIN="user" | ||
87 | PATH="/usr/local/bin:/usr/bin:/bin" | ||
88 | PWD="/home" | ||
89 | USER="user" | ||
90 | ]) | ||
91 | |||
92 | ENVTEST([unset wildcard],[unset],[-unset 'LC_*'], | ||
93 | [HOME="/home/user" | ||
94 | LOGIN="user" | ||
95 | PATH="/usr/local/bin:/usr/bin:/bin" | ||
96 | PWD="/home" | ||
97 | USER="user" | ||
98 | ]) | ||
99 | |||
100 | m4_popdef([ENVTEST]) | ||
101 | |||
diff --git a/tests/envtest.c b/tests/envtest.c new file mode 100644 index 0000000..d6b5650 --- /dev/null +++ b/tests/envtest.c | |||
@@ -0,0 +1,209 @@ | |||
1 | /* Environment test program for GNU Pies. | ||
2 | Copyright (C) 2019 Sergey Poznyakoff | ||
3 | |||
4 | GNU Pies is free software; you can redistribute it and/or modify | ||
5 | it under the terms of the GNU General Public License as published by | ||
6 | the Free Software Foundation; either version 3, or (at your option) | ||
7 | any later version. | ||
8 | |||
9 | GNU Pies is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | GNU General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU General Public License | ||
15 | along with GNU Pies. If not, see <http://www.gnu.org/licenses/>. */ | ||
16 | |||
17 | #ifdef HAVE_CONFIG_H | ||
18 | # include <config.h> | ||
19 | #endif | ||
20 | #include <stdlib.h> | ||
21 | #include <stdio.h> | ||
22 | #include <string.h> | ||
23 | #include <unistd.h> | ||
24 | #include <errno.h> | ||
25 | #include <ctype.h> | ||