Skip to content

Commit

Permalink
chore: run clippy against all targets (#546)
Browse files Browse the repository at this point in the history
This would help us to check if there are any
clippy warning in the tests.
  • Loading branch information
Rustin170506 authored Apr 22, 2024
1 parent 4d91f5d commit 3193fde
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ jobs:
run: cargo fmt --all -- --check

- name: Run cargo clippy
run: cargo clippy -- -D warnings
run: cargo clippy --workspace --all-targets --no-deps -- -D warnings

grpc_web:
name: gRPC-web Example
Expand Down
3 changes: 1 addition & 2 deletions console-subscriber/examples/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ async fn no_yield(seconds: u64) {
#[tracing::instrument]
async fn spawn_blocking(seconds: u64) {
loop {
let seconds = seconds;
_ = tokio::task::spawn_blocking(move || {
std::thread::sleep(Duration::from_secs(seconds));
})
Expand All @@ -165,7 +164,7 @@ fn self_wake() -> impl Future<Output = ()> {
mut self: std::pin::Pin<&mut Self>,
cx: &mut std::task::Context<'_>,
) -> Poll<Self::Output> {
if self.yielded == true {
if self.yielded {
return Poll::Ready(());
}

Expand Down
3 changes: 3 additions & 0 deletions console-subscriber/tests/spawn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ use support::{assert_tasks, spawn_named, ExpectedTask};
/// spawned the child task). In this scenario, that would result in the parent
/// having 3 polls counted, when it should really be 1.
#[test]
// The child task is polled explicitly to control its execution.
// As a result, the clippy warning is ignored.
#[allow(clippy::async_yields_async)]
fn child_polls_dont_count_towards_parent_polls() {
let expected_tasks = vec![
ExpectedTask::default()
Expand Down
4 changes: 2 additions & 2 deletions console-subscriber/tests/support/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ where
tokio::task::Builder::new()
.name(name)
.spawn(f)
.expect(&format!("spawning task '{name}' failed"))
.unwrap_or_else(|_| panic!("spawning task '{name}' failed"))
}

/// Wakes itself from within this task.
Expand Down Expand Up @@ -91,7 +91,7 @@ pub(crate) fn self_wake() -> impl Future<Output = ()> {
mut self: std::pin::Pin<&mut Self>,
cx: &mut std::task::Context<'_>,
) -> Poll<Self::Output> {
if self.yielded == true {
if self.yielded {
return Poll::Ready(());
}

Expand Down
7 changes: 4 additions & 3 deletions console-subscriber/tests/support/subscriber.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ struct TestFailure {

impl fmt::Display for TestFailure {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "Task validation failed:\n")?;
writeln!(f, "Task validation failed:")?;
for failure in &self.failures {
write!(f, " - {failure}\n")?;
writeln!(f, " - {failure}")?;
}
Ok(())
}
Expand Down Expand Up @@ -318,10 +318,11 @@ fn validate_expected_tasks(
if failures.is_empty() {
Ok(())
} else {
Err(TestFailure { failures: failures })
Err(TestFailure { failures })
}
}

#[allow(clippy::result_large_err)]
fn validate_expected_task(
expected: &ExpectedTask,
actual_tasks: &Vec<ActualTask>,
Expand Down
15 changes: 2 additions & 13 deletions console-subscriber/tests/support/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ impl fmt::Debug for TaskValidationFailure {
/// This struct contains the fields that an expected task will attempt to match
/// actual tasks on, as well as the expectations that will be used to validate
/// which the actual task is as expected.
#[derive(Clone, Debug)]
#[derive(Clone, Debug, Default)]
pub(crate) struct ExpectedTask {
match_name: Option<String>,
expect_present: Option<bool>,
Expand All @@ -93,18 +93,7 @@ pub(crate) struct ExpectedTask {
expect_polls: Option<u64>,
}

impl Default for ExpectedTask {
fn default() -> Self {
Self {
match_name: None,
expect_present: None,
expect_wakes: None,
expect_self_wakes: None,
expect_polls: None,
}
}
}

#[allow(clippy::result_large_err)]
impl ExpectedTask {
/// Returns whether or not an actual task matches this expected task.
///
Expand Down
2 changes: 0 additions & 2 deletions console-subscriber/tests/wake.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
mod support;
use std::time::Duration;

use support::{assert_task, ExpectedTask};
use tokio::time::sleep;

#[test]
fn self_wake() {
Expand Down

0 comments on commit 3193fde

Please sign in to comment.