Skip to content

Commit edc8e8d

Browse files
committed
Set up test
1 parent d4d8316 commit edc8e8d

File tree

5 files changed

+153
-0
lines changed

5 files changed

+153
-0
lines changed

.bazelci/presubmit.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,12 @@ tasks:
8585
bazel: 6.3.0
8686
shell_commands:
8787
- "./test_examples.sh"
88+
cross_build_linux:
89+
name: "./test_cross_build"
90+
platform: ubuntu2004
91+
bazel: 6.3.0
92+
shell_commands:
93+
- "./test_cross_build.sh"
8894
lint_linux:
8995
name: "bazel //tools:lint_check"
9096
platform: ubuntu2004

test/shell/test_cross_build.sh

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
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

test_all.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ set -euo pipefail
55
dir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
66
"${dir}"/test_rules_scala.sh
77
"${dir}"/test_version.sh
8+
"${dir}"/test_cross_build.sh
89
"${dir}"/test_reproducibility.sh
910
#"${dir}"/test_intellij_aspect.sh

test_cross_build.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
test_dir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/test/shell
6+
7+
. "${test_dir}"/test_cross_build.sh

test_cross_build/WORKSPACE

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# WORKSPACE
2+
3+
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
4+
5+
http_archive(
6+
name = "bazel_skylib",
7+
sha256 = "d00f1389ee20b60018e92644e0948e16e350a7707219e7a390fb0a99b6ec9262",
8+
urls = [
9+
"https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.7.0/bazel-skylib-1.7.0.tar.gz",
10+
"https://github.com/bazelbuild/bazel-skylib/releases/download/1.7.0/bazel-skylib-1.7.0.tar.gz",
11+
],
12+
)
13+
14+
local_repository(
15+
name = "io_bazel_rules_scala",
16+
path = "..",
17+
)
18+
19+
load("@io_bazel_rules_scala//:scala_config.bzl", "scala_config")
20+
21+
scala_config(
22+
scala_version = "3.1.0",
23+
scala_versions = [
24+
"2.11.12",
25+
"2.12.18",
26+
"2.13.12",
27+
"3.1.0",
28+
"3.2.1",
29+
"3.3.1",
30+
],
31+
)
32+
33+
# loads other rules Rules Scala depends on
34+
load("@io_bazel_rules_scala//scala:scala.bzl", "rules_scala_toolchain_deps_repositories")
35+
36+
rules_scala_toolchain_deps_repositories()
37+
38+
load("@io_bazel_rules_scala//scala:toolchains.bzl", "scala_register_toolchains")
39+
40+
scala_register_toolchains()

0 commit comments

Comments
 (0)