Skip to content

Commit d7d8838

Browse files
refactor: ♻️ move test to own file (#185)
# Description This PR moves the copier test to its own file. This PR needs a quick review. ## Checklist - [x] Formatted Markdown - [x] Ran `just run-all` --------- Co-authored-by: Luke W. Johnston <lwjohnst86@users.noreply.github.com>
1 parent 86b63ae commit d7d8838

File tree

2 files changed

+83
-57
lines changed

2 files changed

+83
-57
lines changed

justfile

Lines changed: 9 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
just --list --unsorted
33

44
@_checks: check-spelling check-commits
5-
@_tests: test
5+
@_tests: (test "true") (test "false")
66
@_builds: build-contributors build-website build-readme
77

88
# Run all build-related recipes in the justfile
@@ -44,62 +44,14 @@ check-commits:
4444
check-spelling:
4545
uvx typos
4646

47-
# Test and check that a data package can be created from the template
48-
test:
49-
#!/usr/bin/env bash
50-
test_name="test-data-package"
51-
test_dir="$(pwd)/_temp/$test_name"
52-
template_dir="$(pwd)"
53-
commit=$(git rev-parse HEAD)
54-
rm -rf $test_dir
55-
# vcs-ref means the current commit/head, not a tag.
56-
uvx copier copy $template_dir $test_dir \
57-
--vcs-ref=$commit \
58-
--defaults \
59-
--trust \
60-
--data github_repo=$test_name \
61-
--data github_user="first-last" \
62-
--data author_given_name="First" \
63-
--data author_family_name="Last" \
64-
--data author_email="first.last@example.com" \
65-
--data review_team="@first-last/developers" \
66-
--data cc0_license="true" \
67-
--data github_board_number=22
68-
# Run checks in the generated test data package
69-
cd $test_dir
70-
git add .
71-
git commit -m "test: initial copy"
72-
just check-python check-spelling
73-
# TODO: Find some way to test the `update` command
74-
# Check that recopy works
75-
echo "Testing recopy command -----------"
76-
rm .cz.toml
77-
git add .
78-
git commit -m "test: preparing to recopy from the template"
79-
uvx copier recopy \
80-
--vcs-ref=$commit \
81-
--defaults \
82-
--overwrite \
83-
--trust
84-
# Check that copying onto an existing data package works
85-
echo "Using the template in an existing package command -----------"
86-
rm .cz.toml .copier-answers.yml LICENSE-MIT.md LICENSE.md
87-
git add .
88-
git commit -m "test: preparing to copy onto an existing package"
89-
uvx copier copy \
90-
$template_dir $test_dir \
91-
--vcs-ref=$commit \
92-
--defaults \
93-
--trust \
94-
--overwrite \
95-
--data github_repo=$test_name \
96-
--data github_user="first-last" \
97-
--data author_given_name="First" \
98-
--data author_family_name="Last" \
99-
--data author_email="first.last@example.com" \
100-
--data review_team="@first-last/developers" \
101-
--data cc0_license="false" \
102-
--data github_board_number=22
47+
# Test that a data package can be created from the template
48+
test cc0_license="true":
49+
sh ./test-template.sh {{ cc0_license }}
50+
51+
# Test template with the manual questionnaire answers
52+
test-manual:
53+
mkdir -p _temp/manual
54+
uvx copier copy --trust -r HEAD . _temp/manual/test-template
10355

10456
# Clean up any leftover and temporary build files
10557
cleanup:

test-template.sh

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#!/usr/bin/env bash
2+
3+
# Needs one argument:
4+
#
5+
# 1. cc0_license: true or false
6+
7+
# Argument naming -----
8+
cc0_license="${1}"
9+
10+
if [ -z "$cc0_license" ]; then
11+
echo "Usage: sh $0 <cc0_license>"
12+
echo "Example: sh $0 true"
13+
exit 1
14+
fi
15+
16+
# Set up variables and functions for the test -----
17+
test_name="test-package"
18+
test_dir="$(pwd)/_temp/$cc0_license/$test_name"
19+
template_dir="$(pwd)"
20+
21+
# Needs two arguments:
22+
#
23+
# 1. Template directory
24+
# 2. Destination directory
25+
copy () {
26+
# `-r HEAD` means to copy from the current HEAD, including uncommitted changes
27+
uvx copier copy $1 $2 \
28+
-r HEAD \
29+
--defaults \
30+
--data github_user="first-last" \
31+
--data author_given_name="First" \
32+
--data author_family_name="Last" \
33+
--data author_email="first.last@example.com" \
34+
--data review_team="@first-last/developers" \
35+
--data cc0_license=$cc0_license \
36+
--data github_board_number=22 \
37+
--overwrite \
38+
--skip-tasks \
39+
--trust
40+
}
41+
42+
# Pre-test setup -----
43+
# Remove the leftover directory from previous runs
44+
rm -rf $test_dir
45+
mkdir -p $test_dir
46+
47+
# Check initial creation -----
48+
# TODO: Find some way to test the `update` command
49+
# Any step that fails will exit the script with an error and not continue
50+
echo "Testing copy for new projects when: 'cc0_license'='$cc0_license' -----------"
51+
(
52+
cd $test_dir &&
53+
copy $template_dir $test_dir &&
54+
git init -b main &&
55+
git add . &&
56+
git commit --quiet -m "test: initial copy" &&
57+
# Check that recopy works -----
58+
echo "Testing recopy when: 'cc0_license'='$cc0_license' -----------" &&
59+
rm .cz.toml &&
60+
git add . &&
61+
git commit --quiet -m "test: preparing to recopy from the template" &&
62+
uvx copier recopy \
63+
-r HEAD \
64+
--defaults \
65+
--overwrite \
66+
--skip-tasks \
67+
--trust &&
68+
# Check that copying onto an existing package works -----
69+
echo "Testing copy in existing projects when: 'cc0_license'='$cc0_license' -----------" &&
70+
rm .cz.toml .copier-answers.yml &&
71+
git add . &&
72+
git commit --quiet -m "test: preparing to copy onto an existing package" &&
73+
copy $template_dir $test_dir
74+
)

0 commit comments

Comments
 (0)