X-Git-Url: https://ruderich.org/simon/gitweb/?p=coloredstderr%2Fcoloredstderr.git;a=blobdiff_plain;f=tests%2Fexample_exec.c;h=e13010b8ee17bb6601cbcd31e97c3abcd5ce02c7;hp=1220f853618bd326539de885c8f58735c31327f2;hb=8a65b4486febf00e3fad5bafc3773a811e675a4c;hpb=219a9882ba55e2dc60f0ab40a2a3afcc7130417c diff --git a/tests/example_exec.c b/tests/example_exec.c index 1220f85..e13010b 100644 --- a/tests/example_exec.c +++ b/tests/example_exec.c @@ -1,7 +1,7 @@ /* * Test execve() and exec*() functions. * - * Copyright (C) 2013 Simon Ruderich + * Copyright (C) 2013-2015 Simon Ruderich * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -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 }