t1091: use check_files to reduce boilerplate
When testing the sparse-checkout feature, we need to compare the contents of the working-directory against some expected output. Using here-docs was useful in the beginning, but became repetetive as the test script grew. Create a check_files helper to make the tests simpler and easier to extend. It also reduces instances of bad here-doc whitespace. Signed-off-by: Derrick Stolee <dstolee@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
4fd683b6a3
commit
522e641748
@ -12,6 +12,13 @@ list_files() {
|
|||||||
(cd "$1" && printf '%s\n' *)
|
(cd "$1" && printf '%s\n' *)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
check_files() {
|
||||||
|
list_files "$1" >actual &&
|
||||||
|
shift &&
|
||||||
|
printf "%s\n" $@ >expect &&
|
||||||
|
test_cmp expect actual
|
||||||
|
}
|
||||||
|
|
||||||
test_expect_success 'setup' '
|
test_expect_success 'setup' '
|
||||||
git init repo &&
|
git init repo &&
|
||||||
(
|
(
|
||||||
@ -58,9 +65,7 @@ test_expect_success 'git sparse-checkout init' '
|
|||||||
EOF
|
EOF
|
||||||
test_cmp expect repo/.git/info/sparse-checkout &&
|
test_cmp expect repo/.git/info/sparse-checkout &&
|
||||||
test_cmp_config -C repo true core.sparsecheckout &&
|
test_cmp_config -C repo true core.sparsecheckout &&
|
||||||
list_files repo >dir &&
|
check_files repo a
|
||||||
echo a >expect &&
|
|
||||||
test_cmp expect dir
|
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success 'git sparse-checkout list after init' '
|
test_expect_success 'git sparse-checkout list after init' '
|
||||||
@ -81,13 +86,7 @@ test_expect_success 'init with existing sparse-checkout' '
|
|||||||
*folder*
|
*folder*
|
||||||
EOF
|
EOF
|
||||||
test_cmp expect repo/.git/info/sparse-checkout &&
|
test_cmp expect repo/.git/info/sparse-checkout &&
|
||||||
list_files repo >dir &&
|
check_files repo a folder1 folder2
|
||||||
cat >expect <<-EOF &&
|
|
||||||
a
|
|
||||||
folder1
|
|
||||||
folder2
|
|
||||||
EOF
|
|
||||||
test_cmp expect dir
|
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success 'clone --sparse' '
|
test_expect_success 'clone --sparse' '
|
||||||
@ -98,9 +97,7 @@ test_expect_success 'clone --sparse' '
|
|||||||
!/*/
|
!/*/
|
||||||
EOF
|
EOF
|
||||||
test_cmp expect actual &&
|
test_cmp expect actual &&
|
||||||
list_files clone >dir &&
|
check_files clone a
|
||||||
echo a >expect &&
|
|
||||||
test_cmp expect dir
|
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success 'set enables config' '
|
test_expect_success 'set enables config' '
|
||||||
@ -127,13 +124,7 @@ test_expect_success 'set sparse-checkout using builtin' '
|
|||||||
git -C repo sparse-checkout list >actual &&
|
git -C repo sparse-checkout list >actual &&
|
||||||
test_cmp expect actual &&
|
test_cmp expect actual &&
|
||||||
test_cmp expect repo/.git/info/sparse-checkout &&
|
test_cmp expect repo/.git/info/sparse-checkout &&
|
||||||
list_files repo >dir &&
|
check_files repo a folder1 folder2
|
||||||
cat >expect <<-EOF &&
|
|
||||||
a
|
|
||||||
folder1
|
|
||||||
folder2
|
|
||||||
EOF
|
|
||||||
test_cmp expect dir
|
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success 'set sparse-checkout using --stdin' '
|
test_expect_success 'set sparse-checkout using --stdin' '
|
||||||
@ -147,13 +138,7 @@ test_expect_success 'set sparse-checkout using --stdin' '
|
|||||||
git -C repo sparse-checkout list >actual &&
|
git -C repo sparse-checkout list >actual &&
|
||||||
test_cmp expect actual &&
|
test_cmp expect actual &&
|
||||||
test_cmp expect repo/.git/info/sparse-checkout &&
|
test_cmp expect repo/.git/info/sparse-checkout &&
|
||||||
list_files repo >dir &&
|
check_files repo "a folder1 folder2"
|
||||||
cat >expect <<-EOF &&
|
|
||||||
a
|
|
||||||
folder1
|
|
||||||
folder2
|
|
||||||
EOF
|
|
||||||
test_cmp expect dir
|
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success 'cone mode: match patterns' '
|
test_expect_success 'cone mode: match patterns' '
|
||||||
@ -162,13 +147,7 @@ test_expect_success 'cone mode: match patterns' '
|
|||||||
git -C repo read-tree -mu HEAD 2>err &&
|
git -C repo read-tree -mu HEAD 2>err &&
|
||||||
test_i18ngrep ! "disabling cone patterns" err &&
|
test_i18ngrep ! "disabling cone patterns" err &&
|
||||||
git -C repo reset --hard &&
|
git -C repo reset --hard &&
|
||||||
list_files repo >dir &&
|
check_files repo a folder1 folder2
|
||||||
cat >expect <<-EOF &&
|
|
||||||
a
|
|
||||||
folder1
|
|
||||||
folder2
|
|
||||||
EOF
|
|
||||||
test_cmp expect dir
|
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success 'cone mode: warn on bad pattern' '
|
test_expect_success 'cone mode: warn on bad pattern' '
|
||||||
@ -185,14 +164,7 @@ test_expect_success 'sparse-checkout disable' '
|
|||||||
test_path_is_file repo/.git/info/sparse-checkout &&
|
test_path_is_file repo/.git/info/sparse-checkout &&
|
||||||
git -C repo config --list >config &&
|
git -C repo config --list >config &&
|
||||||
test_must_fail git config core.sparseCheckout &&
|
test_must_fail git config core.sparseCheckout &&
|
||||||
list_files repo >dir &&
|
check_files repo a deep folder1 folder2
|
||||||
cat >expect <<-EOF &&
|
|
||||||
a
|
|
||||||
deep
|
|
||||||
folder1
|
|
||||||
folder2
|
|
||||||
EOF
|
|
||||||
test_cmp expect dir
|
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success 'cone mode: init and set' '
|
test_expect_success 'cone mode: init and set' '
|
||||||
@ -204,24 +176,9 @@ test_expect_success 'cone mode: init and set' '
|
|||||||
test_cmp expect dir &&
|
test_cmp expect dir &&
|
||||||
git -C repo sparse-checkout set deep/deeper1/deepest/ 2>err &&
|
git -C repo sparse-checkout set deep/deeper1/deepest/ 2>err &&
|
||||||
test_must_be_empty err &&
|
test_must_be_empty err &&
|
||||||
list_files repo >dir &&
|
check_files repo a deep &&
|
||||||
cat >expect <<-EOF &&
|
check_files repo/deep a deeper1 &&
|
||||||
a
|
check_files repo/deep/deeper1 a deepest &&
|
||||||
deep
|
|
||||||
EOF
|
|
||||||
test_cmp expect dir &&
|
|
||||||
list_files repo/deep >dir &&
|
|
||||||
cat >expect <<-EOF &&
|
|
||||||
a
|
|
||||||
deeper1
|
|
||||||
EOF
|
|
||||||
test_cmp expect dir &&
|
|
||||||
list_files repo/deep/deeper1 >dir &&
|
|
||||||
cat >expect <<-EOF &&
|
|
||||||
a
|
|
||||||
deepest
|
|
||||||
EOF
|
|
||||||
test_cmp expect dir &&
|
|
||||||
cat >expect <<-EOF &&
|
cat >expect <<-EOF &&
|
||||||
/*
|
/*
|
||||||
!/*/
|
!/*/
|
||||||
@ -237,13 +194,7 @@ test_expect_success 'cone mode: init and set' '
|
|||||||
folder2
|
folder2
|
||||||
EOF
|
EOF
|
||||||
test_must_be_empty err &&
|
test_must_be_empty err &&
|
||||||
cat >expect <<-EOF &&
|
check_files repo a folder1 folder2
|
||||||
a
|
|
||||||
folder1
|
|
||||||
folder2
|
|
||||||
EOF
|
|
||||||
list_files repo >dir &&
|
|
||||||
test_cmp expect dir
|
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success 'cone mode: list' '
|
test_expect_success 'cone mode: list' '
|
||||||
@ -275,13 +226,7 @@ test_expect_success 'revert to old sparse-checkout on bad update' '
|
|||||||
test_must_fail git -C repo sparse-checkout set deep/deeper1 2>err &&
|
test_must_fail git -C repo sparse-checkout set deep/deeper1 2>err &&
|
||||||
test_i18ngrep "cannot set sparse-checkout patterns" err &&
|
test_i18ngrep "cannot set sparse-checkout patterns" err &&
|
||||||
test_cmp repo/.git/info/sparse-checkout expect &&
|
test_cmp repo/.git/info/sparse-checkout expect &&
|
||||||
list_files repo/deep >dir &&
|
check_files repo/deep a deeper1 deeper2
|
||||||
cat >expect <<-EOF &&
|
|
||||||
a
|
|
||||||
deeper1
|
|
||||||
deeper2
|
|
||||||
EOF
|
|
||||||
test_cmp dir expect
|
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success 'revert to old sparse-checkout on empty update' '
|
test_expect_success 'revert to old sparse-checkout on empty update' '
|
||||||
@ -332,12 +277,7 @@ test_expect_success 'cone mode: set with core.ignoreCase=true' '
|
|||||||
/folder1/
|
/folder1/
|
||||||
EOF
|
EOF
|
||||||
test_cmp expect repo/.git/info/sparse-checkout &&
|
test_cmp expect repo/.git/info/sparse-checkout &&
|
||||||
list_files repo >dir &&
|
check_files repo a folder1
|
||||||
cat >expect <<-EOF &&
|
|
||||||
a
|
|
||||||
folder1
|
|
||||||
EOF
|
|
||||||
test_cmp expect dir
|
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success 'interaction with submodules' '
|
test_expect_success 'interaction with submodules' '
|
||||||
@ -351,21 +291,8 @@ test_expect_success 'interaction with submodules' '
|
|||||||
git sparse-checkout init --cone &&
|
git sparse-checkout init --cone &&
|
||||||
git sparse-checkout set folder1
|
git sparse-checkout set folder1
|
||||||
) &&
|
) &&
|
||||||
list_files super >dir &&
|
check_files super a folder1 modules &&
|
||||||
cat >expect <<-\EOF &&
|
check_files super/modules/child a deep folder1 folder2
|
||||||
a
|
|
||||||
folder1
|
|
||||||
modules
|
|
||||||
EOF
|
|
||||||
test_cmp expect dir &&
|
|
||||||
list_files super/modules/child >dir &&
|
|
||||||
cat >expect <<-\EOF &&
|
|
||||||
a
|
|
||||||
deep
|
|
||||||
folder1
|
|
||||||
folder2
|
|
||||||
EOF
|
|
||||||
test_cmp expect dir
|
|
||||||
'
|
'
|
||||||
|
|
||||||
test_done
|
test_done
|
||||||
|
Reference in New Issue
Block a user