11#! /usr/bin/env bash
22
3- set -euo pipefail
4-
5- # Switch the default Xcode to be incompatible, then use DEVELOPER_DIR
6- # attribute on spm_repositories to specify the one that should be used.
7-
8- exit_on_error () {
9- local err_msg=" ${1:- } "
10- [[ -n " ${err_msg} " ]] || err_msg=" Unspecified error occurred."
11- echo >&2 " ${err_msg} "
12- exit 1
13- }
14-
15- normalize_path () {
16- local path=" ${1} "
17- if [[ -d " ${path} " ]]; then
18- local dirname=" $( dirname " ${path} " ) "
19- else
20- local dirname=" $( dirname " ${path} " ) "
21- local basename=" $( basename " ${path} " ) "
22- fi
23- dirname=" $( cd " ${dirname} " > /dev/null && pwd) "
24- if [[ -z " ${basename:- } " ]]; then
25- echo " ${dirname} "
26- fi
27- echo " ${dirname} /${basename} "
28- }
29-
30- starting_dir=" $( pwd) "
31- bazel_cmds=()
3+ # --- begin runfiles.bash initialization v2 ---
4+ # Copy-pasted from the Bazel Bash runfiles library v2.
5+ set -uo pipefail; f=bazel_tools/tools/bash/runfiles/runfiles.bash
6+ source " ${RUNFILES_DIR:-/ dev/ null} /$f " 2> /dev/null || \
7+ source " $( grep -sm1 " ^$f " " ${RUNFILES_MANIFEST_FILE:-/ dev/ null} " | cut -f2- -d' ' ) " 2> /dev/null || \
8+ source " $0 .runfiles/$f " 2> /dev/null || \
9+ source " $( grep -sm1 " ^$f " " $0 .runfiles_manifest" | cut -f2- -d' ' ) " 2> /dev/null || \
10+ source " $( grep -sm1 " ^$f " " $0 .exe.runfiles_manifest" | cut -f2- -d' ' ) " 2> /dev/null || \
11+ { echo>&2 " ERROR: cannot find $f " ; exit 1; }; f=; set -e
12+ # --- end runfiles.bash initialization v2 ---
13+
14+ assertions_sh_location=cgrindel_bazel_shlib/lib/assertions.sh
15+ assertions_sh=" $( rlocation " ${assertions_sh_location} " ) " || \
16+ (echo >&2 " Failed to locate ${assertions_sh_location} " && exit 1)
17+ source " ${assertions_sh} "
18+
19+ create_scratch_dir_sh_location=cgrindel_rules_bazel_integration_test/tools/create_scratch_dir.sh
20+ create_scratch_dir_sh=" $( rlocation " ${create_scratch_dir_sh_location} " ) " || \
21+ (echo >&2 " Failed to locate ${create_scratch_dir_sh_location} " && exit 1)
22+
23+
24+ # MARK - Process Flags
3225
3326# Process args
3427while (( "$# ")) ; do
3528 case " ${1} " in
3629 " --bazel" )
37- bazel_rel_path=" ${2} "
38- shift 2
39- ;;
40- " --bazel_cmd" )
41- bazel_cmds+=(" ${2} " )
30+ bazel=" ${2} "
4231 shift 2
4332 ;;
4433 " --workspace" )
@@ -51,42 +40,30 @@ while (("$#")); do
5140 esac
5241done
5342
54-
55- [[ -n " ${bazel_rel_path:- } " ]] || exit_on_error " Must specify the location of the Bazel binary."
43+ [[ -n " ${bazel:- } " ]] || exit_on_error " Must specify the location of the Bazel binary."
5644[[ -n " ${workspace_path:- } " ]] || exit_on_error " Must specify the location of the workspace file."
5745
58- starting_path=" $( pwd) "
59- starting_path=" ${starting_path%%* ( )} "
60- bazel=" $( normalize_path " ${bazel_rel_path} " ) "
61-
6246workspace_dir=" $( dirname " ${workspace_path} " ) "
63- cd " ${workspace_dir} "
6447
65- # BEGIN Custom test logic
48+ # MARK - Create Scratch Directory
6649
67- modified_file= " main.swift "
68- backup_file= " ${modified_file} .orig "
50+ scratch_dir= " $( " ${create_scratch_dir_sh} " --workspace " ${workspace_dir} " ) "
51+ cd " ${scratch_dir} "
6952
70- # Rename the file and copy the contents of the symlink to the original filename
71- # This should handle if the source if a symlink or the actual file.
72- mv " ${modified_file} " " ${backup_file} "
73- cp " ${backup_file} " " ${modified_file} "
53+ # MARK - Test Change, Test, and Update All
7454
75- # Set trap for cleanup
76- cleanup () {
77- mv -f " ${backup_file} " " ${modified_file} "
78- cd " ${starting_dir} "
79- }
80- trap cleanup EXIT
55+ # Should not fail, no changes
56+ " ${bazel} " test //... || fail " Expected test to succeed as nothing has changed yet."
8157
8258# Modify the file
8359# The spaces at the front of the statement should be removed by the formatter.
8460echo " let bar = 2" >> main.swift
8561
62+ # Should fail due to unformatted
63+ " ${bazel} " test //... && fail " Expected test to fail due to unformatted files."
64+
8665# Format the Swift files and copy them back to the workspace
87- " ${bazel} " run //:update_all
66+ " ${bazel} " run //:update_all || fail " Expected update_all to succeed. "
8867
8968# This should succeed now that the formatted files have been updated
90- " ${bazel} " test //...
91-
92- # END Custom test logic
69+ " ${bazel} " test //... || fail " Expected test to succeed after update_all."
0 commit comments