fork/rules_rust
git clone https://git.julia.blue/fork/rules_rust
35c92d02
patching
1"""Tests for toolchain channel transitions""" 2 3load ( "@bazel_skylib//lib:unittest.bzl" , "analysistest" ) 4load ( "@bazel_skylib//rules:write_file.bzl" , "write_file" ) 5load ( "//rust:defs.bzl" , "rust_binary" ) 6load ( 7"//test/unit:common.bzl" , 8"assert_action_mnemonic" , 9"assert_argv_contains" , 10"assert_argv_contains_not" , 11) 12 13def _channel_transition_test_impl ( ctx , is_nightly ): 14env = analysistest . begin ( ctx ) 15target = analysistest . target_under_test ( env ) 16 17action = target . actions [ 0 ] 18assert_action_mnemonic ( env , action , "Rustc" ) 19 20if is_nightly : 21assert_argv_contains ( env , action , "-Zunstable-options" ) 22else : 23assert_argv_contains_not ( env , action , "-Zunstable-options" ) 24 25return analysistest . end ( env ) 26 27def _nightly_transition_test_impl ( ctx ): 28return _channel_transition_test_impl ( ctx , True ) 29 30nightly_transition_test = analysistest . make ( 31_nightly_transition_test_impl , 32doc = "Test that targets can be forced to use a nightly toolchain" , 33config_settings = { 34str ( Label ( "//rust/toolchain/channel:channel" )): "nightly" , 35}, 36) 37 38def _stable_transition_test_impl ( ctx ): 39return _channel_transition_test_impl ( ctx , False ) 40 41stable_transition_test = analysistest . make ( 42_stable_transition_test_impl , 43doc = "Test that targets can be forced to use a stable toolchain" , 44config_settings = { 45str ( Label ( "//rust/toolchain/channel:channel" )): "stable" , 46}, 47) 48 49def channel_transitions_test_suite ( name ): 50"""Entry-point macro called from the BUILD file. 51 52Args: 53name (str): Name of the macro. 54""" 55 56write_file ( 57name = "main_rs" , 58out = "main.rs" , 59content = [ 60"fn main() {}" , 61"" , 62], 63) 64 65rust_binary ( 66name = "bin" , 67srcs = [ "main.rs" ], 68edition = "2018" , 69rustc_flags = select ({ 70"@rules_rust//rust/toolchain/channel:nightly" : [ "-Zunstable-options" ], 71"//conditions:default" : [], 72}), 73) 74 75nightly_transition_test ( 76name = "nightly_transition_test" , 77target_under_test = ":bin" , 78) 79 80stable_transition_test ( 81name = "stable_transition_test" , 82target_under_test = ":bin" , 83) 84 85native . test_suite ( 86name = name , 87tests = [ 88":nightly_transition_test" , 89":stable_transition_test" , 90], 91)