| """Unit tests for rust toolchains.""" |
| |
| load("@bazel_skylib//lib:unittest.bzl", "analysistest", "asserts") |
| load("//rust:toolchain.bzl", "rust_stdlib_filegroup", "rust_toolchain") |
| |
| def _toolchain_specifies_target_triple_test_impl(ctx): |
| env = analysistest.begin(ctx) |
| toolchain_info = analysistest.target_under_test(env)[platform_common.ToolchainInfo] |
| |
| asserts.equals(env, None, toolchain_info.target_json) |
| asserts.equals(env, "toolchain-test-triple", toolchain_info.target_flag_value) |
| asserts.equals(env, "toolchain-test-triple", toolchain_info.target_triple) |
| |
| return analysistest.end(env) |
| |
| def _toolchain_specifies_target_json_test_impl(ctx): |
| env = analysistest.begin(ctx) |
| toolchain_info = analysistest.target_under_test(env)[platform_common.ToolchainInfo] |
| |
| asserts.equals(env, "toolchain-test-triple.json", toolchain_info.target_json.basename) |
| asserts.equals(env, "test/unit/toolchain/toolchain-test-triple.json", toolchain_info.target_flag_value) |
| asserts.equals(env, "", toolchain_info.target_triple) |
| |
| return analysistest.end(env) |
| |
| def _toolchain_location_expands_linkflags_impl(ctx): |
| env = analysistest.begin(ctx) |
| toolchain_info = analysistest.target_under_test(env)[platform_common.ToolchainInfo] |
| |
| asserts.equals( |
| env, |
| "test:test/unit/toolchain/config.txt", |
| toolchain_info.stdlib_linkflags.linking_context.linker_inputs.to_list()[0].user_link_flags[0], |
| ) |
| |
| return analysistest.end(env) |
| |
| toolchain_specifies_target_triple_test = analysistest.make(_toolchain_specifies_target_triple_test_impl) |
| toolchain_specifies_target_json_test = analysistest.make(_toolchain_specifies_target_json_test_impl) |
| toolchain_location_expands_linkflags_test = analysistest.make(_toolchain_location_expands_linkflags_impl) |
| |
| def _toolchain_test(): |
| native.filegroup( |
| name = "stdlib_srcs", |
| srcs = ["config.txt"], |
| ) |
| rust_stdlib_filegroup( |
| name = "std_libs", |
| srcs = [":stdlib_srcs"], |
| ) |
| |
| native.filegroup( |
| name = "target_json", |
| srcs = ["toolchain-test-triple.json"], |
| ) |
| |
| rust_toolchain( |
| name = "rust_triple_toolchain", |
| binary_ext = "", |
| dylib_ext = ".so", |
| os = "linux", |
| rust_std = ":std_libs", |
| staticlib_ext = ".a", |
| stdlib_linkflags = [], |
| target_triple = "toolchain-test-triple", |
| ) |
| |
| rust_toolchain( |
| name = "rust_json_toolchain", |
| binary_ext = "", |
| dylib_ext = ".so", |
| os = "linux", |
| rust_std = ":std_libs", |
| staticlib_ext = ".a", |
| stdlib_linkflags = [], |
| target_json = ":target_json", |
| ) |
| |
| rust_toolchain( |
| name = "rust_location_expand_toolchain", |
| binary_ext = "", |
| dylib_ext = ".so", |
| os = "linux", |
| rust_std = ":std_libs", |
| staticlib_ext = ".a", |
| stdlib_linkflags = ["test:$(location :stdlib_srcs)"], |
| target_json = ":target_json", |
| ) |
| |
| toolchain_specifies_target_triple_test( |
| name = "toolchain_specifies_target_triple_test", |
| target_under_test = ":rust_triple_toolchain", |
| ) |
| toolchain_specifies_target_json_test( |
| name = "toolchain_specifies_target_json_test", |
| target_under_test = ":rust_json_toolchain", |
| ) |
| toolchain_location_expands_linkflags_test( |
| name = "toolchain_location_expands_linkflags_test", |
| target_under_test = ":rust_location_expand_toolchain", |
| ) |
| |
| def toolchain_test_suite(name): |
| _toolchain_test() |
| |
| native.test_suite( |
| name = name, |
| tests = [ |
| ":toolchain_specifies_target_triple_test", |
| ":toolchain_specifies_target_json_test", |
| ], |
| ) |