From 6548eccdcc64b494189a833f6a93df781f6348f0 Mon Sep 17 00:00:00 2001 From: Daniel Wagner-Hall Date: Wed, 15 Jun 2022 11:06:29 +0100 Subject: [PATCH] Switch to integration test --- .../BUILD.bazel | 19 ------------- .../defs.bzl | 26 ----------------- .../src/main.rs | 28 ------------------- test/rustc_env_from_toolchain/BUILD.bazel | 19 +++++++++++++ test/rustc_env_from_toolchain/output_test.sh | 6 ++++ test/rustc_env_from_toolchain/src/main.rs | 20 +++++++++++++ 6 files changed, 45 insertions(+), 73 deletions(-) delete mode 100644 test/rust_toolchain_template_variable_info/BUILD.bazel delete mode 100644 test/rust_toolchain_template_variable_info/defs.bzl delete mode 100644 test/rust_toolchain_template_variable_info/src/main.rs create mode 100644 test/rustc_env_from_toolchain/BUILD.bazel create mode 100755 test/rustc_env_from_toolchain/output_test.sh create mode 100644 test/rustc_env_from_toolchain/src/main.rs diff --git a/test/rust_toolchain_template_variable_info/BUILD.bazel b/test/rust_toolchain_template_variable_info/BUILD.bazel deleted file mode 100644 index c69b0074c5..0000000000 --- a/test/rust_toolchain_template_variable_info/BUILD.bazel +++ /dev/null @@ -1,19 +0,0 @@ -load("//rust:defs.bzl", "rust_binary") -load( - "//test/rust_toolchain_template_variable_info:defs.bzl", - "rust_toolchain_template_variable_info_test", -) - -rust_binary( - name = "bin", - srcs = ["src/main.rs"], - edition = "2021", -) - -rust_toolchain_template_variable_info_test( - name = "rust_toolchain_template_variable_info_test", - args = [ - "--cargo=$(CARGO)", - "--rustc=$(RUSTC)", - ], -) diff --git a/test/rust_toolchain_template_variable_info/defs.bzl b/test/rust_toolchain_template_variable_info/defs.bzl deleted file mode 100644 index bd0a5ceed5..0000000000 --- a/test/rust_toolchain_template_variable_info/defs.bzl +++ /dev/null @@ -1,26 +0,0 @@ -"""A module which defines rules for testing TemplateVariableInfo""" - -def _rust_toolchain_template_variable_info_test_impl(ctx): - exe = ctx.actions.declare_file(ctx.label.name + ".exe") - ctx.actions.symlink( - output = exe, - target_file = ctx.executable._bin, - is_executable = True, - ) - return [DefaultInfo( - executable = exe, - runfiles = ctx.attr._bin[DefaultInfo].default_runfiles, - )] - -rust_toolchain_template_variable_info_test = rule( - implementation = _rust_toolchain_template_variable_info_test_impl, - attrs = { - "_bin": attr.label( - default = "//test/rust_toolchain_template_variable_info:bin", - executable = True, - cfg = "exec", - ), - }, - toolchains = ["//rust:toolchain"], - test = True, -) diff --git a/test/rust_toolchain_template_variable_info/src/main.rs b/test/rust_toolchain_template_variable_info/src/main.rs deleted file mode 100644 index 87955f2659..0000000000 --- a/test/rust_toolchain_template_variable_info/src/main.rs +++ /dev/null @@ -1,28 +0,0 @@ -fn main() { - ["cargo", "rustc"].iter().for_each(|target| { - let mut args = std::env::args().skip(1); - - let value = args - .find_map(|arg| { - arg.strip_prefix(&format!("--{}=", target)) - .map(|s| s.to_string()) - }) - .unwrap_or_else(|| panic!("missing flag for {}", target)); - - let want_prefix = "bazel-out/"; - assert!( - value.starts_with(want_prefix), - "want prefix {} for {}", - want_prefix, - value, - ); - - let want_suffix = &format!("/bin/{}", target); - assert!( - value.ends_with(want_suffix), - "want suffix {} for {}", - want_suffix, - value - ); - }); -} diff --git a/test/rustc_env_from_toolchain/BUILD.bazel b/test/rustc_env_from_toolchain/BUILD.bazel new file mode 100644 index 0000000000..dda92afad5 --- /dev/null +++ b/test/rustc_env_from_toolchain/BUILD.bazel @@ -0,0 +1,19 @@ +load("//rust:defs.bzl", "rust_binary") + +package(default_visibility = ["//visibility:public"]) + +rust_binary( + name = "hello_env", + srcs = ["src/main.rs"], + edition = "2018", + rustc_env = { + "CUSTOM_RUSTC_FROM_TOOLCHAIN": "$(RUSTC)", + }, +) + +sh_test( + name = "output_test", + srcs = ["output_test.sh"], + args = ["$(location :hello_env)"], + data = [":hello_env"], +) diff --git a/test/rustc_env_from_toolchain/output_test.sh b/test/rustc_env_from_toolchain/output_test.sh new file mode 100755 index 0000000000..a9aa56da76 --- /dev/null +++ b/test/rustc_env_from_toolchain/output_test.sh @@ -0,0 +1,6 @@ +#!/bin/bash -eu + +set -o pipefail + +output="$($1)" +[[ "${output}" == "Compiled with compiler: "*rustc* ]] || { echo >&2 "Unexpected output: ${output}"; exit 1;} diff --git a/test/rustc_env_from_toolchain/src/main.rs b/test/rustc_env_from_toolchain/src/main.rs new file mode 100644 index 0000000000..dba869533b --- /dev/null +++ b/test/rustc_env_from_toolchain/src/main.rs @@ -0,0 +1,20 @@ +// Copyright 2022 The Bazel Authors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +fn main() { + println!( + "Compiled with compiler: {}", + env!("CUSTOM_RUSTC_FROM_TOOLCHAIN"), + ); +}