Skip to content

Commit

Permalink
🐳 chore: Makes clippy happy
Browse files Browse the repository at this point in the history
  • Loading branch information
wychlw committed Sep 18, 2024
1 parent 1b05c95 commit c707771
Show file tree
Hide file tree
Showing 12 changed files with 90 additions and 147 deletions.
26 changes: 7 additions & 19 deletions src/devhost/sdwirec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,7 @@ impl Sdwirec {
cmd += &self.format_device(chooser);
cmd += "-u";

let res = self.try_run(&cmd);
if let Err(e) = res {
return Err(e);
}
let res = res.unwrap();
let res = self.try_run(&cmd)?;
if !res.status.success() {
return Err(Box::new(std::io::Error::new(
std::io::ErrorKind::Other,
Expand All @@ -96,14 +92,14 @@ impl Sdwirec {
*/
let res = String::from_utf8(res.stdout).unwrap();
if res.contains("SD connected to: TS") {
return Ok(SdwirecStat::TS);
Ok(SdwirecStat::TS)
} else if res.contains("SD connected to: DUT") {
return Ok(SdwirecStat::DUT);
Ok(SdwirecStat::DUT)
} else {
return Err(Box::new(std::io::Error::new(
Err(Box::new(std::io::Error::new(
std::io::ErrorKind::Other,
format!("Failed to get status of device. Reason: {}", res),
)));
)))
}
}

Expand All @@ -116,11 +112,7 @@ impl Sdwirec {
cmd += &self.format_device(chooser);
cmd += "-ts";

let res = self.try_run(&cmd);
if let Err(e) = res {
return Err(e);
}
let res = res.unwrap();
let res = self.try_run(&cmd)?;
if !res.status.success() {
return Err(Box::new(std::io::Error::new(
std::io::ErrorKind::Other,
Expand All @@ -143,11 +135,7 @@ impl Sdwirec {
cmd += &self.format_device(chooser);
cmd += "-d";

let res = self.try_run(&cmd);
if let Err(e) = res {
return Err(e);
}
let res = res.unwrap();
let res = self.try_run(&cmd)?;
if !res.status.success() {
return Err(Box::new(std::io::Error::new(
std::io::ErrorKind::Other,
Expand Down
30 changes: 8 additions & 22 deletions src/exec/cli_exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,7 @@ impl CliTester {
impl CliTester {
fn run_command(&mut self, command: &String) -> Result<(), Box<dyn Error>> {
info!("Write to shell: {}", command);
let res = self.inner.write(command.as_bytes());
if let Err(e) = res {
return Err(e);
}
Ok(())
self.inner.write(command.as_bytes())
}
}

Expand Down Expand Up @@ -81,12 +77,8 @@ impl CliTestApi for CliTester {
info!("Waiting for string {{{}}}", expected);
loop {
sleep(Duration::from_millis(DURATION));
let res = self.inner.read();
if let Err(e) = res {
return Err(e);
}
let line = res.unwrap();
buf.extend_from_slice(&line);
let res = self.inner.read()?;
buf.extend_from_slice(&res);
let content = String::from_utf8(buf.clone()).unwrap_or_default();
if content.contains(expected) {
info!("Matched string {{{}}}", expected);
Expand All @@ -112,10 +104,7 @@ impl CliTestApi for CliTester {
cmd += &echo_content_rand;
cmd += " \n";

let res = self.run_command(&cmd);
if let Err(e) = res {
return Err(e);
}
self.run_command(&cmd)?;

let res = self.wait_serial(&echo_content_rand, timeout);
if let Err(e) = res {
Expand All @@ -124,7 +113,7 @@ impl CliTestApi for CliTester {
}
return Err(e);
}
res
Ok(())
}
fn assert_script_run(&mut self, script: &str, timeout: u32) -> Result<(), Box<dyn Error>> {
let mut cmd = script.to_owned();
Expand All @@ -134,13 +123,10 @@ impl CliTestApi for CliTester {
cmd += &echo_content_rand;
cmd += " \n";

let res = self.run_command(&cmd);
if let Err(e) = res {
return Err(e);
}
self.run_command(&cmd)?;

let res = self.wait_serial(&echo_content_rand, timeout);
res
self.wait_serial(&echo_content_rand, timeout)?;
Ok(())
}
fn background_script_run(&mut self, script: &str) -> Result<(), Box<dyn Error>> {
let mut cmd = script.to_owned();
Expand Down
24 changes: 12 additions & 12 deletions src/pythonapi/pyexec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@ impl PyExec {

let timeout = timeout.unwrap_or(30);

if let Some(_) = inner.downcast_ref::<CliTester>() {
if inner.downcast_ref::<CliTester>().is_some() {
let inner = inner.downcast_mut::<CliTester>().unwrap();
inner
.script_run(script, timeout)
.map_err(|e| PyRuntimeError::new_err(e.to_string()))?;
} else if let Some(_) = inner.downcast_ref::<SudoCliTester>() {
} else if inner.downcast_ref::<SudoCliTester>().is_some() {
let inner = inner.downcast_mut::<SudoCliTester>().unwrap();
inner
.script_run(script, timeout)
Expand All @@ -95,12 +95,12 @@ impl PyExec {

let timeout = timeout.unwrap_or(30);

if let Some(_) = inner.downcast_ref::<CliTester>() {
if inner.downcast_ref::<CliTester>().is_some() {
let inner = inner.downcast_mut::<CliTester>().unwrap();
inner
.assert_script_run(script, timeout)
.map_err(|e| PyRuntimeError::new_err(e.to_string()))?;
} else if let Some(_) = inner.downcast_ref::<SudoCliTester>() {
} else if inner.downcast_ref::<SudoCliTester>().is_some() {
let inner = inner.downcast_mut::<SudoCliTester>().unwrap();
inner
.assert_script_run(script, timeout)
Expand All @@ -118,12 +118,12 @@ impl PyExec {
let inner = self_.inner.get_mut()?;
let inner = inner.as_any_mut();

if let Some(_) = inner.downcast_ref::<CliTester>() {
if inner.downcast_ref::<CliTester>().is_some() {
let inner = inner.downcast_mut::<CliTester>().unwrap();
inner
.background_script_run(script)
.map_err(|e| PyRuntimeError::new_err(e.to_string()))?;
} else if let Some(_) = inner.downcast_ref::<SudoCliTester>() {
} else if inner.downcast_ref::<SudoCliTester>().is_some() {
let inner = inner.downcast_mut::<SudoCliTester>().unwrap();
inner
.background_script_run(script)
Expand All @@ -141,12 +141,12 @@ impl PyExec {
let inner = self_.inner.get_mut()?;
let inner = inner.as_any_mut();

if let Some(_) = inner.downcast_ref::<CliTester>() {
if inner.downcast_ref::<CliTester>().is_some() {
let inner = inner.downcast_mut::<CliTester>().unwrap();
inner
.writeln(script)
.map_err(|e| PyRuntimeError::new_err(e.to_string()))?;
} else if let Some(_) = inner.downcast_ref::<SudoCliTester>() {
} else if inner.downcast_ref::<SudoCliTester>().is_some() {
let inner = inner.downcast_mut::<SudoCliTester>().unwrap();
inner
.writeln(script)
Expand All @@ -171,12 +171,12 @@ impl PyExec {

let timeout = timeout.unwrap_or(30);

if let Some(_) = inner.downcast_ref::<CliTester>() {
if inner.downcast_ref::<CliTester>().is_some() {
let inner = inner.downcast_mut::<CliTester>().unwrap();
inner
.wait_serial(expected, timeout)
.map_err(|e| PyRuntimeError::new_err(e.to_string()))?;
} else if let Some(_) = inner.downcast_ref::<SudoCliTester>() {
} else if inner.downcast_ref::<SudoCliTester>().is_some() {
let inner = inner.downcast_mut::<SudoCliTester>().unwrap();
inner
.wait_serial(expected, timeout)
Expand All @@ -201,7 +201,7 @@ impl PyExec {

let timeout = timeout.unwrap_or(30);

if let Some(_) = inner.downcast_ref::<SudoCliTester>() {
if inner.downcast_ref::<SudoCliTester>().is_some() {
let inner = inner.downcast_mut::<SudoCliTester>().unwrap();
inner
.script_sudo(script, timeout)
Expand All @@ -226,7 +226,7 @@ impl PyExec {

let timeout = timeout.unwrap_or(30);

if let Some(_) = inner.downcast_ref::<SudoCliTester>() {
if inner.downcast_ref::<SudoCliTester>().is_some() {
let inner = inner.downcast_mut::<SudoCliTester>().unwrap();
inner
.assert_script_sudo(script, timeout)
Expand Down
5 changes: 2 additions & 3 deletions src/pythonapi/pyhook.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@ pub fn build_ttyhook(inner: Py<PyAny>) -> PyTty {
let inner = PyTtyWrapper {
tty: heap_raw(inner)
};
let res = PyTty {
PyTty {
inner
};
res
}
}

pub struct PyTtyHook {
Expand Down
32 changes: 16 additions & 16 deletions src/pythonapi/shell_like.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,39 +231,39 @@ impl PyTty {
let inner = Box::into_inner(inner);
let inner = inner.into_any();

if let Some(_) = inner.downcast_ref::<SimpleRecorder>() {
if inner.downcast_ref::<SimpleRecorder>().is_some() {
let inner = inner.downcast::<SimpleRecorder>().unwrap();
let inner = inner.exit();
Ok(PyTty {
inner: PyTtyWrapper {
tty: heap_raw(inner),
},
})
} else if let Some(_) = inner.downcast_ref::<Asciicast>() {
} else if inner.downcast_ref::<Asciicast>().is_some() {
let inner = inner.downcast::<Asciicast>().unwrap();
let inner = inner.exit();
Ok(PyTty {
inner: PyTtyWrapper {
tty: heap_raw(inner),
},
})
} else if let Some(_) = inner.downcast_ref::<Tee>() {
} else if inner.downcast_ref::<Tee>().is_some() {
let inner = inner.downcast::<Tee>().unwrap();
let inner = inner.exit();
Ok(PyTty {
inner: PyTtyWrapper {
tty: heap_raw(inner),
},
})
} else if let Some(_) = inner.downcast_ref::<CliTester>() {
} else if inner.downcast_ref::<CliTester>().is_some() {
let inner = inner.downcast::<CliTester>().unwrap();
let inner = inner.exit();
Ok(PyTty {
inner: PyTtyWrapper {
tty: heap_raw(inner),
},
})
} else if let Some(_) = inner.downcast_ref::<SudoCliTester>() {
} else if inner.downcast_ref::<SudoCliTester>().is_some() {
let inner = inner.downcast::<SudoCliTester>().unwrap();
let inner = inner.exit();
Ok(PyTty {
Expand All @@ -284,12 +284,12 @@ impl PyTty {
let inner = self.inner.get_mut()?;
let inner = inner.as_any_mut();

if let Some(_) = inner.downcast_ref::<SimpleRecorder>() {
if inner.downcast_ref::<SimpleRecorder>().is_some() {
let inner = inner.downcast_mut::<SimpleRecorder>().unwrap();
inner
.begin()
.map_err(|e| PyRuntimeError::new_err(e.to_string()))
} else if let Some(_) = inner.downcast_ref::<Asciicast>() {
} else if inner.downcast_ref::<Asciicast>().is_some() {
let inner = inner.downcast_mut::<Asciicast>().unwrap();
inner
.begin()
Expand All @@ -305,12 +305,12 @@ impl PyTty {
let inner = self.inner.get_mut()?;
let inner = inner.as_any_mut();

if let Some(_) = inner.downcast_ref::<SimpleRecorder>() {
if inner.downcast_ref::<SimpleRecorder>().is_some() {
let inner = inner.downcast_mut::<SimpleRecorder>().unwrap();
inner
.end()
.map_err(|e| PyRuntimeError::new_err(e.to_string()))
} else if let Some(_) = inner.downcast_ref::<Asciicast>() {
} else if inner.downcast_ref::<Asciicast>().is_some() {
let inner = inner.downcast_mut::<Asciicast>().unwrap();
inner
.end()
Expand All @@ -326,12 +326,12 @@ impl PyTty {
let inner = self.inner.get_mut()?;
let inner = inner.as_any_mut();

if let Some(_) = inner.downcast_ref::<SimpleRecorder>() {
if inner.downcast_ref::<SimpleRecorder>().is_some() {
let inner = inner.downcast_mut::<SimpleRecorder>().unwrap();
inner
.start()
.map_err(|e| PyRuntimeError::new_err(e.to_string()))
} else if let Some(_) = inner.downcast_ref::<Asciicast>() {
} else if inner.downcast_ref::<Asciicast>().is_some() {
let inner = inner.downcast_mut::<Asciicast>().unwrap();
inner
.start()
Expand All @@ -347,12 +347,12 @@ impl PyTty {
let inner = self.inner.get_mut()?;
let inner = inner.as_any_mut();

if let Some(_) = inner.downcast_ref::<SimpleRecorder>() {
if inner.downcast_ref::<SimpleRecorder>().is_some() {
let inner = inner.downcast_mut::<SimpleRecorder>().unwrap();
inner
.pause()
.map_err(|e| PyRuntimeError::new_err(e.to_string()))
} else if let Some(_) = inner.downcast_ref::<Asciicast>() {
} else if inner.downcast_ref::<Asciicast>().is_some() {
let inner = inner.downcast_mut::<Asciicast>().unwrap();
inner
.pause()
Expand All @@ -368,7 +368,7 @@ impl PyTty {
let inner = self.inner.get_mut()?;
let inner = inner.as_any_mut();

if let Some(_) = inner.downcast_ref::<SimpleRecorder>() {
if inner.downcast_ref::<SimpleRecorder>().is_some() {
let inner = inner.downcast_mut::<SimpleRecorder>().unwrap();
let target = other.inner.safe_take()?;
let target = Box::into_inner(target);
Expand All @@ -379,7 +379,7 @@ impl PyTty {
let target = target.unwrap();
other.inner.tty = heap_raw(target);
Ok(())
} else if let Some(_) = inner.downcast_ref::<Asciicast>() {
} else if inner.downcast_ref::<Asciicast>().is_some() {
let inner = inner.downcast_mut::<Asciicast>().unwrap();
let target = other.inner.safe_take()?;
let target = Box::into_inner(target);
Expand All @@ -403,7 +403,7 @@ impl PyTty {
let inner = Box::into_inner(inner);
let inner = inner.into_any();

if let Some(_) = inner.downcast_ref::<PyTtyHook>() {
if inner.downcast_ref::<PyTtyHook>().is_some() {
let inner = inner.downcast::<PyTtyHook>().unwrap();
let res = inner.inner;
Ok(res)
Expand Down
Loading

0 comments on commit c707771

Please sign in to comment.