fork/rules_rust
git clone https://git.julia.blue/fork/rules_rust
03a70796
cleanup
1"""Unittests for rust rules.""" 2 3load ( "@bazel_skylib//lib:unittest.bzl" , "analysistest" , "asserts" ) 4load ( 5"//rust:defs.bzl" , 6"rust_binary" , 7"rust_library" , 8"rust_shared_library" , 9"rust_static_library" , 10) 11 12def _check_runfiles_test_impl ( ctx ): 13env = analysistest . begin ( ctx ) 14tut = analysistest . target_under_test ( env ) 15runfiles = tut [ DefaultInfo ]. default_runfiles . files . to_list () 16 17asserts . true ( env , _is_in_runfiles ( "libbar.so" , runfiles )) 18 19return analysistest . end ( env ) 20 21def _is_in_runfiles ( name , runfiles ): 22for file in runfiles : 23if file . basename == name : 24return True 25return False 26 27check_runfiles_test = analysistest . make ( _check_runfiles_test_impl ) 28 29def _check_runfiles_test (): 30rust_library ( 31name = "foo_lib" , 32srcs = [ "foo.rs" ], 33edition = "2018" , 34deps = [ ":libbar.so" ], 35) 36 37rust_binary ( 38name = "foo_bin" , 39srcs = [ "foo_main.rs" ], 40edition = "2018" , 41deps = [ ":libbar.so" ], 42) 43 44rust_shared_library ( 45name = "foo_dylib" , 46srcs = [ "foo.rs" ], 47edition = "2018" , 48deps = [ ":libbar.so" ], 49) 50 51rust_static_library ( 52name = "foo_static" , 53srcs = [ "foo.rs" ], 54edition = "2018" , 55deps = [ ":libbar.so" ], 56) 57 58# buildifier: disable=native-cc 59native . cc_binary ( 60name = "libbar.so" , 61srcs = [ "bar.cc" ], 62linkshared = True , 63) 64 65check_runfiles_test ( 66name = "check_runfiles_lib_test" , 67target_under_test = ":foo_lib" , 68) 69 70check_runfiles_test ( 71name = "check_runfiles_bin_test" , 72target_under_test = ":foo_bin" , 73) 74 75check_runfiles_test ( 76name = "check_runfiles_dylib_test" , 77target_under_test = ":foo_dylib" , 78) 79 80check_runfiles_test ( 81name = "check_runfiles_static_test" , 82target_under_test = ":foo_static" , 83) 84 85def check_runfiles_test_suite ( name ): 86"""Entry-point macro called from the BUILD file. 87 88Args: 89name: Name of the macro. 90""" 91_check_runfiles_test () 92 93native . test_suite ( 94name = name , 95tests = [ 96":check_runfiles_lib_test" , 97":check_runfiles_bin_test" , 98":check_runfiles_dylib_test" , 99":check_runfiles_static_test" , 100], 101)