Skip to content

Commit

Permalink
Add clippy tests for rust_shared_library, rust_static_library and rus…
Browse files Browse the repository at this point in the history
…t_proc_macro
  • Loading branch information
0xAda committed Feb 23, 2023
1 parent 9d04cfd commit 504546c
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 1 deletion.
82 changes: 81 additions & 1 deletion test/clippy/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
load("@rules_rust//rust:defs.bzl", "rust_binary", "rust_clippy", "rust_library", "rust_test")
load(
"@rules_rust//rust:defs.bzl",
"rust_binary",
"rust_clippy",
"rust_library",
"rust_proc_macro",
"rust_shared_library",
"rust_static_library",
"rust_test",
)

package(default_visibility = ["//test:__subpackages__"])

Expand All @@ -16,12 +25,30 @@ rust_library(
edition = "2018",
)

rust_shared_library(
name = "ok_shared_library",
srcs = ["src/lib.rs"],
edition = "2018",
)

rust_static_library(
name = "ok_static_library",
srcs = ["src/lib.rs"],
edition = "2018",
)

rust_test(
name = "ok_test",
srcs = ["src/lib.rs"],
edition = "2018",
)

rust_proc_macro(
name = "ok_proc_macro",
srcs = ["src/proc_macro.rs"],
edition = "2018",
)

# Clippy analysis of passing targets.

rust_clippy(
Expand All @@ -34,12 +61,27 @@ rust_clippy(
deps = [":ok_library"],
)

rust_clippy(
name = "ok_shared_library_clippy",
deps = [":ok_shared_library"],
)

rust_clippy(
name = "ok_static_library_clippy",
deps = [":ok_static_library"],
)

rust_clippy(
name = "ok_test_clippy",
testonly = True,
deps = [":ok_test"],
)

rust_clippy(
name = "ok_proc_macro_clippy",
deps = [":ok_proc_macro"],
)

# Declaration of failing targets.

rust_binary(
Expand All @@ -56,13 +98,33 @@ rust_library(
tags = ["noclippy"],
)

rust_library(
name = "bad_shared_library",
srcs = ["bad_src/lib.rs"],
edition = "2018",
tags = ["noclippy"],
)

rust_library(
name = "bad_static_library",
srcs = ["bad_src/lib.rs"],
edition = "2018",
tags = ["noclippy"],
)

rust_test(
name = "bad_test",
srcs = ["bad_src/lib.rs"],
edition = "2018",
tags = ["noclippy"],
)

rust_proc_macro(
name = "bad_proc_macro",
srcs = ["bad_src/proc_macro.rs"],
edition = "2018",
)

# Clippy analysis of failing targets.

rust_clippy(
Expand All @@ -77,13 +139,31 @@ rust_clippy(
deps = [":bad_library"],
)

rust_clippy(
name = "bad_shared_library_clippy",
tags = ["manual"],
deps = [":bad_shared_library"],
)

rust_clippy(
name = "bad_static_library_clippy",
tags = ["manual"],
deps = [":bad_static_library"],
)

rust_clippy(
name = "bad_test_clippy",
testonly = True,
tags = ["manual"],
deps = [":bad_test"],
)

rust_clippy(
name = "bad_proc_macro_clippy",
tags = ["manual"],
deps = [":bad_proc_macro"],
)

sh_binary(
name = "clippy_failure_test",
srcs = ["clippy_failure_test.sh"],
Expand Down
11 changes: 11 additions & 0 deletions test/clippy/bad_src/proc_macro.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
extern crate proc_macro;
use proc_macro::TokenStream;

#[proc_macro]
pub fn make_answer(_item: TokenStream) -> TokenStream { assert!(true);
loop {
println!("{}", "Hello World");
break;
}
"fn answer() -> u32 { 42 }".parse().unwrap()
}
9 changes: 9 additions & 0 deletions test/clippy/clippy_failure_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,25 @@ EOF

check_build_result $BUILD_OK ok_binary_clippy
check_build_result $BUILD_OK ok_library_clippy
check_build_result $BUILD_OK ok_shared_library_clippy
check_build_result $BUILD_OK ok_static_library_clippy
check_build_result $BUILD_OK ok_test_clippy
check_build_result $BUILD_OK ok_proc_macro_clippy
check_build_result $BUILD_FAILED bad_binary_clippy
check_build_result $BUILD_FAILED bad_library_clippy
check_build_result $BUILD_FAILED bad_shared_library_clippy
check_build_result $BUILD_FAILED bad_static_library_clippy
check_build_result $BUILD_FAILED bad_test_clippy
check_build_result $BUILD_FAILED bad_proc_macro_clippy

# When capturing output, clippy errors are treated as warnings and the build
# should succeed.
check_build_result $BUILD_OK bad_binary_clippy $CAPTURE_OUTPUT
check_build_result $BUILD_OK bad_library_clippy $CAPTURE_OUTPUT
check_build_result $BUILD_OK bad_shared_library_clippy $CAPTURE_OUTPUT
check_build_result $BUILD_OK bad_static_library_clippy $CAPTURE_OUTPUT
check_build_result $BUILD_OK bad_test_clippy $CAPTURE_OUTPUT
check_build_result $BUILD_OK bad_proc_macro_clippy $CAPTURE_OUTPUT

# Test that we can make the ok_library_clippy fail when using an extra config file.
# Proves that the config file is used and overrides default settings.
Expand Down
7 changes: 7 additions & 0 deletions test/clippy/src/proc_macro.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
extern crate proc_macro;
use proc_macro::TokenStream;

#[proc_macro]
pub fn make_answer(_item: TokenStream) -> TokenStream {
"fn answer() -> u32 { 42 }".parse().unwrap()
}

0 comments on commit 504546c

Please sign in to comment.