Skip to content

Commit

Permalink
Run clippy --all-targets and fix lints.
Browse files Browse the repository at this point in the history
  • Loading branch information
nfachan committed Jan 17, 2024
1 parent efd3a26 commit d98721d
Show file tree
Hide file tree
Showing 9 changed files with 81 additions and 102 deletions.
98 changes: 40 additions & 58 deletions crates/cargo-maelstrom/src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,24 +260,18 @@ mod test {
"#,
)
.unwrap();
assert_eq!(
all.get_metadata_for_test(&test_ctx("package1", "test1"), empty_env, no_containers)
.unwrap()
.include_shared_libraries(),
true
);
assert_eq!(
all.get_metadata_for_test(&test_ctx("package1", "test2"), empty_env, no_containers)
.unwrap()
.include_shared_libraries(),
false
);
assert_eq!(
all.get_metadata_for_test(&test_ctx("package2", "test1"), empty_env, no_containers)
.unwrap()
.include_shared_libraries(),
true
);
assert!(all
.get_metadata_for_test(&test_ctx("package1", "test1"), empty_env, no_containers)
.unwrap()
.include_shared_libraries());
assert!(!all
.get_metadata_for_test(&test_ctx("package1", "test2"), empty_env, no_containers)
.unwrap()
.include_shared_libraries());
assert!(all
.get_metadata_for_test(&test_ctx("package2", "test1"), empty_env, no_containers)
.unwrap()
.include_shared_libraries());
}

#[test]
Expand All @@ -298,24 +292,18 @@ mod test {
"#,
)
.unwrap();
assert_eq!(
all.get_metadata_for_test(&test_ctx("package1", "test1"), empty_env, no_containers)
.unwrap()
.include_shared_libraries(),
true
);
assert_eq!(
all.get_metadata_for_test(&test_ctx("package1", "test2"), empty_env, no_containers)
.unwrap()
.include_shared_libraries(),
true
);
assert_eq!(
all.get_metadata_for_test(&test_ctx("package2", "test1"), empty_env, no_containers)
.unwrap()
.include_shared_libraries(),
false
);
assert!(all
.get_metadata_for_test(&test_ctx("package1", "test1"), empty_env, no_containers)
.unwrap()
.include_shared_libraries());
assert!(all
.get_metadata_for_test(&test_ctx("package1", "test2"), empty_env, no_containers)
.unwrap()
.include_shared_libraries());
assert!(!all
.get_metadata_for_test(&test_ctx("package2", "test1"), empty_env, no_containers)
.unwrap()
.include_shared_libraries());
}

