fork/rules_rust
git clone https://git.julia.blue/fork/rules_rust
49906eb2
rust-analyzer
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 (): 32rust_rule ( 33name = "{}_formatted_2018" . format ( variant ), 34srcs = [ "srcs/2018/formatted.rs" ], 35edition = "2018" , 36) 37 38rustfmt_test ( 39name = "{}_formatted_2018_test" . format ( variant ), 40targets = [ ":{}_formatted_2018" . format ( variant )], 41) 42 43rust_rule ( 44name = "{}_unformatted_2018" . format ( variant ), 45srcs = [ "srcs/2018/unformatted.rs" ], 46edition = "2018" , 47tags = [ "norustfmt" ], 48) 49 50rustfmt_test ( 51name = "{}_unformatted_2018_test" . format ( variant ), 52tags = [ "manual" ], 53targets = [ ":{}_unformatted_2018" . format ( variant )], 54) 55 56rust_rule ( 57name = "{}_formatted_2015" . format ( variant ), 58srcs = [ "srcs/2015/formatted.rs" ], 59edition = "2015" , 60) 61 62rustfmt_test ( 63name = "{}_formatted_2015_test" . format ( variant ), 64targets = [ ":{}_formatted_2015" . format ( variant )], 65) 66 67rust_rule ( 68name = "{}_unformatted_2015" . format ( variant ), 69srcs = [ "srcs/2015/unformatted.rs" ], 70edition = "2015" , 71tags = [ "norustfmt" ], 72) 73 74rustfmt_test ( 75name = "{}_unformatted_2015_test" . format ( variant ), 76tags = [ "manual" ], 77targets = [ ":{}_unformatted_2015" . format ( variant )], 78) 79 80tests . extend ([ 81"{}_formatted_2015_test" . format ( variant ), 82"{}_formatted_2018_test" . format ( variant ), 83"{}_unformatted_2015_test" . format ( variant ), 84"{}_unformatted_2018_test" . format ( variant ), 85]) 86 87native . test_suite ( 88name = name , 89tests = tests , 90** kwargs 91) 92 93native . sh_binary ( 94name = "{}.test_runner" . format ( name ), 95srcs = [ "rustfmt_failure_test.sh" ], 96)