Skip to content

Commit

Permalink
ci: Enable the --all-targets flag for tests, check, and clippy
Browse files Browse the repository at this point in the history
Fix clippy lints for these example targets & test code.
  • Loading branch information
Techcable committed Sep 5, 2023
1 parent 6a9ce75 commit 9cbde0f
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 27 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,12 @@ jobs:
- name: Check
# A failing `cargo check` always ends the build
run: |
cargo check --verbose --features "${{ matrix.features }}"
cargo check --all-targets --verbose --features "${{ matrix.features }}"
# A failing `cargo check` always fails the build
continue-on-error: false
- name: Test
run: |
cargo test --verbose --features "${{ matrix.features }}"
cargo test --all-targets --verbose --features "${{ matrix.features }}"
# We only require tests to succeed on the default feature combinations.
#
Expand All @@ -85,7 +85,7 @@ jobs:
- name: Clippy
# With the exception of nightly, we use --deny warnings to treat warnings on errors.
run: |
cargo clippy --verbose --features "${{ matrix.features }}" --deny "${{ matrix.rust != 'nightly' && 'warnings' || 'clippy::correctness' }}"
cargo clippy --all-targets --verbose --features "${{ matrix.features }}" --deny "${{ matrix.rust != 'nightly' && 'warnings' || 'clippy::correctness' }}"
# Clippy is required to succeed on hardcoded versions, and not give any warnings
#
# However, on automatically updated versions of rust (both stable & nightly) we allow clippy to fail.
Expand Down
2 changes: 1 addition & 1 deletion examples/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ impl Drain for PrintlnDrain {
.unwrap();
values.serialize(record, &mut PrintlnSerializer).unwrap();

println!("");
println!();
Ok(())
}
}
9 changes: 3 additions & 6 deletions examples/struct-log-self.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@ struct Peer {

impl Peer {
fn new(host: String, port: u32) -> Self {
Peer {
host: host,
port: port,
}
Peer { host, port }
}
}

Expand Down Expand Up @@ -47,7 +44,7 @@ impl Server {
Server {
_host: host,
_port: port,
log: log,
log,
}
}

Expand All @@ -66,7 +63,7 @@ struct PeerCounter {

impl PeerCounter {
fn new(log: Logger) -> Self {
PeerCounter { count: 0, log: log }
PeerCounter { count: 0, log }
}

// A hybrid approach with `Logger` with parent logging-context embedded into
Expand Down
20 changes: 12 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1297,6 +1297,11 @@ where
record: &Record<'_>,
values: &OwnedKVList,
) -> result::Result<Self::Ok, Self::Err> {
// Arc is required by API, but logically redundant
#[cfg_attr(
feature = "nothreads",
allow(clippy::arc_with_non_send_sync)
)]
let chained = OwnedKVList {
node: Arc::new(MultiListNode {
next_node: values.node.clone(),
Expand Down Expand Up @@ -2427,10 +2432,9 @@ where
{
let string = expected.to_string();

let actual = T::from_str(&string).expect(&format!(
"Failed to parse string representation of {:?}",
expected
));
let actual = T::from_str(&string).unwrap_or_else(|_err| {
panic!("Failed to parse string representation of {:?}", expected)
});

assert_eq!(
expected, actual,
Expand All @@ -2441,10 +2445,10 @@ where

#[test]
fn filter_level_accepts_tests() {
assert_eq!(true, FilterLevel::Warning.accepts(Level::Error));
assert_eq!(true, FilterLevel::Warning.accepts(Level::Warning));
assert_eq!(false, FilterLevel::Warning.accepts(Level::Info));
assert_eq!(false, FilterLevel::Off.accepts(Level::Critical));
assert!(FilterLevel::Warning.accepts(Level::Error));
assert!(FilterLevel::Warning.accepts(Level::Warning));
assert!(!FilterLevel::Warning.accepts(Level::Info));
assert!(!FilterLevel::Off.accepts(Level::Critical));
}
// }}}

Expand Down
27 changes: 18 additions & 9 deletions src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ mod no_imports {
#[cfg(feature = "std")]
mod std_only {
use super::super::*;
use std;

#[derive(Clone)]
struct CheckError;
Expand Down Expand Up @@ -204,7 +203,7 @@ fn expressions() {
let log = Logger::root(Discard, o!("version" => env!("CARGO_PKG_VERSION")));

let foo = Foo;
let r = X { foo: foo };
let r = X { foo };

warn!(log, "logging message");
slog_warn!(log, "logging message");
Expand Down Expand Up @@ -300,13 +299,17 @@ fn expressions() {
info!(log, "message"; "foo" => "bar", &x, &x, "aaa" => "bbb");
}

info!(
log,
"message {}",
{ 3 + 3; 2};
"foo" => "bar",
"foo" => { 3 + 3; 2},
"aaa" => "bbb");
#[allow(clippy::no_effect)]
{
info!(
log,
"message {}",
{ 3 + 3; 2};
"foo" => "bar",
"foo" => { 3 + 3; 2},
"aaa" => "bbb"
);
}
}

#[cfg(integer128)]
Expand Down Expand Up @@ -446,6 +449,7 @@ fn logger_by_ref() {
#[allow(unreachable_code, unused_variables)]
fn test_never_type_clone() {
// We just want to make sure that this compiles
#[allow(clippy::diverging_sub_expression)]
fn _do_not_run() {
let x: Never = panic!("Can't actually construct a Never type here!");
let y = x.clone();
Expand All @@ -458,5 +462,10 @@ fn test_never_type_clone() {
fn can_hash_keys() {
use crate::Key;
use std::collections::HashSet;
// NOTE: Need conversion to support dynamic-keys
#[cfg_attr(
not(feature = "dynamic-keys"),
allow(clippy::useless_conversion)
)]
let _tab: HashSet<Key> = ["foo"].iter().map(|&k| k.into()).collect();
}

0 comments on commit 9cbde0f

Please sign in to comment.