fork/rules_rust
git clone https://git.julia.blue/fork/rules_rust
5abeb933
0.6.0
1"""Unittests for rust rules.""" 2 3load ( "@bazel_skylib//lib:unittest.bzl" , "analysistest" , "asserts" ) 4load ( 5"//rust:defs.bzl" , 6"rust_common" , 7"rust_library" , 8"rust_proc_macro" , 9"rust_shared_library" , 10"rust_static_library" , 11) 12 13def _rule_provides_crate_info_test_impl ( ctx ): 14env = analysistest . begin ( ctx ) 15tut = analysistest . target_under_test ( env ) 16asserts . true ( 17env , 18rust_common . crate_info in tut , 19"{} should provide CrateInfo" . format ( tut . label . name ), 20) 21return analysistest . end ( env ) 22 23def _rule_does_not_provide_crate_info_test_impl ( ctx ): 24env = analysistest . begin ( ctx ) 25tut = analysistest . target_under_test ( env ) 26asserts . false ( 27env , 28rust_common . crate_info in tut , 29"{} should not provide CrateInfo" . format ( tut . label . name ), 30) 31asserts . true ( 32env , 33rust_common . test_crate_info in tut , 34"{} should provide a TestCrateInfo" . format ( tut . label . name ), 35) 36return analysistest . end ( env ) 37 38rule_provides_crate_info_test = analysistest . make ( _rule_provides_crate_info_test_impl ) 39rule_does_not_provide_crate_info_test = analysistest . make ( _rule_does_not_provide_crate_info_test_impl ) 40 41def _crate_info_test (): 42rust_library ( 43name = "rlib" , 44srcs = [ "lib.rs" ], 45edition = "2018" , 46) 47 48rust_proc_macro ( 49name = "proc_macro" , 50srcs = [ "lib.rs" ], 51edition = "2018" , 52) 53 54rust_static_library ( 55name = "staticlib" , 56srcs = [ "lib.rs" ], 57edition = "2018" , 58) 59 60rust_shared_library ( 61name = "cdylib" , 62srcs = [ "lib.rs" ], 63edition = "2018" , 64) 65 66rule_provides_crate_info_test ( 67name = "rlib_provides_crate_info_test" , 68target_under_test = ":rlib" , 69) 70 71rule_provides_crate_info_test ( 72name = "proc_macro_provides_crate_info_test" , 73target_under_test = ":proc_macro" , 74) 75 76rule_does_not_provide_crate_info_test ( 77name = "cdylib_does_not_provide_crate_info_test" , 78target_under_test = ":cdylib" , 79) 80 81rule_does_not_provide_crate_info_test ( 82name = "staticlib_does_not_provide_crate_info_test" , 83target_under_test = ":staticlib" , 84) 85 86def crate_info_test_suite ( name ): 87"""Entry-point macro called from the BUILD file. 88 89Args: 90name: Name of the macro. 91""" 92_crate_info_test () 93 94native . test_suite ( 95name = name , 96tests = [ 97":rlib_provides_crate_info_test" , 98":proc_macro_provides_crate_info_test" , 99":cdylib_does_not_provide_crate_info_test" , 100":staticlib_does_not_provide_crate_info_test" , 101], 102)