#[test]
Expand All @@ -332,23 +320,20 @@ mod test {
"#,
)
.unwrap();
assert_eq!(
all.get_metadata_for_test(&test_ctx("package1", "test1"), empty_env, no_containers)
assert!(
!all.get_metadata_for_test(&test_ctx("package1", "test1"), empty_env, no_containers)
.unwrap()
.enable_loopback,
false
.enable_loopback
);
assert_eq!(
assert!(
all.get_metadata_for_test(&test_ctx("package1", "test2"), empty_env, no_containers)
.unwrap()
.enable_loopback,
true
.enable_loopback
);
assert_eq!(
all.get_metadata_for_test(&test_ctx("package2", "test1"), empty_env, no_containers)
assert!(
!all.get_metadata_for_test(&test_ctx("package2", "test1"), empty_env, no_containers)
.unwrap()
.enable_loopback,
false
.enable_loopback
);
}

Expand All @@ -366,23 +351,20 @@ mod test {
"#,
)
.unwrap();
assert_eq!(
all.get_metadata_for_test(&test_ctx("package1", "test1"), empty_env, no_containers)
assert!(
!all.get_metadata_for_test(&test_ctx("package1", "test1"), empty_env, no_containers)
.unwrap()
.enable_writable_file_system,
false
.enable_writable_file_system
);
assert_eq!(
assert!(
all.get_metadata_for_test(&test_ctx("package1", "test2"), empty_env, no_containers)
.unwrap()
.enable_writable_file_system,
true
.enable_writable_file_system
);
assert_eq!(
all.get_metadata_for_test(&test_ctx("package2", "test1"), empty_env, no_containers)
assert!(
!all.get_metadata_for_test(&test_ctx("package2", "test1"), empty_env, no_containers)
.unwrap()
.enable_writable_file_system,
false
.enable_writable_file_system
);
}

Expand Down
13 changes: 5 additions & 8 deletions crates/cargo-maelstrom/src/pattern/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ fn matcher_parameter_test() {
test_it("((a)(b))", "(a)(b)");

fn test_err(a: &str) {
assert!(matches!(parse_str!(MatcherParameter, a), Err(_)));
assert!(parse_str!(MatcherParameter, a).is_err());
}
test_err("[1)");
test_err("(((hello))");
Expand Down Expand Up @@ -621,13 +621,10 @@ fn pattern_longer_boolean_expr() {
"all || any || none",
OrExpression::Or(
SimpleSelectorName::All.into(),
Box::new(
OrExpression::Or(
SimpleSelectorName::Any.into(),
Box::new(SimpleSelectorName::None.into()),
)
.into(),
),
Box::new(OrExpression::Or(
SimpleSelectorName::Any.into(),
Box::new(SimpleSelectorName::None.into()),
)),
),
);
test_it(
Expand Down
41 changes: 19 additions & 22 deletions crates/cargo-maelstrom/tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ fn generate_cargo_project(tmp_dir: &TempDir, fake_tests: &FakeTests) -> String {
fs.create_dir(&crates_dir).unwrap();
for binary in &fake_tests.test_binaries {
let crate_name = &binary.name;
let project_dir = crates_dir.join(&crate_name);
let project_dir = crates_dir.join(crate_name);
fs.create_dir(&project_dir).unwrap();
put_file(
&fs,
Expand Down Expand Up @@ -144,18 +144,17 @@ fn test_path(spec: &JobSpec) -> TestPath {
let binary = spec
.program
.as_str()
.split("/")
.split('/')
.last()
.unwrap()
.split("-")
.split('-')
.next()
.unwrap()
.into();
let test_name = spec
.arguments
.iter()
.filter(|a| !a.starts_with("-"))
.next()
.find(|a| !a.starts_with('-'))
.unwrap()
.clone();
TestPath { binary, test_name }
Expand Down Expand Up @@ -217,7 +216,7 @@ impl FakeBrokerConnection {
}
ClientToBroker::JobStateCountsRequest => send_message(
&self.messages.stream,
&BrokerToClient::JobStateCountsResponse(self.state.job_states.clone()),
&BrokerToClient::JobStateCountsResponse(self.state.job_states),
),

_ => (),
Expand Down Expand Up @@ -304,22 +303,17 @@ struct TestPath {

impl FakeTests {
fn all_test_paths(&self) -> impl Iterator<Item = (&FakeTestCase, TestPath)> + '_ {
self.test_binaries
.iter()
.map(|b| {
b.tests.iter().filter_map(|t| {
(!t.ignored).then(|| {
(
t,
TestPath {
binary: b.name.clone(),
test_name: t.name.clone(),
},
)
})
})
self.test_binaries.iter().flat_map(|b| {
b.tests.iter().filter(|&t| !t.ignored).map(|t| {
(
t,
TestPath {
binary: b.name.clone(),
test_name: t.name.clone(),
},
)
})
.flatten()
})
}

fn get(&self, package_name: &str, case: &str) -> &FakeTestCase {
Expand Down Expand Up @@ -367,6 +361,7 @@ impl TestClientDriver {

#[derive(Default, Clone)]
struct TestProgressDriver<'scope> {
#[allow(clippy::type_complexity)]
update_func: Rc<RefCell<Option<Box<dyn FnMut(JobStateCounts) -> Result<bool> + 'scope>>>>,
}

Expand All @@ -393,6 +388,7 @@ impl<'scope> TestProgressDriver<'scope> {
}
}

#[allow(clippy::too_many_arguments)]
fn run_app(
term: InMemoryTerm,
fake_tests: FakeTests,
Expand Down Expand Up @@ -424,7 +420,7 @@ fn run_app(
false, // stderr_color
&workspace_root,
&cargo_metadata.workspace_packages(),
b.address.clone(),
b.address,
client_driver.clone(),
)
.unwrap();
Expand Down Expand Up @@ -534,6 +530,7 @@ fn run_all_tests_sync(
)
}

#[allow(clippy::too_many_arguments)]
fn list_all_tests_sync(
tmp_dir: &TempDir,
fake_tests: FakeTests,
Expand Down
18 changes: 10 additions & 8 deletions crates/maelstrom-broker/src/scheduler_task/scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ mod tests {
use maelstrom_base::proto::BrokerToWorker::{self, *};
use maelstrom_test::*;
use maplit::hashmap;
use std::{cell::RefCell, sync::Arc};
use std::{cell::RefCell, rc::Rc};

#[derive(Clone, Debug, PartialEq)]
enum TestMessage {
Expand All @@ -633,11 +633,12 @@ mod tests {
messages: Vec<TestMessage>,
get_artifact_returns: HashMap<(JobId, Sha256Digest), Vec<GetArtifact>>,
got_artifact_returns: HashMap<Sha256Digest, Vec<Vec<JobId>>>,
#[allow(clippy::type_complexity)]
get_artifact_for_worker_returns:
HashMap<Sha256Digest, Vec<Result<(PathBuf, u64), GetArtifactForWorkerError>>>,
}

impl SchedulerCache for Arc<RefCell<TestState>> {
impl SchedulerCache for Rc<RefCell<TestState>> {
fn get_artifact(&mut self, jid: JobId, digest: Sha256Digest) -> GetArtifact {
self.borrow_mut()
.messages
Expand Down Expand Up @@ -684,13 +685,13 @@ mod tests {
.push(CacheGetArtifactForWorker(digest.clone()));
self.borrow_mut()
.get_artifact_for_worker_returns
.get_mut(&digest)
.get_mut(digest)
.unwrap()
.remove(0)
}
}

impl SchedulerDeps for Arc<RefCell<TestState>> {
impl SchedulerDeps for Rc<RefCell<TestState>> {
type ClientSender = TestClientSender;
type WorkerSender = TestWorkerSender;
type WorkerArtifactFetcherSender = TestWorkerArtifactFetcherSender;
Expand Down Expand Up @@ -723,13 +724,13 @@ mod tests {
}

struct Fixture {
test_state: Arc<RefCell<TestState>>,
scheduler: Scheduler<Arc<RefCell<TestState>>, Arc<RefCell<TestState>>>,
test_state: Rc<RefCell<TestState>>,
scheduler: Scheduler<Rc<RefCell<TestState>>, Rc<RefCell<TestState>>>,
}

impl Default for Fixture {
fn default() -> Self {
let test_state = Arc::new(RefCell::new(TestState::default()));
let test_state = Rc::new(RefCell::new(TestState::default()));
Fixture {
test_state: test_state.clone(),
scheduler: Scheduler::new(test_state),
Expand All @@ -738,6 +739,7 @@ mod tests {
}

impl Fixture {
#[allow(clippy::type_complexity)]
fn new<const L: usize, const M: usize, const N: usize>(
get_artifact_returns: [((JobId, Sha256Digest), Vec<GetArtifact>); L],
got_artifact_returns: [(Sha256Digest, Vec<Vec<JobId>>); M],
Expand Down Expand Up @@ -772,7 +774,7 @@ mod tests {
);
}

fn receive_message(&mut self, msg: Message<Arc<RefCell<TestState>>>) {
fn receive_message(&mut self, msg: Message<Rc<RefCell<TestState>>>) {
self.scheduler.receive_message(&mut self.test_state, msg);
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/maelstrom-client/src/spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ mod test {
fn std_env_lookup_error() {
let var = "AN_ENVIRONMENT_VARIABLE_2";
let val = unsafe { std::ffi::OsString::from_encoded_bytes_unchecked(vec![0xff]) };
env::set_var(var, &val);
env::set_var(var, val);
assert_eq!(
format!("{}", std_env_lookup(var).unwrap_err()),
r#"environment variable was not valid unicode: "\xFF""#
Expand Down
3 changes: 2 additions & 1 deletion crates/maelstrom-container/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ fn sorted_dir_listing(fs: &Fs, path: impl AsRef<Path>) -> Vec<String> {
.unwrap()
.into()
})
.filter(|n: &String| !n.starts_with("."))
.filter(|n: &String| !n.starts_with('.'))
.collect();
listing.sort();
listing
Expand Down Expand Up @@ -685,6 +685,7 @@ fn container_image_depot_update_image() {
}),
)
.unwrap();
#[allow(clippy::disallowed_names)]
let foo = depot
.get_container_image("foo", "latest", ProgressBar::hidden())
.unwrap();
Expand Down
2 changes: 1 addition & 1 deletion crates/maelstrom-util/src/heap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ mod tests {
impl Fixture {
fn validate_indices(&self) {
for (idx, id) in self.heap.0.iter().enumerate() {
assert_eq!(self.elements.get(&id).unwrap().heap_index, HeapIndex(idx));
assert_eq!(self.elements.get(id).unwrap().heap_index, HeapIndex(idx));
}
}

Expand Down
4 changes: 2 additions & 2 deletions crates/maelstrom-worker/src/dispatcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ mod tests {
.push(CacheGotArtifactFailure(digest.clone()));
self.borrow_mut()
.got_artifact_failure_returns
.remove(&digest)
.remove(digest)
.unwrap()
}

Expand All @@ -501,7 +501,7 @@ mod tests {
.push(CacheGotArtifactSuccess(digest.clone(), bytes_used));
self.borrow_mut()
.got_artifact_success_returns
.remove(&digest)
.remove(digest)
.unwrap()
}

Expand Down
Loading

0 comments on commit d98721d

Please sign in to comment.