From c2396fb7a2bf647b193026dc9ab54adf7f15e680 Mon Sep 17 00:00:00 2001 From: UebelAndre Date: Tue, 13 Jun 2023 06:30:47 -0700 Subject: [PATCH] Minor CI and test cleanup --- .bazelci/presubmit.yml | 13 ++++++------- test/BUILD.bazel | 19 ------------------- test/rust/BUILD.bazel | 16 ++++++++++++++++ test/rustc_env_files/BUILD.bazel | 6 ++++-- test/rustc_env_files/output_test.rs | 18 ++++++++++++++++++ test/rustc_env_files/output_test.sh | 6 ------ 6 files changed, 44 insertions(+), 34 deletions(-) create mode 100644 test/rustc_env_files/output_test.rs delete mode 100755 test/rustc_env_files/output_test.sh diff --git a/.bazelci/presubmit.yml b/.bazelci/presubmit.yml index 80e7bc5d6d..7b3afaa950 100644 --- a/.bazelci/presubmit.yml +++ b/.bazelci/presubmit.yml @@ -50,7 +50,6 @@ tasks: test_targets: - "--" # Allows negative patterns; hack for https://github.com/bazelbuild/continuous-integration/pull/245 - "//..." - - "//test/..." - "-//test/conflicting_deps:conflicting_deps_test" # TODO: This test does not work on RBE - "-//test/versioned_dylib:versioned_dylib_test" @@ -103,8 +102,7 @@ tasks: build_targets: *default_linux_targets test_targets: - "--" # Allows negative patterns; hack for https://github.com/bazelbuild/continuous-integration/pull/245 - - "..." - - "//test/..." + - "//..." - "-//test/conflicting_deps:conflicting_deps_test" # TODO: This test does not work on RBE - "-//test/versioned_dylib:versioned_dylib_test" @@ -118,8 +116,7 @@ tasks: build_targets: *default_linux_targets test_targets: - "--" # Allows negative patterns; hack for https://github.com/bazelbuild/continuous-integration/pull/245 - - "..." - - "//test/..." + - "//..." - "-//test/conflicting_deps:conflicting_deps_test" # TODO: This test does not work on RBE - "-//test/versioned_dylib:versioned_dylib_test" @@ -302,11 +299,12 @@ tasks: working_directory: examples build_flags: - "--repo_env=CC=clang" + - "--config=rustfmt" + - "--config=clippy" build_targets: - "//..." test_targets: - "//..." - build_flags: *aspects_flags ubuntu2004_examples_clang_lld: name: Examples with Clang and LLD platform: ubuntu2004 @@ -316,11 +314,12 @@ tasks: build_flags: - "--repo_env=CC=clang" - "--linkopt=-fuse-ld=lld" + - "--config=rustfmt" + - "--config=clippy" build_targets: - "//..." test_targets: - "//..." - build_flags: *aspects_flags ubuntu2004_examples_rolling: name: "Examples with Rolling Bazel Version" platform: ubuntu2004 diff --git a/test/BUILD.bazel b/test/BUILD.bazel index a217437d3e..e69de29bb2 100644 --- a/test/BUILD.bazel +++ b/test/BUILD.bazel @@ -1,19 +0,0 @@ -load( - "@bazel_tools//tools/build_rules:test_rules.bzl", - "rule_test", -) - -rule_test( - name = "hello_lib_rule_test", - generates = ["libhello_lib-683707109.rlib"], - rule = "//test/rust:hello_lib", -) - -rule_test( - name = "hello_world_rule_test", - generates = select({ - "//rust/platform:windows": ["hello_world.exe"], - "//conditions:default": ["hello_world"], - }), - rule = "//test/rust:hello_world", -) diff --git a/test/rust/BUILD.bazel b/test/rust/BUILD.bazel index 4209f4ce87..ad873a4dc6 100644 --- a/test/rust/BUILD.bazel +++ b/test/rust/BUILD.bazel @@ -1,3 +1,4 @@ +load("@bazel_tools//tools/build_rules:test_rules.bzl", "rule_test") load("//rust:defs.bzl", "rust_binary", "rust_library", "rust_test") package(default_visibility = ["//visibility:public"]) @@ -24,3 +25,18 @@ rust_test( name = "hello_lib_test", crate = ":hello_lib", ) + +rule_test( + name = "hello_lib_rule_test", + generates = ["libhello_lib-683707109.rlib"], + rule = ":hello_lib", +) + +rule_test( + name = "hello_world_rule_test", + generates = select({ + "//rust/platform:windows": ["hello_world.exe"], + "//conditions:default": ["hello_world"], + }), + rule = "//test/rust:hello_world", +) diff --git a/test/rustc_env_files/BUILD.bazel b/test/rustc_env_files/BUILD.bazel index cb48b2ef4a..d32457fa43 100644 --- a/test/rustc_env_files/BUILD.bazel +++ b/test/rustc_env_files/BUILD.bazel @@ -20,11 +20,13 @@ write_file( ], ) -sh_test( +rust_test( name = "output_test", - srcs = ["output_test.sh"], + srcs = ["output_test.rs"], args = ["$(rootpath :hello_env)"], data = [":hello_env"], + edition = "2018", + use_libtest_harness = False, ) rust_library( diff --git a/test/rustc_env_files/output_test.rs b/test/rustc_env_files/output_test.rs new file mode 100644 index 0000000000..daa71c3ca4 --- /dev/null +++ b/test/rustc_env_files/output_test.rs @@ -0,0 +1,18 @@ +use std::process; + +fn main() { + let binary = std::env::args().nth(1).expect("No argument was provided"); + + let output = process::Command::new(binary) + .output() + .expect("Failed to spawn process"); + if !output.status.success() { + eprintln!("Failed to execute binary"); + eprintln!("{}", std::str::from_utf8(&output.stdout).unwrap()); + eprintln!("{}", std::str::from_utf8(&output.stderr).unwrap()); + process::exit(output.status.code().unwrap()); + } + + let stdout = std::str::from_utf8(&output.stdout).unwrap().trim(); + assert_eq!("Howdy from version 1.2.3", stdout); +} diff --git a/test/rustc_env_files/output_test.sh b/test/rustc_env_files/output_test.sh deleted file mode 100755 index 9bb91fe474..0000000000 --- a/test/rustc_env_files/output_test.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/bash -eu - -set -o pipefail - -output="$($1)" -[[ "${output}" == "Howdy from version 1.2.3" ]] || { echo >&2 "Unexpected output: ${output}"; exit 1;}