-
Notifications
You must be signed in to change notification settings - Fork 131
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add nativelink_test macro for tests (#888)
This macro is to replace the tokio::test macro. It will allow us to do some setup & cleanup on all tests without burdening the dev with wrappers.
- Loading branch information
Showing
46 changed files
with
442 additions
and
301 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
load( | ||
"@rules_rust//rust:defs.bzl", | ||
"rust_doc", | ||
"rust_proc_macro", | ||
) | ||
|
||
rust_proc_macro( | ||
name = "nativelink-macro", | ||
srcs = [ | ||
"src/lib.rs", | ||
], | ||
visibility = ["//visibility:public"], | ||
deps = [ | ||
"@crates//:proc-macro2", | ||
"@crates//:quote", | ||
"@crates//:syn", | ||
], | ||
) | ||
|
||
rust_doc( | ||
name = "docs", | ||
crate = ":nativelink-macro", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
[package] | ||
name = "nativelink-macro" | ||
version = "0.3.0" | ||
edition = "2021" | ||
|
||
[lib] | ||
crate_type = ["proc-macro"] | ||
|
||
[dependencies] | ||
# TODO(allada) We currently need to pin these to specific version. | ||
# Some down-stream can't be upgraded just yet. | ||
proc-macro2 = "=1.0.78" | ||
quote = "=1.0.35" | ||
syn = "=2.0.52" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Copyright 2024 The NativeLink Authors. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
extern crate proc_macro; | ||
|
||
use proc_macro::TokenStream; | ||
use quote::quote; | ||
use syn::{parse_macro_input, ItemFn}; | ||
|
||
#[proc_macro_attribute] | ||
pub fn nativelink_test(attr: TokenStream, item: TokenStream) -> TokenStream { | ||
let attr = proc_macro2::TokenStream::from(attr); | ||
let input_fn = parse_macro_input!(item as ItemFn); | ||
|
||
let fn_name = &input_fn.sig.ident; | ||
let fn_block = &input_fn.block; | ||
let fn_inputs = &input_fn.sig.inputs; | ||
let fn_output = &input_fn.sig.output; | ||
let fn_attr = &input_fn.attrs; | ||
|
||
let expanded = quote! { | ||
#(#fn_attr)* | ||
#[tokio::test(#attr)] | ||
async fn #fn_name(#fn_inputs) #fn_output { | ||
#fn_block | ||
} | ||
}; | ||
|
||
TokenStream::from(expanded) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.