Fix a bunch of errors from clippy --tests

This commit is contained in:
Richard Feldman 2022-05-10 14:43:49 -04:00
parent a426a61e5d
commit dbc6302681
No known key found for this signature in database
GPG Key ID: 7E4127D1E4241798
19 changed files with 123 additions and 123 deletions

View File

@ -92,7 +92,7 @@ mod cli_run {
let (before_first_digit, _) = err.split_at(err.rfind("found in ").unwrap());
let err = format!("{}found in <ignored for test> ms.", before_first_digit);
assert_multiline_str_eq!(err.as_str(), expected.into());
assert_multiline_str_eq!(err.as_str(), expected);
}
fn check_format_check_as_expected(file: &Path, expects_success_exit_code: bool) {
@ -122,10 +122,9 @@ mod cli_run {
),
};
if !compile_out.stderr.is_empty() &&
// If there is any stderr, it should be reporting the runtime and that's it!
!(compile_out.stderr.starts_with("runtime: ")
&& compile_out.stderr.ends_with("ms\n"))
// If there is any stderr, it should be reporting the runtime and that's it!
if !(compile_out.stderr.is_empty()
|| compile_out.stderr.starts_with("runtime: ") && compile_out.stderr.ends_with("ms\n"))
{
panic!(
"`roc` command had unexpected stderr: {}",
@ -165,7 +164,7 @@ mod cli_run {
if use_valgrind && ALLOW_VALGRIND {
let (valgrind_out, raw_xml) = if let Some(ref input_file) = input_file {
run_with_valgrind(
stdin.clone().iter().copied(),
stdin.iter().copied(),
&[
file.with_file_name(executable_filename).to_str().unwrap(),
input_file.clone().to_str().unwrap(),
@ -173,7 +172,7 @@ mod cli_run {
)
} else {
run_with_valgrind(
stdin.clone().iter().copied(),
stdin.iter().copied(),
&[file.with_file_name(executable_filename).to_str().unwrap()],
)
};

View File

@ -326,10 +326,12 @@ mod test_can {
// 2. Thus, `g` is not defined then final reference to it is a
// `LookupNotInScope`.
assert_eq!(problems.len(), 2);
assert!(problems.iter().all(|problem| match problem {
Problem::SignatureDefMismatch { .. } => true,
Problem::RuntimeError(RuntimeError::LookupNotInScope(_, _)) => true,
_ => false,
assert!(problems.iter().all(|problem| {
matches!(
problem,
Problem::SignatureDefMismatch { .. }
| Problem::RuntimeError(RuntimeError::LookupNotInScope(_, _))
)
}));
}
@ -352,10 +354,12 @@ mod test_can {
// 2. Thus, `g` is not defined then final reference to it is a
// `LookupNotInScope`.
assert_eq!(problems.len(), 2);
assert!(problems.iter().all(|problem| match problem {
Problem::SignatureDefMismatch { .. } => true,
Problem::RuntimeError(RuntimeError::LookupNotInScope(_, _)) => true,
_ => false,
assert!(problems.iter().all(|problem| {
matches!(
problem,
Problem::SignatureDefMismatch { .. }
| Problem::RuntimeError(RuntimeError::LookupNotInScope(_, _))
)
}));
}
@ -374,10 +378,10 @@ mod test_can {
let CanExprOut { problems, .. } = can_expr_with(&arena, test_home(), src);
assert_eq!(problems.len(), 1);
assert!(problems.iter().all(|problem| match problem {
Problem::RuntimeError(RuntimeError::Shadowing { .. }) => true,
_ => false,
}));
assert!(problems.iter().all(|problem| matches!(
problem,
Problem::RuntimeError(RuntimeError::Shadowing { .. })
)));
}
#[test]
@ -395,10 +399,10 @@ mod test_can {
let CanExprOut { problems, .. } = can_expr_with(&arena, test_home(), src);
assert_eq!(problems.len(), 1);
assert!(problems.iter().all(|problem| match problem {
Problem::RuntimeError(RuntimeError::Shadowing { .. }) => true,
_ => false,
}));
assert!(problems.iter().all(|problem| matches!(
problem,
Problem::RuntimeError(RuntimeError::Shadowing { .. })
)));
}
#[test]
@ -417,10 +421,10 @@ mod test_can {
assert_eq!(problems.len(), 1);
println!("{:#?}", problems);
assert!(problems.iter().all(|problem| match problem {
Problem::RuntimeError(RuntimeError::Shadowing { .. }) => true,
_ => false,
}));
assert!(problems.iter().all(|problem| matches!(
problem,
Problem::RuntimeError(RuntimeError::Shadowing { .. })
)));
}
#[test]
@ -540,10 +544,9 @@ mod test_can {
let CanExprOut { problems, .. } = can_expr_with(&arena, test_home(), src);
assert_eq!(problems.len(), 1);
assert!(problems.iter().all(|problem| match problem {
Problem::UnusedDef(_, _) => true,
_ => false,
}));
assert!(problems
.iter()
.all(|problem| matches!(problem, Problem::UnusedDef(_, _))));
}
#[test]
@ -563,10 +566,9 @@ mod test_can {
let CanExprOut { problems, .. } = can_expr_with(&arena, test_home(), src);
assert_eq!(problems.len(), 2);
assert!(problems.iter().all(|problem| match problem {
Problem::UnusedDef(_, _) => true,
_ => false,
}));
assert!(problems
.iter()
.all(|problem| matches!(problem, Problem::UnusedDef(_, _))));
}
// LOCALS
@ -643,10 +645,9 @@ mod test_can {
} = can_expr_with(&arena, test_home(), src);
assert_eq!(problems.len(), 1);
assert!(problems.iter().all(|problem| match problem {
Problem::InvalidOptionalValue { .. } => true,
_ => false,
}));
assert!(problems
.iter()
.all(|problem| matches!(problem, Problem::InvalidOptionalValue { .. })));
assert!(matches!(
loc_expr.value,

View File

@ -86,7 +86,7 @@ mod test_fmt {
) {
fmt_module(buf, module);
match module_defs().parse(&arena, state) {
match module_defs().parse(arena, state) {
Ok((_, loc_defs, _)) => {
for loc_def in loc_defs {
fmt_def(buf, arena.alloc(loc_def.value), 0);

View File

@ -2425,12 +2425,13 @@ mod tests {
let mut buf = bumpalo::vec![in &arena];
let cvtss2sd_code: u8 = 0x5A;
for (op_code, reg1, reg2, expected) in &[(
{
let (op_code, reg1, reg2, expected) = &(
cvtss2sd_code,
X86_64FloatReg::XMM1,
X86_64FloatReg::XMM0,
[0xF3, 0x0F, 0x5A, 0xC8],
)] {
);
buf.clear();
cvtsx2_help(&mut buf, 0xF3, *op_code, *reg1, *reg2);
assert_eq!(expected, &buf[..]);

View File

@ -331,7 +331,7 @@ mod tests {
use super::*;
use bumpalo::{self, collections::Vec, Bump};
fn help_u32<'a>(arena: &'a Bump, value: u32) -> Vec<'a, u8> {
fn help_u32(arena: &Bump, value: u32) -> Vec<'_, u8> {
let mut buffer = Vec::with_capacity_in(MAX_SIZE_ENCODED_U32, arena);
buffer.encode_u32(value);
buffer
@ -349,7 +349,7 @@ mod tests {
assert_eq!(help_u32(a, u32::MAX), &[0xff, 0xff, 0xff, 0xff, 0x0f]);
}
fn help_u64<'a>(arena: &'a Bump, value: u64) -> Vec<'a, u8> {
fn help_u64(arena: &Bump, value: u64) -> Vec<'_, u8> {
let mut buffer = Vec::with_capacity_in(10, arena);
buffer.encode_u64(value);
buffer
@ -370,7 +370,7 @@ mod tests {
);
}
fn help_i32<'a>(arena: &'a Bump, value: i32) -> Vec<'a, u8> {
fn help_i32(arena: &Bump, value: i32) -> Vec<'_, u8> {
let mut buffer = Vec::with_capacity_in(MAX_SIZE_ENCODED_U32, arena);
buffer.encode_i32(value);
buffer
@ -390,7 +390,7 @@ mod tests {
assert_eq!(help_i32(a, i32::MIN), &[0x80, 0x80, 0x80, 0x80, 0x78]);
}
fn help_i64<'a>(arena: &'a Bump, value: i64) -> Vec<'a, u8> {
fn help_i64(arena: &Bump, value: i64) -> Vec<'_, u8> {
let mut buffer = Vec::with_capacity_in(10, arena);
buffer.encode_i64(value);
buffer

View File

@ -2,6 +2,6 @@ extern crate bumpalo;
use std::path::{Path, PathBuf};
pub fn fixtures_dir<'a>() -> PathBuf {
pub fn fixtures_dir() -> PathBuf {
Path::new("tests").join("fixtures").join("build")
}

View File

@ -663,7 +663,7 @@ mod test {
FlexVar(Some(name)) => {
assert_eq!(subs[*name].as_str(), "a");
}
it => assert!(false, "{:?}", it),
it => unreachable!("{:?}", it),
}
}
@ -686,7 +686,7 @@ mod test {
RigidVar(name) => {
assert_eq!(subs[*name].as_str(), "a");
}
it => assert!(false, "{:?}", it),
it => unreachable!("{:?}", it),
}
}
@ -709,7 +709,7 @@ mod test {
FlexAbleVar(Some(name), Symbol::UNDERSCORE) => {
assert_eq!(subs[*name].as_str(), "a");
}
it => assert!(false, "{:?}", it),
it => unreachable!("{:?}", it),
}
}
@ -732,7 +732,7 @@ mod test {
RigidAbleVar(name, Symbol::UNDERSCORE) => {
assert_eq!(subs[*name].as_str(), "a");
}
it => assert!(false, "{:?}", it),
it => unreachable!("{:?}", it),
}
}
}

View File

@ -342,7 +342,7 @@ mod test_parse {
assert_eq!(Ok(expected_expr), actual);
}
fn assert_parsing_fails<'a>(input: &'a str, _reason: SyntaxError) {
fn assert_parsing_fails(input: &str, _reason: SyntaxError) {
let arena = Bump::new();
let actual = parse_expr_with(&arena, input);
@ -820,7 +820,7 @@ mod test_parse {
}
Err((_, _fail, _state)) => {
// dbg!(_fail, _state);
assert!(false);
panic!("Failed to parse!");
}
}
}

View File

@ -113,7 +113,7 @@ mod solve_expr {
let filename = PathBuf::from("test.roc");
let src_lines: Vec<&str> = src.split('\n').collect();
let lines = LineInfo::new(src);
let alloc = RocDocAllocator::new(&src_lines, home, &interns);
let alloc = RocDocAllocator::new(&src_lines, home, interns);
let mut can_reports = vec![];
let mut type_reports = vec![];
@ -271,7 +271,7 @@ mod solve_expr {
let end = region.end().offset;
let text = &src[start as usize..end as usize];
let var = find_type_at(region, &decls)
.expect(&format!("No type for {} ({:?})!", &text, region));
.unwrap_or_else(|| panic!("No type for {} ({:?})!", &text, region));
let actual_str = name_and_print_var(var, subs, home, &interns);
@ -323,8 +323,7 @@ mod solve_expr {
let has_the_one = pretty_specializations
.iter()
// references are annoying so we do this
.find(|(p, s)| p == parent && s == &specialization)
.is_some();
.any(|(p, s)| p == parent && s == &specialization);
assert!(
has_the_one,
"{:#?} not in {:#?}",

View File

@ -107,7 +107,7 @@ fn build_wasm_libc_compilerrt(out_dir: &str, source_path: &str) -> (String, Stri
fn feature_is_enabled(feature_name: &str) -> bool {
let cargo_env_var = format!(
"CARGO_FEATURE_{}",
feature_name.replace("-", "_").to_uppercase()
feature_name.replace('-', "_").to_uppercase()
);
env::var(cargo_env_var).is_ok()
}

View File

@ -65,7 +65,7 @@ fn dict_nonempty_contains() {
indoc!(
r#"
empty : Dict I64 F64
empty = Dict.insert Dict.empty 42 3.14
empty = Dict.insert Dict.empty 42 1.23
Dict.contains empty 42
"#
@ -101,7 +101,7 @@ fn dict_nonempty_remove() {
indoc!(
r#"
empty : Dict I64 F64
empty = Dict.insert Dict.empty 42 3.14
empty = Dict.insert Dict.empty 42 1.23
empty
|> Dict.remove 42
@ -120,7 +120,7 @@ fn dict_nonempty_get() {
indoc!(
r#"
empty : Dict I64 F64
empty = Dict.insert Dict.empty 42 3.14
empty = Dict.insert Dict.empty 42 1.23
withDefault = \x, def ->
when x is
@ -128,12 +128,12 @@ fn dict_nonempty_get() {
Err _ -> def
empty
|> Dict.insert 42 3.14
|> Dict.insert 42 1.23
|> Dict.get 42
|> withDefault 0
"#
),
3.14,
1.23,
f64
);
@ -146,7 +146,7 @@ fn dict_nonempty_get() {
Err _ -> def
Dict.empty
|> Dict.insert 42 3.14
|> Dict.insert 42 1.23
|> Dict.get 43
|> withDefault 0
"#

View File

@ -1089,7 +1089,7 @@ fn list_map_closure() {
indoc!(
r#"
pi : F64
pi = 3.14
pi = 1.23
single : List F64
single =
@ -1098,7 +1098,7 @@ fn list_map_closure() {
List.map single (\x -> x + pi)
"#
),
RocList::from_slice(&[3.14]),
RocList::from_slice(&[1.23]),
RocList<f64>
);
}

View File

@ -217,7 +217,7 @@ fn gen_when_one_branch() {
assert_evals_to!(
indoc!(
r#"
when 3.14 is
when 1.23 is
_ -> 23
"#
),
@ -332,12 +332,12 @@ fn return_unnamed_fn() {
alwaysFloatIdentity = \_ ->
(\a -> a)
(alwaysFloatIdentity 2) 3.14
(alwaysFloatIdentity 2) 1.23
wrapper {}
"#
),
3.14,
1.23,
f64
);
}
@ -380,12 +380,12 @@ fn gen_basic_def() {
assert_evals_to!(
indoc!(
r#"
pi = 3.14
pi = 1.23
pi
"#
),
3.14,
1.23,
f64
);
}
@ -398,7 +398,7 @@ fn gen_multiple_defs() {
r#"
answer = 42
pi = 3.14
pi = 1.23
if pi > 3 then answer else answer
"#
@ -412,12 +412,12 @@ fn gen_multiple_defs() {
r#"
answer = 42
pi = 3.14
pi = 1.23
if answer > 3 then pi else pi
"#
),
3.14,
1.23,
f64
);
}
@ -582,13 +582,13 @@ fn top_level_constant() {
r#"
app "test" provides [ main ] to "./platform"
pi = 3.1415
pi = 1.2315
main =
pi + pi
"#
),
3.1415 + 3.1415,
1.2315 + 1.2315,
f64
);
}
@ -1144,7 +1144,7 @@ fn io_poc_effect() {
foo : Effect F64
foo =
succeed 3.14
succeed 1.23
main : F64
main =
@ -1152,7 +1152,7 @@ fn io_poc_effect() {
"#
),
3.14,
1.23,
f64
);
}
@ -1170,7 +1170,7 @@ fn io_poc_desugared() {
foo : Str -> F64
foo =
succeed 3.14
succeed 1.23
# runEffect : ({} -> a) -> a
runEffect = \thunk -> thunk ""
@ -1180,7 +1180,7 @@ fn io_poc_desugared() {
runEffect foo
"#
),
3.14,
1.23,
f64
);
}
@ -1817,15 +1817,15 @@ fn unified_empty_closure_bool() {
foo = \{} ->
when A is
A -> (\_ -> 3.14)
B -> (\_ -> 3.14)
A -> (\_ -> 1.23)
B -> (\_ -> 1.23)
main : Frac *
main =
(foo {}) 0
"#
),
3.14,
1.23,
f64
);
}
@ -1842,16 +1842,16 @@ fn unified_empty_closure_byte() {
foo = \{} ->
when A is
A -> (\_ -> 3.14)
B -> (\_ -> 3.14)
C -> (\_ -> 3.14)
A -> (\_ -> 1.23)
B -> (\_ -> 1.23)
C -> (\_ -> 1.23)
main : Frac *
main =
(foo {}) 0
"#
),
3.14,
1.23,
f64
);
}

View File

@ -200,7 +200,7 @@ fn when_record_with_guard_pattern() {
assert_evals_to!(
indoc!(
r#"
when { x: 0x2, y: 3.14 } is
when { x: 0x2, y: 1.23 } is
{ x: var } -> var + 3
"#
),
@ -215,7 +215,7 @@ fn let_with_record_pattern() {
assert_evals_to!(
indoc!(
r#"
{ x } = { x: 0x2, y: 3.14 }
{ x } = { x: 0x2, y: 1.23 }
x
"#
@ -231,7 +231,7 @@ fn record_guard_pattern() {
assert_evals_to!(
indoc!(
r#"
when { x: 0x2, y: 3.14 } is
when { x: 0x2, y: 1.23 } is
{ x: 0x4 } -> 5
{ x } -> x + 3
"#
@ -741,10 +741,10 @@ fn return_record_float_int() {
assert_evals_to!(
indoc!(
r#"
{ a: 3.14, b: 0x1 }
{ a: 1.23, b: 0x1 }
"#
),
(3.14, 0x1),
(1.23, 0x1),
(f64, i64)
);
}
@ -755,10 +755,10 @@ fn return_record_int_float() {
assert_evals_to!(
indoc!(
r#"
{ a: 0x1, b: 3.14 }
{ a: 0x1, b: 1.23 }
"#
),
(0x1, 3.14),
(0x1, 1.23),
(i64, f64)
);
}
@ -769,10 +769,10 @@ fn return_record_float_float() {
assert_evals_to!(
indoc!(
r#"
{ a: 6.28, b: 3.14 }
{ a: 2.46, b: 1.23 }
"#
),
(6.28, 3.14),
(2.46, 1.23),
(f64, f64)
);
}
@ -783,10 +783,10 @@ fn return_record_float_float_float() {
assert_evals_to!(
indoc!(
r#"
{ a: 6.28, b: 3.14, c: 0.1 }
{ a: 2.46, b: 1.23, c: 0.1 }
"#
),
(6.28, 3.14, 0.1),
(2.46, 1.23, 0.1),
(f64, f64, f64)
);
}
@ -797,10 +797,10 @@ fn return_nested_record() {
assert_evals_to!(
indoc!(
r#"
{ flag: 0x0, payload: { a: 6.28, b: 3.14, c: 0.1 } }
{ flag: 0x0, payload: { a: 2.46, b: 1.23, c: 0.1 } }
"#
),
(0x0, (6.28, 3.14, 0.1)),
(0x0, (2.46, 1.23, 0.1)),
(i64, (f64, f64, f64))
);
}
@ -826,7 +826,7 @@ fn nested_record_load() {
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn accessor_twice() {
assert_evals_to!(".foo { foo: 4 } + .foo { bar: 6.28, foo: 3 } ", 7, i64);
assert_evals_to!(".foo { foo: 4 } + .foo { bar: 2.46, foo: 3 } ", 7, i64);
}
#[test]
@ -863,12 +863,12 @@ fn update_record() {
assert_evals_to!(
indoc!(
r#"
rec = { foo: 42, bar: 6.28 }
rec = { foo: 42, bar: 2.46 }
{ rec & foo: rec.foo + 1 }
"#
),
(6.28, 43),
(2.46, 43),
(f64, i64)
);
}

View File

@ -1383,7 +1383,7 @@ pub mod test_ed_update {
expected_post_lines: Vec<String>,
new_char_seq: &str,
) -> Result<(), String> {
let mut code_str = pre_lines.join("\n").replace("", "");
let mut code_str = pre_lines.join("\n").replace('┃', "");
let mut model_refs = init_model_refs();
let code_arena = Bump::new();
@ -1453,11 +1453,11 @@ pub mod test_ed_update {
macro_rules! ovec {
( $( $x:expr ),* ) => {
{
let mut temp_vec = Vec::new();
$(
temp_vec.push($x.to_owned());
)*
temp_vec
vec![
$(
$x.to_owned(),
)*
]
}
};
}
@ -2589,7 +2589,7 @@ pub mod test_ed_update {
input_seq: &str,
repeats: usize,
) -> Result<(), String> {
let mut code_str = pre_lines.join("").replace("", "");
let mut code_str = pre_lines.join("").replace('┃', "");
let mut model_refs = init_model_refs();
let code_arena = Bump::new();
@ -3001,7 +3001,7 @@ pub mod test_ed_update {
expected_tooltips: Vec<String>,
new_char_seq: &str,
) -> Result<(), String> {
let mut code_str = pre_lines.join("").replace("", "");
let mut code_str = pre_lines.join("").replace('┃', "");
let mut model_refs = init_model_refs();
let code_arena = Bump::new();
@ -3179,7 +3179,7 @@ pub mod test_ed_update {
repeats: usize,
move_caret_fun: ModelMoveCaretFun,
) -> Result<(), String> {
let mut code_str = pre_lines.join("").replace("", "");
let mut code_str = pre_lines.join("").replace('┃', "");
let mut model_refs = init_model_refs();
let code_arena = Bump::new();
@ -3343,7 +3343,7 @@ pub mod test_ed_update {
expected_post_lines: Vec<String>,
repeats: usize,
) -> Result<(), String> {
let mut code_str = pre_lines.join("").replace("", "");
let mut code_str = pre_lines.join("").replace('┃', "");
let mut model_refs = init_model_refs();
let code_arena = Bump::new();

View File

@ -587,7 +587,7 @@ pub mod test_big_sel_text {
let lines_vec = all_lines_vec(&big_text)
.iter()
.map(|l| l.replace("\n", ""))
.map(|l| l.replace('\n', ""))
.collect();
let post_lines_res = convert_selection_to_dsl(big_text.caret_w_select, lines_vec);

View File

@ -489,7 +489,7 @@ fn lex_string(bytes: &[u8]) -> (Token, usize) {
}
#[cfg(test)]
mod tokenizer {
mod test_tokenizer {
use super::Token;
use crate::tokenizer::tokenize;

View File

@ -285,11 +285,11 @@ where
}
#[allow(dead_code)]
pub fn fixtures_dir<'a>() -> PathBuf {
pub fn fixtures_dir() -> PathBuf {
Path::new("tests").join("fixtures").join("build")
}
#[allow(dead_code)]
pub fn builtins_dir<'a>() -> PathBuf {
pub fn builtins_dir() -> PathBuf {
PathBuf::new().join("builtins")
}

View File

@ -101,6 +101,7 @@ mod test_reporting {
(module_src, loaded)
}
#[allow(clippy::type_complexity)]
fn infer_expr_help_new<'a>(
subdir: &str,
arena: &'a Bump,
@ -176,8 +177,7 @@ mod test_reporting {
buf
}
Err(other) => {
assert!(false, "failed to load: {:?}", other);
unreachable!()
panic!("failed to load: {:?}", other);
}
}
}
@ -342,7 +342,7 @@ mod test_reporting {
list_reports(&arena, src, &mut buf, callback);
// convenient to copy-paste the generated message
if true && buf != expected_rendering {
if buf != expected_rendering {
for line in buf.split('\n') {
println!(" {}", line);
}
@ -364,7 +364,7 @@ mod test_reporting {
list_header_reports(&arena, src, &mut buf, callback);
// convenient to copy-paste the generated message
if true && buf != expected_rendering {
if buf != expected_rendering {
for line in buf.split('\n') {
println!(" {}", line);
}