fork/rules_rust
git clone https://git.julia.blue/fork/rules_rust
9803d303
cleanup
1"""Unittest to verify compile_data (attribute) propagation""" 2 3load ( "@bazel_skylib//lib:unittest.bzl" , "analysistest" , "asserts" ) 4load ( "//rust:defs.bzl" , "rust_common" , "rust_doc" , "rust_library" , "rust_test" ) 5load ( 6"//test/unit:common.bzl" , 7"assert_action_mnemonic" , 8) 9 10def _target_has_compile_data ( ctx , expected ): 11env = analysistest . begin ( ctx ) 12target = analysistest . target_under_test ( env ) 13 14# Extract compile_data from a target expected to have a `CrateInfo` provider 15crate_info = target [ rust_common . crate_info ] 16compile_data = crate_info . compile_data . to_list () 17 18# Ensure compile data was correctly propagated to the provider 19asserts . equals ( 20env , 21sorted ([ data . short_path for data in compile_data ]), 22expected , 23) 24 25return analysistest . end ( env ) 26 27def _compile_data_propagates_to_crate_info_test_impl ( ctx ): 28return _target_has_compile_data ( 29ctx , 30[ "test/unit/compile_data/compile_data.txt" ], 31) 32 33def _wrapper_rule_propagates_to_crate_info_test_impl ( ctx ): 34return _target_has_compile_data ( 35ctx , 36[ "test/unit/compile_data/compile_data.txt" ], 37) 38 39def _wrapper_rule_propagates_and_joins_compile_data_test_impl ( ctx ): 40return _target_has_compile_data ( 41ctx , 42[ 43"test/unit/compile_data/compile_data.txt" , 44"test/unit/compile_data/test_compile_data.txt" , 45], 46) 47 48def _compile_data_propagates_to_rust_doc_test_impl ( ctx ): 49env = analysistest . begin ( ctx ) 50target = analysistest . target_under_test ( env ) 51 52actions = target . actions 53action = actions [ 0 ] 54assert_action_mnemonic ( env , action , "Rustdoc" ) 55 56return analysistest . end ( env ) 57 58compile_data_propagates_to_crate_info_test = analysistest . make ( _compile_data_propagates_to_crate_info_test_impl ) 59wrapper_rule_propagates_to_crate_info_test = analysistest . make ( _wrapper_rule_propagates_to_crate_info_test_impl ) 60wrapper_rule_propagates_and_joins_compile_data_test = analysistest . make ( _wrapper_rule_propagates_and_joins_compile_data_test_impl ) 61compile_data_propagates_to_rust_doc_test = analysistest . make ( _compile_data_propagates_to_rust_doc_test_impl ) 62 63def _define_test_targets (): 64rust_library ( 65name = "compile_data" , 66srcs = [ "compile_data.rs" ], 67compile_data = [ "compile_data.txt" ], 68edition = "2018" , 69) 70 71rust_test ( 72name = "compile_data_unit_test" , 73crate = ":compile_data" , 74) 75 76rust_test ( 77name = "test_compile_data_unit_test" , 78compile_data = [ "test_compile_data.txt" ], 79crate = ":compile_data" , 80rustc_flags = [ "--cfg=test_compile_data" ], 81) 82 83rust_library ( 84name = "compile_data_env" , 85srcs = [ "compile_data_env.rs" ], 86compile_data = [ "compile_data.txt" ], 87rustc_env = { 88"COMPILE_DATA_PATH" : "$(execpath :compile_data.txt)" , 89}, 90edition = "2018" , 91) 92 93rust_doc ( 94name = "compile_data_env_rust_doc" , 95crate = ":compile_data_env" , 96) 97 98def compile_data_test_suite ( name ): 99"""Entry-point macro called from the BUILD file. 100 101Args: 102name (str): Name of the macro. 103""" 104 105_define_test_targets () 106 107compile_data_propagates_to_crate_info_test ( 108name = "compile_data_propagates_to_crate_info_test" , 109target_under_test = ":compile_data" , 110) 111 112wrapper_rule_propagates_to_crate_info_test ( 113name = "wrapper_rule_propagates_to_crate_info_test" , 114target_under_test = ":compile_data_unit_test" , 115) 116 117wrapper_rule_propagates_and_joins_compile_data_test ( 118name = "wrapper_rule_propagates_and_joins_compile_data_test" , 119target_under_test = ":test_compile_data_unit_test" , 120) 121 122compile_data_propagates_to_rust_doc_test ( 123name = "compile_data_propagates_to_rust_doc_test" , 124target_under_test = ":compile_data_env_rust_doc" , 125) 126 127native . test_suite ( 128name = name , 129tests = [ 130":compile_data_propagates_to_crate_info_test" , 131":wrapper_rule_propagates_to_crate_info_test" , 132":wrapper_rule_propagates_and_joins_compile_data_test" , 133":compile_data_propagates_to_rust_doc_test" , 134], 135)