fork/rules_rust
git clone https://git.julia.blue/fork/rules_rust
e10ab210
0.9.0
1"""Unittest to verify compile_data (attribute) propagation""" 2 3load ( "@bazel_skylib//lib:unittest.bzl" , "analysistest" , "asserts" ) 4load ( "//rust:defs.bzl" , "rust_common" , "rust_library" , "rust_test" ) 5 6def _target_has_compile_data ( ctx , expected ): 7env = analysistest . begin ( ctx ) 8target = analysistest . target_under_test ( env ) 9 10# Extract compile_data from a target expected to have a `CrateInfo` provider 11crate_info = target [ rust_common . crate_info ] 12compile_data = crate_info . compile_data . to_list () 13 14# Ensure compile data was correctly propagated to the provider 15asserts . equals ( 16env , 17sorted ([ data . short_path for data in compile_data ]), 18expected , 19) 20 21return analysistest . end ( env ) 22 23def _compile_data_propagates_to_crate_info_test_impl ( ctx ): 24return _target_has_compile_data ( 25ctx , 26[ "test/unit/compile_data/compile_data.txt" ], 27) 28 29def _wrapper_rule_propagates_to_crate_info_test_impl ( ctx ): 30return _target_has_compile_data ( 31ctx , 32[ "test/unit/compile_data/compile_data.txt" ], 33) 34 35def _wrapper_rule_propagates_and_joins_compile_data_test_impl ( ctx ): 36return _target_has_compile_data ( 37ctx , 38[ 39"test/unit/compile_data/compile_data.txt" , 40"test/unit/compile_data/test_compile_data.txt" , 41], 42) 43 44compile_data_propagates_to_crate_info_test = analysistest . make ( _compile_data_propagates_to_crate_info_test_impl ) 45wrapper_rule_propagates_to_crate_info_test = analysistest . make ( _wrapper_rule_propagates_to_crate_info_test_impl ) 46wrapper_rule_propagates_and_joins_compile_data_test = analysistest . make ( _wrapper_rule_propagates_and_joins_compile_data_test_impl ) 47 48def _define_test_targets (): 49rust_library ( 50name = "compile_data" , 51srcs = [ "compile_data.rs" ], 52compile_data = [ "compile_data.txt" ], 53edition = "2018" , 54) 55 56rust_test ( 57name = "compile_data_unit_test" , 58crate = ":compile_data" , 59) 60 61rust_test ( 62name = "test_compile_data_unit_test" , 63compile_data = [ "test_compile_data.txt" ], 64crate = ":compile_data" , 65rustc_flags = [ "--cfg=test_compile_data" ], 66) 67 68def compile_data_test_suite ( name ): 69"""Entry-point macro called from the BUILD file. 70 71Args: 72name (str): Name of the macro. 73""" 74 75_define_test_targets () 76 77compile_data_propagates_to_crate_info_test ( 78name = "compile_data_propagates_to_crate_info_test" , 79target_under_test = ":compile_data" , 80) 81 82wrapper_rule_propagates_to_crate_info_test ( 83name = "wrapper_rule_propagates_to_crate_info_test" , 84target_under_test = ":compile_data_unit_test" , 85) 86 87wrapper_rule_propagates_and_joins_compile_data_test ( 88name = "wrapper_rule_propagates_and_joins_compile_data_test" , 89target_under_test = ":test_compile_data_unit_test" , 90) 91 92native . test_suite ( 93name = name , 94tests = [ 95":compile_data_propagates_to_crate_info_test" , 96":wrapper_rule_propagates_to_crate_info_test" , 97":wrapper_rule_propagates_and_joins_compile_data_test" , 98], 99)