From 3f6aa021a7bff4b68b07244e65dfe7aebcb73873 Mon Sep 17 00:00:00 2001 From: Franciszek Stachura Date: Tue, 9 Jul 2024 13:12:16 +0200 Subject: [PATCH] Improve tests * Run pytest only for t, do not run tests for other libraries * Add email and name git options to test repo init * Change test repo permissions to avoid "dubious ownership" error --- t/200-api.t | 2 +- t/TestEnvironment.pm | 18 +++++++++++++----- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/t/200-api.t b/t/200-api.t index 289e226..0c01f2c 100644 --- a/t/200-api.t +++ b/t/200-api.t @@ -31,6 +31,6 @@ my $tenv = TestEnvironment->new; $tenv->build_repo(sibling_abs_path('tree'))->build_db->update_env; # Test the api using pytest. Prints the test results -run_produces_ok('api pytest suite', ["pytest", "-v"], [], MUST_SUCCEED, 1); +run_produces_ok('api pytest suite', ["pytest", "-v", "t"], [], MUST_SUCCEED, 1); done_testing; diff --git a/t/TestEnvironment.pm b/t/TestEnvironment.pm index 18a54da..20d204d 100644 --- a/t/TestEnvironment.pm +++ b/t/TestEnvironment.pm @@ -135,19 +135,27 @@ sub build_repo { die "Need a source dir" unless $tree_src_dir; die "No repo dir" unless $self->lxr_repo_dir; + my $tempdir_path = $self->lxr_repo_dir; - my @gitdir = ('-C', $tempdir_path); + my @gitopts = ( + '-C', $tempdir_path, + '-c', 'init.defaultBranch=main', + '-c', 'user.name=test@example.com', + '-c', 'user.email=test'); diag "Using temporary directory $tempdir_path"; - run_program('git', 'init', $tempdir_path) or die("git init failed"); + run_program('git', @gitopts, 'init', $tempdir_path) or die("git init failed"); run_program('sh', '-c', "tar cf - -C \"$tree_src_dir\" . | tar xf - -C \"$tempdir_path\"") or die("Could not copy files into $tempdir_path"); - run_program('git', @gitdir, 'add', '.') or die("git add failed"); - run_program('git', @gitdir, 'commit', '-am', 'Initial commit') + run_program('sh', '-c', "chown -R `whoami`:`id -ng` \"$tempdir_path\""); + run_program('sh', '-c', "chmod -R 775 \"$tempdir_path\""); + + run_program('git', @gitopts, 'add', '.') or die("git add failed"); + run_program('git', @gitopts, 'commit', '-am', 'Initial commit') or die("git commit failed"); - run_program('git', @gitdir, 'tag', 'v5.4') or die("git tag failed"); + run_program('git', @gitopts, 'tag', 'v5.4') or die("git tag failed"); return $self; } #build_repo()