fork/rules_rust
git clone https://git.julia.blue/fork/rules_rust
ce1b842c
main
1"""Test definitions for rustfmt test rules""" 2 3load ( 4"@rules_rust//rust:defs.bzl" , 5"rust_binary" , 6"rust_library" , 7"rust_shared_library" , 8"rust_static_library" , 9"rustfmt_test" , 10) 11 12_VARIANTS = { 13"rust_binary" : rust_binary , 14"rust_library" : rust_library , 15"rust_shared_library" : rust_shared_library , 16"rust_static_library" : rust_static_library , 17} 18 19def rustfmt_integration_test_suite ( name , ** kwargs ): 20"""Generate a test suite for rustfmt integration tests. 21 22Targets generated are expected to be executed using a target 23named: `{name}.test_runner` 24 25Args: 26name (str): The name of the test suite 27**kwargs (dict): Additional keyword arguments for the underlying test_suite. 28""" 29 30tests = [] 31for variant , rust_rule in _VARIANTS . items (): 32# 33# Test edition 2018 34# 35rust_rule ( 36name = "{}_formatted_2018" . format ( variant ), 37srcs = [ "srcs/2018/formatted.rs" ], 38edition = "2018" , 39) 40 41rustfmt_test ( 42name = "{}_formatted_2018_test" . format ( variant ), 43targets = [ ":{}_formatted_2018" . format ( variant )], 44) 45 46rust_rule ( 47name = "{}_unformatted_2018" . format ( variant ), 48srcs = [ "srcs/2018/unformatted.rs" ], 49edition = "2018" , 50tags = [ "norustfmt" ], 51) 52 53rustfmt_test ( 54name = "{}_unformatted_2018_test" . format ( variant ), 55tags = [ "manual" ], 56targets = [ ":{}_unformatted_2018" . format ( variant )], 57) 58 59# 60# Test edition 2015 61# 62rust_rule ( 63name = "{}_formatted_2015" . format ( variant ), 64srcs = [ "srcs/2015/formatted.rs" ], 65edition = "2015" , 66) 67 68rustfmt_test ( 69name = "{}_formatted_2015_test" . format ( variant ), 70targets = [ ":{}_formatted_2015" . format ( variant )], 71) 72 73rust_rule ( 74name = "{}_unformatted_2015" . format ( variant ), 75srcs = [ "srcs/2015/unformatted.rs" ], 76edition = "2015" , 77tags = [ "norustfmt" ], 78) 79 80rustfmt_test ( 81name = "{}_unformatted_2015_test" . format ( variant ), 82tags = [ "manual" ], 83targets = [ ":{}_unformatted_2015" . format ( variant )], 84) 85 86# 87# Test targets with generated sources 88# 89rust_rule ( 90name = "{}_generated" . format ( variant ), 91srcs = [ 92"srcs/generated/lib.rs" , 93"srcs/generated/generated.rs" , 94], 95crate_root = "srcs/generated/lib.rs" , 96edition = "2021" , 97) 98 99rustfmt_test ( 100name = "{}_generated_test" . format ( variant ), 101targets = [ ":{}_generated" . format ( variant )], 102) 103 104tests . extend ([ 105"{}_formatted_2015_test" . format ( variant ), 106"{}_formatted_2018_test" . format ( variant ), 107"{}_unformatted_2015_test" . format ( variant ), 108"{}_unformatted_2018_test" . format ( variant ), 109"{}_generated_test" . format ( variant ), 110]) 111 112native . test_suite ( 113name = name , 114tests = tests , 115** kwargs 116) 117 118native . sh_binary ( 119name = "{}.test_runner" . format ( name ), 120srcs = [ "rustfmt_failure_test.sh" ], 121testonly = True , 122)