From: Simon Ruderich Date: Mon, 1 Jul 2013 00:35:11 +0000 (+0200) Subject: tests/example_exec.c: Sort environment variables. X-Git-Tag: 0.1~15 X-Git-Url: https://ruderich.org/simon/gitweb/?a=commitdiff_plain;h=2c55827f6f2c231a8f166e015df4c5c3818c8ba4;p=coloredstderr%2Fcoloredstderr.git tests/example_exec.c: Sort environment variables. --- diff --git a/tests/example_exec.c b/tests/example_exec.c index 1220f85..415da45 100644 --- a/tests/example_exec.c +++ b/tests/example_exec.c @@ -59,6 +59,9 @@ static int find_magic_run_number(char *argv0, int *number) { return 1; } +static int cmp(void const *a, void const *b) { + return strcmp(*(char * const *)a, *(char * const *)b); +} static void dump(char *argv[]) { size_t i; @@ -66,14 +69,23 @@ static void dump(char *argv[]) { while (*argv) { printf("argv[%zu] = |%s|\n", i++, *argv++); } + + /* Order of environment variables is not defined, sort them for consistent + * test results. */ i = 0; char **env = environ; + while (*env++) { + i++; + } + qsort(environ, i, sizeof(*env), cmp); + + i = 0; + env = environ; while (*env) { /* Skip LD_PRELOAD which contains system dependent values. */ if (strncmp(*env, "LD_PRELOAD=", 11)) { - printf("environ[%zu] = |%s|\n", i, *env); + printf("environ[%zu] = |%s|\n", i++, *env); } - i++; env++; } printf("\n"); @@ -321,14 +333,14 @@ int main(int argc unused, char **argv) { /* Fake output to let the test pass. */ } else if (!skip--) { puts("argv[0] = |./example_exec|"); - puts("environ[0] = |TEST=54|"); - puts("environ[2] = |COLORED_STDERR_PRIVATE_FDS=2,|"); + puts("environ[0] = |COLORED_STDERR_PRIVATE_FDS=2,|"); + puts("environ[1] = |TEST=54|"); puts(""); puts("argv[0] = |./example_exec|"); puts("argv[1] = |foo|"); puts("argv[2] = |bar|"); - puts("environ[0] = |TEST=55|"); - puts("environ[2] = |COLORED_STDERR_PRIVATE_FDS=2,|"); + puts("environ[0] = |COLORED_STDERR_PRIVATE_FDS=2,|"); + puts("environ[1] = |TEST=55|"); puts(""); #endif } diff --git a/tests/example_exec.expected b/tests/example_exec.expected index 61ca212..8dee58c 100644 --- a/tests/example_exec.expected +++ b/tests/example_exec.expected @@ -1,125 +1,125 @@ argv[0] = |./example_exec| -environ[1] = |COLORED_STDERR_PRIVATE_FDS=2,| +environ[0] = |COLORED_STDERR_PRIVATE_FDS=2,| CHECKING COLORING. argv[0] = |./example_exec| -environ[1] = |COLORED_STDERR_PRIVATE_FDS=2,3,| +environ[0] = |COLORED_STDERR_PRIVATE_FDS=2,3,| argv[0] = |./example_exec| -environ[1] = |COLORED_STDERR_PRIVATE_FDS=2,3,4,| +environ[0] = |COLORED_STDERR_PRIVATE_FDS=2,3,4,| argv[0] = |./example_exec| -environ[1] = |COLORED_STDERR_PRIVATE_FDS=2,3,4,5,| +environ[0] = |COLORED_STDERR_PRIVATE_FDS=2,3,4,5,| argv[0] = |./example_exec| -environ[1] = |COLORED_STDERR_PRIVATE_FDS=2,3,4,5,6,| +environ[0] = |COLORED_STDERR_PRIVATE_FDS=2,3,4,5,6,| argv[0] = |./example_exec| -environ[1] = |COLORED_STDERR_PRIVATE_FDS=2,3,4,7,| +environ[0] = |COLORED_STDERR_PRIVATE_FDS=2,3,4,7,| argv[0] = |./example_exec| -environ[1] = |COLORED_STDERR_PRIVATE_FDS=2,3,8,| +environ[0] = |COLORED_STDERR_PRIVATE_FDS=2,3,8,| argv[0] = |./example_exec| -environ[1] = |COLORED_STDERR_FDS=5,| -environ[2] = |COLORED_STDERR_PRIVATE_FDS=2,5,| +environ[0] = |COLORED_STDERR_FDS=5,| +environ[1] = |COLORED_STDERR_PRIVATE_FDS=2,5,| argv[0] = |./example_exec| -environ[1] = |COLORED_STDERR_PRIVATE_FDS=6,| +environ[0] = |COLORED_STDERR_PRIVATE_FDS=6,| argv[0] = |./example_exec| +environ[0] = |COLORED_STDERR_FDS=2,| environ[1] = |COLORED_STDERR_PRIVATE_FDS=| -environ[2] = |COLORED_STDERR_FDS=2,| CHECKING TRANSPARENCY. argv[0] = |./example_exec| -environ[1] = |COLORED_STDERR_PRIVATE_FDS=2,| +environ[0] = |COLORED_STDERR_PRIVATE_FDS=2,| argv[0] = |./example_exec| -environ[0] = |TEST=42| -environ[2] = |COLORED_STDERR_PRIVATE_FDS=2,| +environ[0] = |COLORED_STDERR_PRIVATE_FDS=2,| +environ[1] = |TEST=42| argv[0] = |./example_exec| argv[1] = |foo| argv[2] = |bar| -environ[0] = |TEST=43| +environ[0] = |COLORED_STDERR_PRIVATE_FDS=2,| environ[1] = |FOO=| -environ[3] = |COLORED_STDERR_PRIVATE_FDS=2,| +environ[2] = |TEST=43| argv[0] = |./example_exec| -environ[0] = |TEST=44| +environ[0] = |COLORED_STDERR_PRIVATE_FDS=2,| environ[1] = |FOO=| -environ[3] = |COLORED_STDERR_PRIVATE_FDS=2,| +environ[2] = |TEST=44| argv[0] = |./example_exec| argv[1] = |foo| argv[2] = |bar| -environ[0] = |TEST=45| +environ[0] = |COLORED_STDERR_PRIVATE_FDS=2,| environ[1] = |FOO=| -environ[3] = |COLORED_STDERR_PRIVATE_FDS=2,| +environ[2] = |TEST=45| argv[0] = |./example_exec| -environ[0] = |TEST=46| +environ[0] = |COLORED_STDERR_PRIVATE_FDS=2,| environ[1] = |FOO=| -environ[3] = |COLORED_STDERR_PRIVATE_FDS=2,| +environ[2] = |TEST=46| argv[0] = |./example_exec| argv[1] = |foo| argv[2] = |bar| -environ[0] = |TEST=47| +environ[0] = |COLORED_STDERR_PRIVATE_FDS=2,| environ[1] = |FOO=| -environ[3] = |COLORED_STDERR_PRIVATE_FDS=2,| +environ[2] = |TEST=47| argv[0] = |./example_exec| -environ[1] = |COLORED_STDERR_PRIVATE_FDS=2,| +environ[0] = |COLORED_STDERR_PRIVATE_FDS=2,| argv[0] = |./example_exec| -environ[0] = |TEST=48| -environ[2] = |COLORED_STDERR_PRIVATE_FDS=2,| +environ[0] = |COLORED_STDERR_PRIVATE_FDS=2,| +environ[1] = |TEST=48| argv[0] = |./example_exec| argv[1] = |foo| argv[2] = |bar| -environ[0] = |TEST=49| +environ[0] = |COLORED_STDERR_PRIVATE_FDS=2,| environ[1] = |FOO=| -environ[3] = |COLORED_STDERR_PRIVATE_FDS=2,| +environ[2] = |TEST=49| argv[0] = |./example_exec| -environ[0] = |TEST=50| +environ[0] = |COLORED_STDERR_PRIVATE_FDS=2,| environ[1] = |FOO=| -environ[3] = |COLORED_STDERR_PRIVATE_FDS=2,| +environ[2] = |TEST=50| argv[0] = |./example_exec| argv[1] = |foo| argv[2] = |bar| -environ[0] = |TEST=51| +environ[0] = |COLORED_STDERR_PRIVATE_FDS=2,| environ[1] = |FOO=| -environ[3] = |COLORED_STDERR_PRIVATE_FDS=2,| +environ[2] = |TEST=51| argv[0] = |./example_exec| -environ[0] = |TEST=52| +environ[0] = |COLORED_STDERR_PRIVATE_FDS=2,| environ[1] = |FOO=| -environ[3] = |COLORED_STDERR_PRIVATE_FDS=2,| +environ[2] = |TEST=52| argv[0] = |./example_exec| argv[1] = |foo| argv[2] = |bar| -environ[0] = |TEST=53| +environ[0] = |COLORED_STDERR_PRIVATE_FDS=2,| environ[1] = |FOO=| -environ[3] = |COLORED_STDERR_PRIVATE_FDS=2,| +environ[2] = |TEST=53| argv[0] = |./example_exec| -environ[0] = |TEST=54| -environ[2] = |COLORED_STDERR_PRIVATE_FDS=2,| +environ[0] = |COLORED_STDERR_PRIVATE_FDS=2,| +environ[1] = |TEST=54| argv[0] = |./example_exec| argv[1] = |foo| argv[2] = |bar| -environ[0] = |TEST=55| -environ[2] = |COLORED_STDERR_PRIVATE_FDS=2,| +environ[0] = |COLORED_STDERR_PRIVATE_FDS=2,| +environ[1] = |TEST=55| Done.