fork/rules_rust
git clone https://git.julia.blue/fork/rules_rust
a366b761
0.8.1
1"""Unittest to verify re-exported symbols propagate to downstream crates""" 2 3load ( "@bazel_skylib//lib:unittest.bzl" , "analysistest" , "asserts" ) 4load ( "//test/unit:common.bzl" , "assert_argv_contains_prefix" , "assert_argv_contains_prefix_suffix" ) 5 6def _exports_test_impl ( ctx , dependencies , externs ): 7env = analysistest . begin ( ctx ) 8target = analysistest . target_under_test ( env ) 9 10action = target . actions [ 0 ] 11asserts . equals ( env , action . mnemonic , "Rustc" ) 12 13# Transitive symbols that get re-exported are expected to be located by a `-Ldependency` flag. 14# The assert below ensures that each dependnecy flag is passed to the Rustc action. For details see 15# https://doc.rust-lang.org/rustc/command-line-arguments.html#-l-add-a-directory-to-the-library-search-path 16for dep in dependencies : 17assert_argv_contains_prefix_suffix ( 18env = env , 19action = action , 20prefix = "-Ldependency" , 21suffix = dep , 22) 23 24for dep in externs : 25assert_argv_contains_prefix ( 26env = env , 27action = action , 28prefix = "--extern={}=" . format ( dep ), 29) 30 31return analysistest . end ( env ) 32 33def _lib_exports_test_impl ( ctx ): 34# This test is only expected to be used with 35# `//test/unit/exports/lib_c` 36return _exports_test_impl ( 37ctx = ctx , 38dependencies = [ "lib_a" , "lib_b" ], 39externs = [ "lib_b" ], 40) 41 42def _test_exports_test_impl ( ctx ): 43# This test is only expected to be used with 44# `//test/unit/exports/lib_c:lib_c_test` 45return _exports_test_impl ( 46ctx = ctx , 47dependencies = [ "lib_a" , "lib_b" ], 48externs = [ "lib_b" ], 49) 50 51lib_exports_test = analysistest . make ( _lib_exports_test_impl ) 52test_exports_test = analysistest . make ( _test_exports_test_impl ) 53 54def exports_test_suite ( name ): 55"""Entry-point macro called from the BUILD file. 56 57Args: 58name (str): Name of the macro. 59""" 60 61lib_exports_test ( 62name = "lib_exports_test" , 63target_under_test = "//test/unit/exports/lib_c" , 64) 65 66test_exports_test ( 67name = "test_exports_test" , 68target_under_test = "//test/unit/exports/lib_c:lib_c_test" , 69) 70 71native . test_suite ( 72name = name , 73tests = [ 74":lib_exports_test" , 75":test_exports_test" , 76], 77)