mirror of https://github.com/djcb/mu.git
* fix mu_util_dir_expand for non-existant dirs, add unit test
This commit is contained in:
parent
6a3decdc7c
commit
0b87be5f18
|
@ -93,7 +93,11 @@ mu_util_dir_expand (const char *path)
|
|||
dir = do_wordexp (path);
|
||||
if (!dir)
|
||||
return NULL; /* error */
|
||||
|
||||
|
||||
/* don't try realpath if the dir does not exist */
|
||||
if (access (dir, F_OK) != 0)
|
||||
return dir;
|
||||
|
||||
/* now resolve any symlinks, .. etc. */
|
||||
if (realpath (dir, resolved) == NULL) {
|
||||
g_debug ("%s: could not get realpath for '%s': %s",
|
||||
|
|
|
@ -30,6 +30,22 @@
|
|||
#include "test-mu-common.h"
|
||||
#include "src/mu-util.h"
|
||||
|
||||
static void
|
||||
test_mu_util_dir_expand_00 (void)
|
||||
{
|
||||
gchar *got, *expected;
|
||||
|
||||
got = mu_util_dir_expand ("~/IProbablyDoNotExist");
|
||||
expected = g_strdup_printf ("%s%cIProbablyDoNotExist",
|
||||
getenv("HOME"), G_DIR_SEPARATOR);
|
||||
|
||||
g_assert_cmpstr (got,==,expected);
|
||||
|
||||
g_free (got);
|
||||
g_free (expected);
|
||||
|
||||
}
|
||||
|
||||
static void
|
||||
test_mu_util_dir_expand_01 (void)
|
||||
{
|
||||
|
@ -46,6 +62,7 @@ test_mu_util_dir_expand_01 (void)
|
|||
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
test_mu_util_dir_expand_02 (void)
|
||||
{
|
||||
|
@ -203,6 +220,7 @@ main (int argc, char *argv[])
|
|||
g_test_init (&argc, &argv, NULL);
|
||||
|
||||
/* mu_util_dir_expand */
|
||||
g_test_add_func ("/mu-util/mu-util-dir-expand-00", test_mu_util_dir_expand_00);
|
||||
g_test_add_func ("/mu-util/mu-util-dir-expand-01", test_mu_util_dir_expand_01);
|
||||
g_test_add_func ("/mu-util/mu-util-dir-expand-02", test_mu_util_dir_expand_02);
|
||||
g_test_add_func ("/mu-util/mu-util-dir-expand-03", test_mu_util_dir_expand_03);
|
||||
|
|
Loading…
Reference in New Issue