|
| 1 | +# shellcheck source=./test_runner.sh |
| 2 | +dir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) |
| 3 | +. "${dir}"/test_runner.sh |
| 4 | +. "${dir}"/test_helper.sh |
| 5 | +runner=$(get_test_runner "${1:-local}") |
| 6 | + |
| 7 | +cd test_cross_build |
| 8 | + |
| 9 | +function test_cross_build() { |
| 10 | + bazel test //... |
| 11 | + bazel clean |
| 12 | + bazel shutdown; |
| 13 | +} |
| 14 | + |
| 15 | +backup_unformatted() { |
| 16 | + FILE_PATH=$1 |
| 17 | + FILENAME=$2 |
| 18 | + cp $FILE_PATH/unformatted/unformatted-$FILENAME.scala $FILE_PATH/unformatted/unformatted-$FILENAME.backup.scala |
| 19 | +} |
| 20 | + |
| 21 | +restore_unformatted_before_exit() { |
| 22 | + FILE_PATH=$1 |
| 23 | + FILENAME=$2 |
| 24 | + cp $FILE_PATH/unformatted/unformatted-$FILENAME.backup.scala $FILE_PATH/unformatted/unformatted-$FILENAME.scala |
| 25 | + rm -f $FILE_PATH/unformatted/unformatted-$FILENAME.backup.scala |
| 26 | +} |
| 27 | + |
| 28 | +run_formatting() { |
| 29 | + set +e |
| 30 | + |
| 31 | + FILE_PATH=src/main/scalafmt |
| 32 | + NAME=$1 |
| 33 | + |
| 34 | + local run_under="" |
| 35 | + if is_windows; then |
| 36 | + run_under="--run_under=bash" |
| 37 | + fi |
| 38 | + |
| 39 | + bazel run //src/main/scalafmt:formatted-$NAME.format-test $run_under |
| 40 | + if [ $? -ne 0 ]; then |
| 41 | + echo -e "${RED} formatted-$NAME.format-test should be a formatted target. $NC" |
| 42 | + exit 1 |
| 43 | + fi |
| 44 | + |
| 45 | + bazel run //src/main/scalafmt:unformatted-$NAME.format-test $run_under |
| 46 | + if [ $? -eq 0 ]; then |
| 47 | + echo -e "${RED} unformatted-$NAME.format-test should be an unformatted target. $NC" |
| 48 | + exit 1 |
| 49 | + fi |
| 50 | + |
| 51 | + backup_unformatted $FILE_PATH $NAME |
| 52 | + |
| 53 | + bazel run //src/main/scalafmt:unformatted-$NAME.format $run_under |
| 54 | + if [ $? -ne 0 ]; then |
| 55 | + echo -e "${RED} unformatted-$NAME.format should run formatting. $NC" |
| 56 | + restore_unformatted_before_exit $FILE_PATH $NAME |
| 57 | + exit 1 |
| 58 | + fi |
| 59 | + |
| 60 | + diff $FILE_PATH/unformatted/unformatted-$FILENAME.scala $FILE_PATH/formatted/formatted-$FILENAME.scala |
| 61 | + if [ $? -ne 0 ]; then |
| 62 | + echo -e "${RED} unformatted-$NAME.scala should be the same as formatted-$NAME.scala after formatting. $NC" |
| 63 | + restore_unformatted_before_exit $FILE_PATH $NAME |
| 64 | + exit 1 |
| 65 | + fi |
| 66 | + restore_unformatted_before_exit $FILE_PATH $NAME |
| 67 | +} |
| 68 | + |
| 69 | +test_scalafmt_library2() { |
| 70 | + run_formatting library2 |
| 71 | +} |
| 72 | + |
| 73 | +test_scalafmt_library3() { |
| 74 | + run_formatting library3 |
| 75 | +} |
| 76 | + |
| 77 | +test_scalafmt_binary2() { |
| 78 | + run_formatting binary2 |
| 79 | +} |
| 80 | + |
| 81 | +test_scalafmt_binary3() { |
| 82 | + run_formatting binary3 |
| 83 | +} |
| 84 | + |
| 85 | +test_scalafmt_test2() { |
| 86 | + run_formatting test2 |
| 87 | +} |
| 88 | + |
| 89 | +test_scalafmt_test3() { |
| 90 | + run_formatting test3 |
| 91 | +} |
| 92 | + |
| 93 | +$runner test_scalafmt_library2 |
| 94 | +$runner test_scalafmt_library3 |
| 95 | +$runner test_scalafmt_binary2 |
| 96 | +$runner test_scalafmt_binary3 |
| 97 | +$runner test_scalafmt_test2 |
| 98 | +$runner test_scalafmt_test3 |
| 99 | +$runner test_cross_build |
0 commit comments