mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-28 06:14:46 +00:00
make clippy happy
This commit is contained in:
parent
926014518f
commit
d0ee040421
11 changed files with 163 additions and 113 deletions
|
@ -1,6 +1,6 @@
|
|||
use std::ffi::{OsStr, OsString};
|
||||
use std::path::PathBuf;
|
||||
use std::process::{Command};
|
||||
use std::process::Command;
|
||||
|
||||
use crate::command::{run_command, CmdOut};
|
||||
use crate::helpers::path_to_roc_binary;
|
||||
|
@ -8,7 +8,6 @@ use const_format::concatcp;
|
|||
|
||||
const LINKER_FLAG: &str = concatcp!("--", roc_cli::FLAG_LINKER, "=", "legacy");
|
||||
|
||||
|
||||
/// A builder for running the Roc CLI.
|
||||
///
|
||||
/// Unlike `std::process::Command`, this builder is clonable. This is necessary to be able to test a command with both linkers.
|
||||
|
@ -49,16 +48,23 @@ impl ExecCli {
|
|||
|
||||
pub fn run(&self) -> CmdOut {
|
||||
let mut roc_cli_command = Command::new(path_to_roc_binary());
|
||||
|
||||
|
||||
roc_cli_command.arg(self.sub_command);
|
||||
roc_cli_command.arg(self.roc_file_path.clone());
|
||||
roc_cli_command.args(&self.args);
|
||||
|
||||
|
||||
let app_stdin_opt = None;
|
||||
run_command(roc_cli_command, app_stdin_opt)
|
||||
}
|
||||
|
||||
pub fn full_check_build_and_run(mut self, expected_output: &'static str, both_linkers: bool, with_valgrind: bool, app_stdin_opt: Option<&str>, app_args_opt: Option<&[&str]>) {
|
||||
|
||||
pub fn full_check_build_and_run(
|
||||
mut self,
|
||||
expected_output: &'static str,
|
||||
both_linkers: bool,
|
||||
with_valgrind: bool,
|
||||
app_stdin_opt: Option<&str>,
|
||||
app_args_opt: Option<&[&str]>,
|
||||
) {
|
||||
self.check_build_and_run(expected_output, with_valgrind, app_stdin_opt, app_args_opt);
|
||||
|
||||
if both_linkers {
|
||||
|
@ -66,29 +72,46 @@ impl ExecCli {
|
|||
self.check_build_and_run(expected_output, with_valgrind, app_stdin_opt, app_args_opt);
|
||||
}
|
||||
}
|
||||
|
||||
fn check_build_and_run(&self, expected_output: &'static str, with_valgrind: bool, app_stdin_opt: Option<&str>, app_args_opt: Option<&[&str]>) {
|
||||
|
||||
fn check_build_and_run(
|
||||
&self,
|
||||
expected_output: &'static str,
|
||||
with_valgrind: bool,
|
||||
app_stdin_opt: Option<&str>,
|
||||
app_args_opt: Option<&[&str]>,
|
||||
) {
|
||||
let build_cmd_out = self.run();
|
||||
build_cmd_out.assert_clean_success();
|
||||
|
||||
let executable_output = self.run_executable(false, app_stdin_opt, app_args_opt);
|
||||
executable_output.assert_clean_success();
|
||||
assert_eq!(executable_output.stdout, expected_output);
|
||||
|
||||
|
||||
if with_valgrind {
|
||||
let executable_output_w_valgrind = self.run_executable(true, app_stdin_opt, app_args_opt);
|
||||
assert!(executable_output_w_valgrind.status.success(), "Valgrind found issue(s):\n{}\nCommand used for building:\n\t{:?}", executable_output_w_valgrind, build_cmd_out.cmd_str);
|
||||
let executable_output_w_valgrind =
|
||||
self.run_executable(true, app_stdin_opt, app_args_opt);
|
||||
assert!(
|
||||
executable_output_w_valgrind.status.success(),
|
||||
"Valgrind found issue(s):\n{}\nCommand used for building:\n\t{:?}",
|
||||
executable_output_w_valgrind,
|
||||
build_cmd_out.cmd_str
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// run executable produced by e.g. `roc build`
|
||||
fn run_executable(&self, with_valgrind: bool, app_stdin_opt: Option<&str>, app_args_opt: Option<&[&str]>) -> CmdOut {
|
||||
fn run_executable(
|
||||
&self,
|
||||
with_valgrind: bool,
|
||||
app_stdin_opt: Option<&str>,
|
||||
app_args_opt: Option<&[&str]>,
|
||||
) -> CmdOut {
|
||||
let executable = self.get_executable();
|
||||
|
||||
if with_valgrind {
|
||||
let mut command = Command::new("valgrind");
|
||||
|
||||
command.args(&[
|
||||
command.args([
|
||||
"--leak-check=full",
|
||||
"--error-exitcode=1",
|
||||
"--errors-for-leak-kinds=definite,possible",
|
||||
|
@ -107,7 +130,7 @@ impl ExecCli {
|
|||
run_command(command, app_stdin_opt)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fn get_executable(&self) -> PathBuf {
|
||||
let mut executable_path = self.roc_file_path.with_extension("");
|
||||
|
||||
|
@ -121,6 +144,4 @@ impl ExecCli {
|
|||
panic!("Executable {:?} does not exist.", executable_path)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue