Skip to content

Commit

Permalink
Fix invalid home test
Browse files Browse the repository at this point in the history
If a user has set environment variable GNC_DATA_HOME
to a valid directory (containing real gnucash metadata)
the test would fail. It expects to follow the code path
to set up a gnucash data home directory in the temporary
directory, but the directory pointed to in GNC_DATA_HOME
is used instead.
Fix this by also setting environment variable GNC_DATA_HOME
to something invalid during the test.
  • Loading branch information
gjanssens committed Oct 31, 2024
1 parent cf73829 commit 831ce06
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions libgnucash/core-utils/test/test-userdata-dir-invalid-home.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ main(G_GNUC_UNUSED int argc, G_GNUC_UNUSED char **argv)
const char *tmp_dir = g_get_tmp_dir();
const char *builddir = g_getenv ("GNC_BUILDDIR");
char *homedir = g_build_filename (builddir, "notexist", NULL);
char *testdatahome = g_build_filename (homedir, "gnucash", NULL);

/* Assume we're not in a build environment to test
* the function's actual behaviour in a real world use case, using
Expand All @@ -83,7 +84,9 @@ main(G_GNUC_UNUSED int argc, G_GNUC_UNUSED char **argv)
* The code should fall back to using the temporary
* directory in that case. */
g_setenv("HOME", homedir, TRUE);
g_setenv("GNC_DATA_HOME", testdatahome, TRUE);
g_free (homedir);
g_free (testdatahome);

for (i = 0; strs2[i].funcname != NULL; i++)
{
Expand Down

0 comments on commit 831ce06

Please sign in to comment.