From f454c283031e282ade3db78ce9da3726ec4a0234 Mon Sep 17 00:00:00 2001 From: rl1987 Date: Sun, 12 Aug 2018 15:04:58 +0300 Subject: [PATCH 1/2] Fix test to pass without HOME env being set --- changes/bug27096 | 3 +++ src/test/test_options.c | 14 ++++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 changes/bug27096 diff --git a/changes/bug27096 b/changes/bug27096 new file mode 100644 index 0000000000..d1c139549d --- /dev/null +++ b/changes/bug27096 @@ -0,0 +1,3 @@ + o Minor bugfixes (testing): + - Fix two unit tests to work when HOME environment variable is not + set. Fixes bug 27096; bugfix on 0.2.8.1-alpha. diff --git a/src/test/test_options.c b/src/test/test_options.c index 4e890205b2..dcb8932bec 100644 --- a/src/test/test_options.c +++ b/src/test/test_options.c @@ -473,6 +473,11 @@ test_options_validate__uname_for_server(void *ignored) { (void)ignored; char *msg; + + int unset_home_env = 0; + if (setenv("HOME", "/home/john", 0) == 0) + unset_home_env = 1; + options_test_data_t *tdata = get_options_test_data( "ORPort 127.0.0.1:5555"); setup_capture_of_logs(LOG_WARN); @@ -512,6 +517,8 @@ test_options_validate__uname_for_server(void *ignored) free_options_test_data(tdata); tor_free(msg); teardown_capture_of_logs(); + if (unset_home_env) + unsetenv("HOME"); } static void @@ -1413,6 +1420,11 @@ test_options_validate__paths_needed(void *ignored) (void)ignored; int ret; char *msg; + + int unset_home_env = 0; + if (setenv("HOME", "/home/john", 0) == 0) + unset_home_env = 1; + setup_capture_of_logs(LOG_WARN); options_test_data_t *tdata = get_options_test_data( "PathsNeededToBuildCircuits 0.1\n" @@ -1455,6 +1467,8 @@ test_options_validate__paths_needed(void *ignored) teardown_capture_of_logs(); free_options_test_data(tdata); tor_free(msg); + if (unset_home_env) + unsetenv("HOME"); } static void From fb137b30fc69bb9fa4b417cfe47a8191ecf0a70c Mon Sep 17 00:00:00 2001 From: rl1987 Date: Sun, 12 Aug 2018 15:28:34 +0300 Subject: [PATCH 2/2] Exclude setenv/unsetenv code on Windows --- src/test/test_options.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/test/test_options.c b/src/test/test_options.c index dcb8932bec..801b5895ff 100644 --- a/src/test/test_options.c +++ b/src/test/test_options.c @@ -474,9 +474,11 @@ test_options_validate__uname_for_server(void *ignored) (void)ignored; char *msg; +#ifndef _WIN32 int unset_home_env = 0; if (setenv("HOME", "/home/john", 0) == 0) unset_home_env = 1; +#endif options_test_data_t *tdata = get_options_test_data( "ORPort 127.0.0.1:5555"); @@ -517,8 +519,10 @@ test_options_validate__uname_for_server(void *ignored) free_options_test_data(tdata); tor_free(msg); teardown_capture_of_logs(); +#ifndef _WIN32 if (unset_home_env) unsetenv("HOME"); +#endif } static void @@ -1421,9 +1425,11 @@ test_options_validate__paths_needed(void *ignored) int ret; char *msg; +#ifndef _WIN32 int unset_home_env = 0; if (setenv("HOME", "/home/john", 0) == 0) unset_home_env = 1; +#endif setup_capture_of_logs(LOG_WARN); options_test_data_t *tdata = get_options_test_data( @@ -1467,8 +1473,10 @@ test_options_validate__paths_needed(void *ignored) teardown_capture_of_logs(); free_options_test_data(tdata); tor_free(msg); +#ifndef _WIN32 if (unset_home_env) unsetenv("HOME"); +#endif } static void