11#! /usr/bin/env bash
2+ # shellcheck disable=SC2317
3+ # shellcheck disable=SC2329
24
35
46function usage() {
@@ -7,8 +9,9 @@ Usage: $(basename "$0") [options]
79
810Options:
911 -h, --help Show this help message and exit
10- --debug Enable debug mode
12+ -d, - -debug Enable debug mode
1113 --verbose Enable verbose output
14+ -t|--testcase <#> Specify a single test case to run (e.g., 1, 2, 3.1, etc.)
1215
1316Description:
1417 This script runs integration tests for git-artifact.
@@ -89,7 +92,6 @@ remote_tester_repo=.remote
8992clone_tester_repo=.clone
9093global_exit_code=0
9194
92- # shellcheck disable=SC2317
9395function testcase_header() {
9496 [[ ! -d " ${test} " ]] && {
9597 echo " Creating test directory: ${test} and empty git-reference.log"
@@ -103,13 +105,11 @@ function testcase_header() {
103105 echo " --------------------------------------------------------------------------------"
104106}
105107
106- # shellcheck disable=SC2317
107108function generate_git_test_log() {
108109 rm -rf .git/refs/remotes/origin/HEAD
109110 git log --graph --all --oneline --format=" %d %s" >> " ${root_folder} /${test} /git-test.log"
110111}
111112
112- # shellcheck disable=SC2317
113113function eval_testcase() {
114114 # expect to be in repo to test against
115115
@@ -141,7 +141,6 @@ function eval_testcase() {
141141 echo
142142}
143143
144- # shellcheck disable=SC2317
145144function generate_base_repo() {
146145 rm -rf " ${local_tester_repo:? } /" " ${remote_tester_repo:? } /" " ${clone_tester_repo:? } /"
147146 git init --bare -b " ${default_branch:- main} " $remote_tester_repo || {
@@ -167,7 +166,6 @@ echo " - <test>/ok.log(all good)"
167166echo " - <test>/nok.log(failed tests)"
168167echo
169168
170- # shellcheck disable=SC2317
171169function 1 {
172170 export test=" 1"
173171 testcase_synopsis=" base-repo default-branch; clone"
@@ -180,7 +178,6 @@ function 1 {
180178 eval_testcase
181179}
182180
183- # shellcheck disable=SC2317
184181function 1.1 {
185182 export test=" 1.1"
186183 testcase_synopsis=" base-repo master-branch; clone"
@@ -195,7 +192,6 @@ function 1.1 {
195192 eval_testcase
196193}
197194
198- # shellcheck disable=SC2317
199195function 2 {
200196 test=" ${FUNCNAME[0]} "
201197 testcase_synopsis=" base-repo ; clone; fetch-co : the repo has two tags and the latest is checked out"
@@ -211,7 +207,6 @@ function 2 {
211207 eval_testcase
212208}
213209
214- # shellcheck disable=SC2317
215210function 3 {
216211 test=" ${FUNCNAME[0]} "
217212 testcase_synopsis=" base-repo ; clone - gives a repo without any artifacts"
@@ -225,7 +220,6 @@ function 3 {
225220 eval_testcase
226221}
227222
228- # shellcheck disable=SC2317
229223function 4 {
230224 export test=" 4"
231225 testcase_synopsis=" base-repo ; clone; add-n-push with branch"
@@ -243,7 +237,6 @@ function 4 {
243237 eval_testcase
244238}
245239
246- # shellcheck disable=SC2317
247240function 5 {
248241 test=" ${FUNCNAME[0]} "
249242 testcase_synopsis=" base-repo ; clone; fetch-co-latest pattern"
@@ -279,7 +272,6 @@ function 5 {
279272 eval_testcase
280273}
281274
282- # shellcheck disable=SC2317
283275function 5.1 {
284276 test=" ${FUNCNAME[0]} "
285277 testcase_synopsis=" base-repo ; clone; find-latest pattern"
@@ -297,7 +289,6 @@ function 5.1 {
297289}
298290
299291
300- # shellcheck disable=SC2317
301292function 6 {
302293 test=" ${FUNCNAME[0]} "
303294 testcase_synopsis=" base-repo ; clone; fetch-tags"
@@ -315,7 +306,6 @@ function 6 {
315306 eval_testcase
316307}
317308
318- # shellcheck disable=SC2317
319309function 7 {
320310 test=" ${FUNCNAME[0]} "
321311 testcase_synopsis=" base-repo ; clone; list"
@@ -342,7 +332,6 @@ function 7 {
342332 eval_testcase
343333}
344334
345- # shellcheck disable=SC2317
346335function 8 {
347336 test=" ${FUNCNAME[0]} "
348337 testcase_synopsis=" base-repo ; clone; summary"
@@ -377,7 +366,6 @@ function 8 {
377366 eval_testcase
378367}
379368
380- # shellcheck disable=SC2317
381369function 9 {
382370 test=" ${FUNCNAME[0]} "
383371
@@ -400,26 +388,56 @@ function 9 {
400388 sleep 1
401389 done
402390
403- generate_git_test_log
404- git artifact prune --glob ' v*.*' --keep 5 --dryrun >> ${root_folder} /${test} /git-test.log
405- git artifact prune --glob ' v*.*' --keep 5
406- git fetch origin -pP
391+ generate_git_test_log
392+ git artifact prune --glob ' v*.*' --keep 5 --dryrun >> ${root_folder} /${test} /git-test.log
393+ git artifact prune --glob ' v*.*' --keep 5
394+ git fetch origin -pP
407395
408- generate_git_test_log
396+ generate_git_test_log
397+
398+ git artifact list --glob ' v*.*' >> ${root_folder} /${test} /git-test.log
409399
410- git artifact list --glob ' v*.*' >> ${root_folder} /${test} /git-test.log
400+ } > ${root_folder} /${test} /run.log 2>&1 || { pwd && cat ${root_folder} /${test} /run.log; }
401+ eval_testcase
402+ }
403+
404+ function 10 {
405+ test=" ${FUNCNAME[0]} "
411406
407+ testcase_synopsis=" base-repo ; add-as-submodule"
408+ testcase_header
409+ {
410+ cd $test
411+ generate_base_repo
412+
413+ cd $local_tester_repo
414+
415+ git artifact add-as-submodule --url " ../$remote_tester_repo " --path submodule-repo
416+
417+ git status
412418
419+ git commit -m " Added submodule repo"
420+ git push origin HEAD:" ${default_branch:- main} "
421+ git fetch origin -apP
422+
423+ generate_git_test_log
424+ cat .gitmodules >> ${root_folder} /${test} /git-test.log
425+ git status >> ${root_folder} /${test} /git-test.log
426+
413427 } > ${root_folder} /${test} /run.log 2>&1 || { pwd && cat ${root_folder} /${test} /run.log; }
414428 eval_testcase
415429}
416430
431+
417432if [[ ${arg_testcase:- } == " " ]]; then
418433 # Dynamically list and call test functions
419434 mapfile -t test_functions < <( declare -F | awk ' {print $3}' | grep -E ' ^[0-9]+(\.[0-9]+)?$' )
420435
421436 for fn in " ${test_functions[@]} " ; do
422- " $fn "
437+ " $fn " || {
438+ echo " Test case '$fn ' failed. Check the logs in .test/$fn /run.log"
439+ global_exit_code=1
440+ }
423441 done
424442else
425443 # Run a specific test case if provided
430448 exit 1
431449 fi
432450fi
451+
452+
433453echo
434454echo " ########################################"
435455echo " All tests completed. Checking results..."
0 commit comments