diff --git a/.bazelci/presubmit.yml b/.bazelci/presubmit.yml index d7cac2dfcf..6f35805268 100644 --- a/.bazelci/presubmit.yml +++ b/.bazelci/presubmit.yml @@ -397,12 +397,12 @@ tasks: name: Negative Clippy Tests platform: ubuntu2004 run_targets: - - "//test/clippy:clippy_failure_test" + - "//test/clippy:clippy_failure_tester" rustfmt_failure: name: Negative Rustfmt Tests platform: ubuntu2004 run_targets: - - "//test/rustfmt:rustfmt_integration_test_suite.test_runner" + - "//test/rustfmt:rustfmt_failure_tester" rust_analyzer_tests: name: Rust-Analyzer Tests platform: ubuntu2004 diff --git a/test/clippy/BUILD.bazel b/test/clippy/BUILD.bazel index 14d4710392..ea449a0008 100644 --- a/test/clippy/BUILD.bazel +++ b/test/clippy/BUILD.bazel @@ -10,7 +10,7 @@ load( ) load("@rules_shell//shell:sh_binary.bzl", "sh_binary") -package(default_visibility = ["//test:__subpackages__"]) +package(default_visibility = ["//test/unit/clippy:__pkg__"]) # Declaration of passing targets. @@ -167,6 +167,6 @@ rust_clippy( ) sh_binary( - name = "clippy_failure_test", - srcs = ["clippy_failure_test.sh"], + name = "clippy_failure_tester", + srcs = ["clippy_failure_tester.sh"], ) diff --git a/test/clippy/clippy_failure_test.sh b/test/clippy/clippy_failure_tester.sh similarity index 86% rename from test/clippy/clippy_failure_test.sh rename to test/clippy/clippy_failure_tester.sh index ef202ee928..05ab24c6f9 100755 --- a/test/clippy/clippy_failure_test.sh +++ b/test/clippy/clippy_failure_tester.sh @@ -61,16 +61,32 @@ function test_all() { mkdir -p "${NEW_WORKSPACE}/test/clippy" && \ cp -r test/clippy/* "${NEW_WORKSPACE}/test/clippy/" && \ - cat << EOF > "${NEW_WORKSPACE}/WORKSPACE.bazel" -workspace(name = "rules_rust_test_clippy") -local_repository( - name = "rules_rust", + cat << EOF > "${NEW_WORKSPACE}/MODULE.bazel" +module(name = "rules_rust_test_clippy") +bazel_dep(name = "rules_rust", version = "0.0.0") +local_path_override( + module_name = "rules_rust", path = "${BUILD_WORKSPACE_DIRECTORY}", ) -load("@rules_rust//rust:repositories.bzl", "rust_repositories") -rust_repositories() + +bazel_dep( + name = "bazel_skylib", + version = "1.7.1", +) +bazel_dep( + name = "rules_shell", + version = "0.3.0", +) + +rust = use_extension("@rules_rust//rust:extensions.bzl", "rust") +use_repo(rust, "rust_toolchains") +register_toolchains("@rust_toolchains//:all") EOF + if [[ -f "${BUILD_WORKSPACE_DIRECTORY}/.bazelversion" ]]; then + cp "${BUILD_WORKSPACE_DIRECTORY}/.bazelversion" "${NEW_WORKSPACE}/.bazelversion" + fi + # Drop the 'noclippy' tags if [ "$(uname)" == "Darwin" ]; then SEDOPTS=(-i '' -e) diff --git a/test/rustfmt/BUILD.bazel b/test/rustfmt/BUILD.bazel index 1b327cb8db..d101c8f97b 100644 --- a/test/rustfmt/BUILD.bazel +++ b/test/rustfmt/BUILD.bazel @@ -1,4 +1,5 @@ load("@bazel_skylib//rules:write_file.bzl", "write_file") +load("@rules_shell//shell:sh_binary.bzl", "sh_binary") load(":rustfmt_integration_test_suite.bzl", "rustfmt_integration_test_suite") exports_files([ @@ -19,3 +20,9 @@ pub fn greeting() { rustfmt_integration_test_suite( name = "rustfmt_integration_test_suite", ) + +sh_binary( + name = "rustfmt_failure_tester", + testonly = True, + srcs = ["rustfmt_failure_tester.sh"], +) diff --git a/test/rustfmt/rustfmt_failure_test.sh b/test/rustfmt/rustfmt_failure_tester.sh similarity index 82% rename from test/rustfmt/rustfmt_failure_test.sh rename to test/rustfmt/rustfmt_failure_tester.sh index bcad661537..54755ef763 100755 --- a/test/rustfmt/rustfmt_failure_test.sh +++ b/test/rustfmt/rustfmt_failure_tester.sh @@ -43,18 +43,34 @@ function test_all_and_apply() { mkdir -p "${new_workspace}/test/rustfmt" && \ cp -r test/rustfmt/* "${new_workspace}/test/rustfmt/" && \ - cat << EOF > "${new_workspace}/WORKSPACE.bazel" -workspace(name = "rules_rust_test_rustfmt") -local_repository( - name = "rules_rust", + cat << EOF > "${new_workspace}/MODULE.bazel" +module(name = "rules_rust_test_rustfmt") +bazel_dep(name = "rules_rust", version = "0.0.0") +local_path_override( + module_name = "rules_rust", path = "${BUILD_WORKSPACE_DIRECTORY}", ) -load("@rules_rust//rust:repositories.bzl", "rust_repositories") -rust_repositories() + +bazel_dep( + name = "bazel_skylib", + version = "1.7.1", +) +bazel_dep( + name = "rules_shell", + version = "0.3.0", +) + +rust = use_extension("@rules_rust//rust:extensions.bzl", "rust") +use_repo(rust, "rust_toolchains") +register_toolchains("@rust_toolchains//:all") EOF # See github.com/bazelbuild/rules_rust/issues/2317. echo "build --noincompatible_sandbox_hermetic_tmp" > "${new_workspace}/.bazelrc" + if [[ -f "${BUILD_WORKSPACE_DIRECTORY}/.bazelversion" ]]; then + cp "${BUILD_WORKSPACE_DIRECTORY}/.bazelversion" "${new_workspace}/.bazelversion" + fi + # Drop the 'norustfmt' tags if [ "$(uname)" == "Darwin" ]; then SEDOPTS=(-i '' -e) diff --git a/test/rustfmt/rustfmt_integration_test_suite.bzl b/test/rustfmt/rustfmt_integration_test_suite.bzl index 03a197d8a3..183c4cd3cf 100644 --- a/test/rustfmt/rustfmt_integration_test_suite.bzl +++ b/test/rustfmt/rustfmt_integration_test_suite.bzl @@ -8,7 +8,6 @@ load( "rust_static_library", "rustfmt_test", ) -load("@rules_shell//shell:sh_binary.bzl", "sh_binary") _VARIANTS = { "rust_binary": rust_binary, @@ -115,9 +114,3 @@ def rustfmt_integration_test_suite(name, **kwargs): tests = tests, **kwargs ) - - sh_binary( - name = "{}.test_runner".format(name), - srcs = ["rustfmt_failure_test.sh"], - testonly = True, - )