Merge branch 'fix-gutils-user-database' into 'main'

Fix gutils-user-database unit test

See merge request GNOME/glib!3564
This commit is contained in:
Philip Withnall 2023-09-06 12:11:49 +00:00
commit a2a5d91354
3 changed files with 50 additions and 4 deletions

View File

@ -47,3 +47,35 @@ getpwuid (uid_t uid)
my_pw.pw_name = NULL;
return &my_pw;
}
int
getpwnam_r (const char *name, struct passwd *pwd, char buf[], size_t buflen, struct passwd **result)
{
int code;
int (*real_getpwnam_r) (const char *,
struct passwd *,
char[],
size_t,
struct passwd **) = dlsym (RTLD_NEXT, "getpwnam_r");
code = real_getpwnam_r (name, pwd, buf, buflen, result);
pwd->pw_name = NULL;
return code;
}
int
getpwuid_r (uid_t uid, struct passwd *restrict pwd, char buf[], size_t buflen, struct passwd **result)
{
int code;
int (*real_getpwuid_r) (uid_t,
struct passwd *,
char[],
size_t,
struct passwd **) = dlsym (RTLD_NEXT, "getpwuid_r");
code = real_getpwuid_r (uid, pwd, buf, buflen, result);
pwd->pw_name = NULL;
return code;
}

View File

@ -27,10 +27,10 @@ test_get_user_database_entry (void)
const gchar *r = NULL;
r = g_get_user_name ();
g_assert_nonnull (r);
g_assert_cmpstr (r, ==, "somebody");
r = g_get_real_name ();
g_assert_nonnull (r);
g_assert_cmpstr (r, ==, "Unknown");
}
int

View File

@ -356,12 +356,21 @@ subdir('path-test-subdir')
foreach test_name, extra_args : glib_tests
source = extra_args.get('source', test_name + '.c')
install = installed_tests_enabled and extra_args.get('install', true)
installed_tests_env = extra_args.get('installed_tests_env', {})
if install
test_conf = configuration_data()
test_conf.set('installed_tests_dir', installed_tests_execdir)
test_conf.set('program', test_name)
test_conf.set('env', '')
test_env_override = ''
if installed_tests_env != {}
envs = []
foreach var, value : installed_tests_env
envs += '@0@=@1@'.format(var, value)
endforeach
test_env_override = '@0@ @1@ '.format(env_program.full_path(), ' '.join(envs))
endif
test_conf.set('env', test_env_override)
configure_file(
input: installed_tests_template_tap,
output: test_name + '.test',
@ -394,11 +403,16 @@ foreach test_name, extra_args : glib_tests
depends += test_extra_programs_targets[program]
endforeach
local_test_env = test_env
foreach var, value : extra_args.get('env', {})
local_test_env.append(var, value)
endforeach
test(test_name, exe,
args: extra_args.get('args', []),
protocol : extra_args.get('protocol', test_protocol),
depends : depends,
env : test_env,
env : local_test_env,
timeout : timeout,
suite : suite,
should_fail : extra_args.get('should_fail', false),