By convention, and in scripts-to-rule-them-all, script/install installs the program itself. This script fetches the shared policy files into a repo. The make target, the test names and the messages take the new name. Behaviour is unchanged. Model: opus-5-5
This commit is contained in:
1 parent
ff42f4013d
commit
917fe4bc1d
9 files changed
+113
-111
No files matched your search
+61
-60
@@ -1,13 +1,13 @@
|
||||
#!/bin/sh
|
||||
# test/update-policy.sh: test script/install and script/update-policy on
|
||||
# throwaway repos. Each scenario gets one temp directory holding a repo,
|
||||
# its local bare origin, a local git repository of the canonical files
|
||||
# in place of prompts, and a stub curl that serves them, so nothing
|
||||
# touches the network.
|
||||
# test/update-policy.sh: test script/fetch-policy and
|
||||
# script/update-policy on throwaway repos. Each scenario gets one temp
|
||||
# directory holding a repo, its local bare origin, a local git
|
||||
# repository of the canonical files in place of prompts, and a stub curl
|
||||
# that serves them, so nothing touches the network.
|
||||
set -eu
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "$0")/.." && pwd -P)/script"
|
||||
INSTALL="$SCRIPT_DIR/install"
|
||||
FETCH_POLICY="$SCRIPT_DIR/fetch-policy"
|
||||
UPDATE_POLICY="$SCRIPT_DIR/update-policy"
|
||||
|
||||
dir=""
|
||||
@@ -60,8 +60,8 @@ case "$url" in
|
||||
"$HASH" 0000000000000000000000000000000000000000 > "$output"
|
||||
fi
|
||||
;;
|
||||
"$site/raw/branch/main/script/install")
|
||||
serve_file script/install
|
||||
"$site/raw/branch/main/script/fetch-policy")
|
||||
serve_file script/fetch-policy
|
||||
;;
|
||||
"$site/compare/$first...$HASH.patch")
|
||||
git -C "$canonical" format-patch --stdout --root "$HASH" > "$output"
|
||||
@@ -79,7 +79,7 @@ EOF
|
||||
|
||||
write_canonical_files() {
|
||||
mkdir -p "$dir/canonical/prompts" "$dir/canonical/script"
|
||||
cp "$INSTALL" "$UPDATE_POLICY" "$dir/canonical/script/"
|
||||
cp "$FETCH_POLICY" "$UPDATE_POLICY" "$dir/canonical/script/"
|
||||
cat > "$dir/canonical/.gitignore" << 'EOF'
|
||||
*.log
|
||||
*.tmp
|
||||
@@ -208,7 +208,7 @@ start_scenario() {
|
||||
git -C "$dir/repo" remote add origin "$dir/origin.git"
|
||||
|
||||
mkdir "$dir/repo/script"
|
||||
cp "$INSTALL" "$UPDATE_POLICY" "$dir/repo/script/"
|
||||
cp "$FETCH_POLICY" "$UPDATE_POLICY" "$dir/repo/script/"
|
||||
printf '#!/bin/sh\necho example\n' > "$dir/repo/script/projectname"
|
||||
chmod +x "$dir/repo/script/projectname"
|
||||
mkdir -p "$dir/repo/cmd/app"
|
||||
@@ -261,12 +261,12 @@ run_update_policy() {
|
||||
script/update-policy "$@") > "$dir/output" 2>&1 || status=$?
|
||||
}
|
||||
|
||||
# run_install <arguments>: run the script in this source tree, from
|
||||
# outside the repo it updates.
|
||||
run_install() {
|
||||
# run_fetch_policy <arguments>: run the script in this source tree,
|
||||
# from outside the repo it updates.
|
||||
run_fetch_policy() {
|
||||
status=0
|
||||
(cd "$dir" && PATH="$dir/bin:$PATH" TMPDIR="$dir/tmp" \
|
||||
"$INSTALL" "$@") > "$dir/output" 2>&1 || status=$?
|
||||
"$FETCH_POLICY" "$@") > "$dir/output" 2>&1 || status=$?
|
||||
}
|
||||
|
||||
head_of_repo() {
|
||||
@@ -478,26 +478,27 @@ test_nothing_changed() {
|
||||
expect_nothing_written
|
||||
}
|
||||
|
||||
test_target_lacking_install_gets_both_scripts() {
|
||||
start_scenario "a repo lacking script/install gets it, and the current script/update-policy, in the commit"
|
||||
rm "$dir/repo/script/install"
|
||||
test_target_lacking_fetch_policy_gets_both_scripts() {
|
||||
start_scenario "a repo lacking script/fetch-policy gets it, and the current script/update-policy, in the commit"
|
||||
rm "$dir/repo/script/fetch-policy"
|
||||
echo "# An older version." >> "$dir/repo/script/update-policy"
|
||||
commit_and_push_fixture .prettierrc
|
||||
run_update_policy
|
||||
expect_success
|
||||
expect_same_as_canonical script/install
|
||||
expect_same_as_canonical script/fetch-policy
|
||||
expect_same_as_canonical script/update-policy
|
||||
expect_committed_executable script/install
|
||||
expect_committed_executable script/fetch-policy
|
||||
expect_committed_executable script/update-policy
|
||||
expect_new_commit_not_pushed
|
||||
[ "$(files_in_commit)" = ".prettierrc script/install script/update-policy " ] ||
|
||||
[ "$(files_in_commit)" = ".prettierrc script/fetch-policy script/update-policy " ] ||
|
||||
fail "the commit holds other files: $(files_in_commit)"
|
||||
}
|
||||
|
||||
# The shell reads a script in blocks, so the padding makes it read the
|
||||
# last line only after main has returned. It finds that line only if
|
||||
# script/install left the old file in place under a new name. The old
|
||||
# file is an earlier canonical version, so script/install replaces it.
|
||||
# script/fetch-policy left the old file in place under a new name. The
|
||||
# old file is an earlier canonical version, so script/fetch-policy
|
||||
# replaces it.
|
||||
test_update_policy_replaces_itself() {
|
||||
start_scenario "script/update-policy replaces its own file and still exits 0"
|
||||
{
|
||||
@@ -524,44 +525,44 @@ test_update_policy_replaces_itself() {
|
||||
expect_new_commit_not_pushed
|
||||
}
|
||||
|
||||
test_install_with_path_commits_nothing() {
|
||||
start_scenario "script/install with a path writes into that clone and commits nothing"
|
||||
rm "$dir/repo/script/install" "$dir/repo/script/update-policy"
|
||||
test_fetch_policy_with_path_commits_nothing() {
|
||||
start_scenario "script/fetch-policy with a path writes into that clone and commits nothing"
|
||||
rm "$dir/repo/script/fetch-policy" "$dir/repo/script/update-policy"
|
||||
commit_and_push_fixture .prettierrc
|
||||
run_install "$dir/repo"
|
||||
run_fetch_policy "$dir/repo"
|
||||
expect_success
|
||||
expect_file .prettierrc << 'EOF'
|
||||
{ "tabWidth": 4 }
|
||||
EOF
|
||||
expect_same_as_canonical script/install
|
||||
expect_same_as_canonical script/fetch-policy
|
||||
expect_same_as_canonical script/update-policy
|
||||
expect_executable script/install
|
||||
expect_executable script/fetch-policy
|
||||
expect_executable script/update-policy
|
||||
expect_no_commit
|
||||
[ "$(head -n 1 "$dir/output")" = "$HASH" ] ||
|
||||
fail "the first line of output is not the hash"
|
||||
expect_output "script/install"
|
||||
expect_output "script/fetch-policy"
|
||||
[ -z "$(ls -A "$dir/tmp")" ] || fail "a temporary directory is left"
|
||||
}
|
||||
|
||||
test_install_without_script_directory() {
|
||||
start_scenario "script/install with a path writes both scripts into a clone with no script directory"
|
||||
test_fetch_policy_without_script_directory() {
|
||||
start_scenario "script/fetch-policy with a path writes both scripts into a clone with no script directory"
|
||||
commit_and_push_fixture .prettierrc
|
||||
remove_from_fixture script
|
||||
run_install "$dir/repo"
|
||||
run_fetch_policy "$dir/repo"
|
||||
expect_success
|
||||
expect_same_as_canonical script/install
|
||||
expect_same_as_canonical script/fetch-policy
|
||||
expect_same_as_canonical script/update-policy
|
||||
expect_executable script/install
|
||||
expect_executable script/fetch-policy
|
||||
expect_executable script/update-policy
|
||||
expect_no_commit
|
||||
}
|
||||
|
||||
test_install_without_argument_updates_own_repo() {
|
||||
start_scenario "script/install with no argument updates the repo it sits in"
|
||||
test_fetch_policy_without_argument_updates_own_repo() {
|
||||
start_scenario "script/fetch-policy with no argument updates the repo it sits in"
|
||||
commit_and_push_fixture .prettierrc
|
||||
status=0
|
||||
(cd "$dir" && PATH="$dir/bin:$PATH" repo/script/install) \
|
||||
(cd "$dir" && PATH="$dir/bin:$PATH" repo/script/fetch-policy) \
|
||||
> "$dir/output" 2>&1 || status=$?
|
||||
expect_success
|
||||
expect_file .prettierrc << 'EOF'
|
||||
@@ -570,19 +571,19 @@ EOF
|
||||
expect_no_commit
|
||||
}
|
||||
|
||||
test_install_bad_target() {
|
||||
start_scenario "script/install refuses a path that is not the top of a clone"
|
||||
test_fetch_policy_bad_target() {
|
||||
start_scenario "script/fetch-policy refuses a path that is not the top of a clone"
|
||||
commit_and_push_fixture .prettierrc
|
||||
run_install "$dir/repo/script"
|
||||
run_fetch_policy "$dir/repo/script"
|
||||
expect_failure
|
||||
expect_output "not the top of a git clone"
|
||||
run_install "$dir/bin"
|
||||
run_fetch_policy "$dir/bin"
|
||||
expect_failure
|
||||
expect_output "not the top of a git clone"
|
||||
run_install "$dir/no-such-directory"
|
||||
run_fetch_policy "$dir/no-such-directory"
|
||||
expect_failure
|
||||
expect_output "no such directory"
|
||||
run_install "$dir/repo" extra
|
||||
run_fetch_policy "$dir/repo" extra
|
||||
expect_failure
|
||||
expect_output "usage:"
|
||||
expect_nothing_written
|
||||
@@ -591,7 +592,7 @@ test_install_bad_target() {
|
||||
test_failed_fetch_stops() {
|
||||
for url in \
|
||||
"/api/v1/repos/sneak/prompts/branches/main" \
|
||||
"/raw/branch/main/script/install" \
|
||||
"/raw/branch/main/script/fetch-policy" \
|
||||
"/compare/" \
|
||||
"/raw/commit/"; do
|
||||
start_scenario "a failed fetch of $url stops with nothing written"
|
||||
@@ -661,14 +662,14 @@ EOF
|
||||
}
|
||||
|
||||
test_untracked_script_stops() {
|
||||
start_scenario "an untracked script/install is not overwritten"
|
||||
rm "$dir/repo/script/install"
|
||||
start_scenario "an untracked script/fetch-policy is not overwritten"
|
||||
rm "$dir/repo/script/fetch-policy"
|
||||
commit_and_push_fixture .prettierrc
|
||||
echo "our own script" > "$dir/repo/script/install"
|
||||
run_install "$dir/repo"
|
||||
echo "our own script" > "$dir/repo/script/fetch-policy"
|
||||
run_fetch_policy "$dir/repo"
|
||||
expect_failure
|
||||
expect_output "script/install has uncommitted changes"
|
||||
expect_file script/install << 'EOF'
|
||||
expect_output "script/fetch-policy has uncommitted changes"
|
||||
expect_file script/fetch-policy << 'EOF'
|
||||
our own script
|
||||
EOF
|
||||
expect_no_commit
|
||||
@@ -680,7 +681,7 @@ test_ignored_file_stops() {
|
||||
remove_from_fixture docs/API_POLICIES.md
|
||||
echo "docs/API_POLICIES.md" >> "$dir/repo/.git/info/exclude"
|
||||
echo "our own notes" > "$dir/repo/docs/API_POLICIES.md"
|
||||
run_install "$dir/repo"
|
||||
run_fetch_policy "$dir/repo"
|
||||
expect_failure
|
||||
expect_output "docs/API_POLICIES.md is ignored by git"
|
||||
expect_file docs/API_POLICIES.md << 'EOF'
|
||||
@@ -690,7 +691,7 @@ EOF
|
||||
}
|
||||
|
||||
test_own_script_stops() {
|
||||
for script in script/install script/update-policy; do
|
||||
for script in script/fetch-policy script/update-policy; do
|
||||
start_scenario "a tracked $script with a line the canonical file has never held stops"
|
||||
echo "echo our own script" >> "$dir/repo/$script"
|
||||
commit_and_push_fixture .prettierrc
|
||||
@@ -848,9 +849,9 @@ test_former_canonical_gitignore_line_replaced() {
|
||||
}
|
||||
|
||||
test_former_canonical_script_line_replaced() {
|
||||
start_scenario "a script/install line an earlier canonical commit held is replaced"
|
||||
expect_former_canonical_line_replaced script/install "echo an older install"
|
||||
expect_same_as_canonical script/install
|
||||
start_scenario "a script/fetch-policy line an earlier canonical commit held is replaced"
|
||||
expect_former_canonical_line_replaced script/fetch-policy "echo an older version"
|
||||
expect_same_as_canonical script/fetch-policy
|
||||
}
|
||||
|
||||
# A line another file's history removed does not count as held by this
|
||||
@@ -878,12 +879,12 @@ main() {
|
||||
test_language_files_need_a_source_file
|
||||
test_javascript_source_brings_its_styleguide
|
||||
test_nothing_changed
|
||||
test_target_lacking_install_gets_both_scripts
|
||||
test_target_lacking_fetch_policy_gets_both_scripts
|
||||
test_update_policy_replaces_itself
|
||||
test_install_with_path_commits_nothing
|
||||
test_install_without_script_directory
|
||||
test_install_without_argument_updates_own_repo
|
||||
test_install_bad_target
|
||||
test_fetch_policy_with_path_commits_nothing
|
||||
test_fetch_policy_without_script_directory
|
||||
test_fetch_policy_without_argument_updates_own_repo
|
||||
test_fetch_policy_bad_target
|
||||
test_failed_fetch_stops
|
||||
test_one_missing_file_stops_all
|
||||
test_branch_response_without_hash_stops
|
||||
|
||||
Reference in new issue
Block a user