test-env-replace.c revision 1f28b2deb4e118cd2d2a5138ccb4cc45841c136d
796b06c21b62d13c9021e2fbd9c58a5c6edb2764Kay Sievers/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
796b06c21b62d13c9021e2fbd9c58a5c6edb2764Kay Sievers This file is part of systemd.
cf7ebcea78223b95b2676b97e1d2aad16caa3c86Kay Sievers Copyright 2010 Lennart Poettering
8db6dcfd3c3d19d35767f04884a99368f6c64b36Kay Sievers systemd is free software; you can redistribute it and/or modify it
8db6dcfd3c3d19d35767f04884a99368f6c64b36Kay Sievers under the terms of the GNU Lesser General Public License as published by
1d09582ab9d8bc619de3a01f01d614eab44d31c0Kay Sievers the Free Software Foundation; either version 2.1 of the License, or
8db6dcfd3c3d19d35767f04884a99368f6c64b36Kay Sievers (at your option) any later version.
378cf88f72a9cda84baf703ed24f54c8c539fdcfKay Sievers systemd is distributed in the hope that it will be useful, but
8db6dcfd3c3d19d35767f04884a99368f6c64b36Kay Sievers WITHOUT ANY WARRANTY; without even the implied warranty of
8db6dcfd3c3d19d35767f04884a99368f6c64b36Kay Sievers MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
8db6dcfd3c3d19d35767f04884a99368f6c64b36Kay Sievers Lesser General Public License for more details.
8db6dcfd3c3d19d35767f04884a99368f6c64b36Kay Sievers You should have received a copy of the GNU Lesser General Public License
8db6dcfd3c3d19d35767f04884a99368f6c64b36Kay Sievers along with systemd; If not, see <http://www.gnu.org/licenses/>.
8db6dcfd3c3d19d35767f04884a99368f6c64b36Kay Sieversstatic void test_strv_env_merge(void) {
1d09582ab9d8bc619de3a01f01d614eab44d31c0Kay Sievers _cleanup_strv_free_ char **a = NULL, **b = NULL, **r = NULL;
8db6dcfd3c3d19d35767f04884a99368f6c64b36Kay Sievers a = strv_new("FOO=BAR", "WALDO=WALDO", "WALDO=", "PIEP", "SCHLUMPF=SMURF", NULL);
1d09582ab9d8bc619de3a01f01d614eab44d31c0Kay Sievers b = strv_new("FOO=KKK", "FOO=", "PIEP=", "SCHLUMPF=SMURFF", "NANANANA=YES", NULL);
378cf88f72a9cda84baf703ed24f54c8c539fdcfKay Sieversstatic void test_replace_env_arg(void) {
8db6dcfd3c3d19d35767f04884a99368f6c64b36Kay Sievers const char *env[] = {
8db6dcfd3c3d19d35767f04884a99368f6c64b36Kay Sievers "FOO=BAR BAR",
8db6dcfd3c3d19d35767f04884a99368f6c64b36Kay Sievers "BAR=waldo",
8db6dcfd3c3d19d35767f04884a99368f6c64b36Kay Sievers const char *line[] = {
09d8f5d757515122d7b726218e249621e564157cKay Sievers "FOO$FOOFOO",
8db6dcfd3c3d19d35767f04884a99368f6c64b36Kay Sievers "FOO${FOO}$FOO",
8db6dcfd3c3d19d35767f04884a99368f6c64b36Kay Sievers "FOO${FOO}",
8db6dcfd3c3d19d35767f04884a99368f6c64b36Kay Sievers "${FOO}${BAR}",
8db6dcfd3c3d19d35767f04884a99368f6c64b36Kay Sievers r = replace_env_argv((char**) line, (char**) env);
8db6dcfd3c3d19d35767f04884a99368f6c64b36Kay Sieversstatic void test_one_normalize(const char *input, const char *output)
8db6dcfd3c3d19d35767f04884a99368f6c64b36Kay Sieversstatic void test_normalize_env_assignment(void) {
f9cd22249dbdcebe2ab54eea56c0b32e2a1c2ce5Mantas Mikulėnas test_one_normalize(" xyz = bar ", "xyz=bar");
f9cd22249dbdcebe2ab54eea56c0b32e2a1c2ce5Mantas Mikulėnas test_one_normalize(" xyz = 'bar ' ", "xyz=bar ");
cf7ebcea78223b95b2676b97e1d2aad16caa3c86Kay Sievers test_one_normalize(" ' xyz' = 'bar ' ", "' xyz'=bar ");