fix(render): fix warnings

This commit is contained in:
Federico Terzi 2021-10-05 23:18:39 +02:00
parent 2cd974c80b
commit c318b1aaf6
6 changed files with 41 additions and 83 deletions

View File

@ -78,16 +78,13 @@ impl DateExtension {
mod tests {
use super::*;
use chrono::offset::TimeZone;
use std::iter::FromIterator;
#[test]
fn date_formatted_correctly() {
let mut extension = DateExtension::new();
extension.fixed_date = Some(Local.ymd(2014, 7, 8).and_hms(9, 10, 11));
let param = Params::from_iter(
vec![("format".to_string(), Value::String("%H:%M:%S".to_string()))].into_iter(),
);
let param = vec![("format".to_string(), Value::String("%H:%M:%S".to_string()))].into_iter().collect::<Params>();
assert_eq!(
extension
.calculate(&Default::default(), &Default::default(), &param)
@ -102,13 +99,11 @@ mod tests {
let mut extension = DateExtension::new();
extension.fixed_date = Some(Local.ymd(2014, 7, 8).and_hms(9, 10, 11));
let param = Params::from_iter(
vec![
let param = vec![
("format".to_string(), Value::String("%H:%M:%S".to_string())),
("offset".to_string(), Value::Number(Number::Integer(3600))),
]
.into_iter(),
);
.into_iter().collect::<Params>();
assert_eq!(
extension
.calculate(&Default::default(), &Default::default(), &param)

View File

@ -67,14 +67,13 @@ pub enum EchoExtensionError {
#[cfg(test)]
mod tests {
use super::*;
use std::iter::FromIterator;
#[test]
fn echo_works_correctly() {
let extension = EchoExtension::new();
let param =
Params::from_iter(vec![("echo".to_string(), Value::String("test".to_string()))].into_iter());
vec![("echo".to_string(), Value::String("test".to_string()))].into_iter().collect::<Params>();
assert_eq!(
extension
.calculate(&Default::default(), &Default::default(), &param)

View File

@ -71,14 +71,12 @@ pub enum RandomExtensionError {
#[cfg(test)]
mod tests {
use super::*;
use std::iter::FromIterator;
#[test]
fn random_works_correctly() {
let extension = RandomExtension::new();
let param = Params::from_iter(
vec![(
let param = vec![(
"choices".to_string(),
Value::Array(vec![
Value::String("first".to_string()),
@ -86,8 +84,7 @@ mod tests {
Value::String("third".to_string()),
]),
)]
.into_iter(),
);
.into_iter().collect::<Params>();
assert!(matches!(
extension
.calculate(&Default::default(), &Default::default(), &param)

View File

@ -181,7 +181,6 @@ mod tests {
use super::*;
#[cfg(not(target_os = "windows"))]
use crate::Scope;
use std::iter::FromIterator;
fn get_extension() -> ScriptExtension {
ScriptExtension::new(&PathBuf::new(), &PathBuf::new(), &PathBuf::new())
@ -192,16 +191,14 @@ mod tests {
fn basic() {
let extension = get_extension();
let param = Params::from_iter(
vec![(
let param = vec![(
"args".to_string(),
Value::Array(vec![
Value::String("echo".to_string()),
Value::String("hello world".to_string()),
]),
)]
.into_iter(),
);
.into_iter().collect::<Params>();
assert_eq!(
extension
.calculate(&Default::default(), &Default::default(), &param)
@ -216,8 +213,7 @@ mod tests {
fn basic_no_trim() {
let extension = get_extension();
let param = Params::from_iter(
vec![
let param = vec![
(
"args".to_string(),
Value::Array(vec![
@ -227,8 +223,7 @@ mod tests {
),
("trim".to_string(), Value::Bool(false)),
]
.into_iter(),
);
.into_iter().collect::<Params>();
if cfg!(target_os = "windows") {
assert_eq!(
extension
@ -253,8 +248,7 @@ mod tests {
fn var_injection() {
let extension = get_extension();
let param = Params::from_iter(
vec![
let param = vec![
(
"args".to_string(),
Value::Array(vec![
@ -264,8 +258,7 @@ mod tests {
]),
),
]
.into_iter(),
);
.into_iter().collect::<Params>();
let mut scope = Scope::new();
scope.insert("var1", ExtensionOutput::Single("hello world".to_string()));
assert_eq!(
@ -281,8 +274,7 @@ mod tests {
fn invalid_command() {
let extension = get_extension();
let param = Params::from_iter(
vec![
let param = vec![
(
"args".to_string(),
Value::Array(vec![
@ -290,8 +282,7 @@ mod tests {
]),
),
]
.into_iter(),
);
.into_iter().collect::<Params>();
assert!(matches!(
extension.calculate(&Default::default(), &Default::default(), &param),
ExtensionResult::Error(_)
@ -303,8 +294,7 @@ mod tests {
fn exit_error() {
let extension = get_extension();
let param = Params::from_iter(
vec![
let param = vec![
(
"args".to_string(),
Value::Array(vec![
@ -314,8 +304,7 @@ mod tests {
]),
),
]
.into_iter(),
);
.into_iter().collect::<Params>();
assert!(matches!(
extension.calculate(&Default::default(), &Default::default(), &param),
ExtensionResult::Error(_)
@ -327,8 +316,7 @@ mod tests {
fn ignore_error() {
let extension = get_extension();
let param = Params::from_iter(
vec![
let param = vec![
(
"args".to_string(),
Value::Array(vec![
@ -339,8 +327,7 @@ mod tests {
),
("ignore_error".to_string(), Value::Bool(true)),
]
.into_iter(),
);
.into_iter().collect::<Params>();
assert_eq!(
extension
.calculate(&Default::default(), &Default::default(), &param)

View File

@ -27,6 +27,7 @@ use crate::{Extension, ExtensionOutput, ExtensionResult, Params, Value};
use log::{info, warn};
use thiserror::Error;
#[allow(clippy::upper_case_acronyms)]
pub enum Shell {
Cmd,
Powershell,
@ -252,22 +253,19 @@ pub enum ShellExtensionError {
mod tests {
use super::*;
use crate::Scope;
use std::iter::FromIterator;
#[test]
fn shell_not_trimmed() {
let extension = ShellExtension::new(&PathBuf::new());
let param = Params::from_iter(
vec![
let param = vec![
(
"cmd".to_string(),
Value::String("echo \"hello world\"".to_string()),
),
("trim".to_string(), Value::Bool(false)),
]
.into_iter(),
);
.into_iter().collect::<Params>();
if cfg!(target_os = "windows") {
assert_eq!(
extension
@ -291,13 +289,12 @@ mod tests {
fn shell_trimmed() {
let extension = ShellExtension::new(&PathBuf::new());
let param = Params::from_iter(
vec![(
let param = vec![(
"cmd".to_string(),
Value::String("echo \"hello world\"".to_string()),
)]
.into_iter(),
);
.into_iter().collect::<Params>();
assert_eq!(
extension
.calculate(&Default::default(), &Default::default(), &param)
@ -312,13 +309,11 @@ mod tests {
fn pipes() {
let extension = ShellExtension::new(&PathBuf::new());
let param = Params::from_iter(
vec![(
let param = vec![(
"cmd".to_string(),
Value::String("echo \"hello world\" | cat".to_string()),
)]
.into_iter(),
);
.into_iter().collect::<Params>();
assert_eq!(
extension
.calculate(&Default::default(), &Default::default(), &param)
@ -333,24 +328,20 @@ mod tests {
let extension = ShellExtension::new(&PathBuf::new());
let param = if cfg!(not(target_os = "windows")) {
Params::from_iter(
vec![(
vec![(
"cmd".to_string(),
Value::String("echo $ESPANSO_VAR1".to_string()),
)]
.into_iter(),
)
.into_iter().collect::<Params>()
} else {
Params::from_iter(
vec![
vec![
(
"cmd".to_string(),
Value::String("echo %ESPANSO_VAR1%".to_string()),
),
("shell".to_string(), Value::String("cmd".to_string())),
]
.into_iter(),
)
.into_iter().collect::<Params>()
};
let mut scope = Scope::new();
scope.insert("var1", ExtensionOutput::Single("hello world".to_string()));
@ -367,13 +358,12 @@ mod tests {
fn invalid_command() {
let extension = ShellExtension::new(&PathBuf::new());
let param = Params::from_iter(
let param =
vec![(
"cmd".to_string(),
Value::String("nonexistentcommand".to_string()),
)]
.into_iter(),
);
.into_iter().collect::<Params>();
assert!(matches!(
extension.calculate(&Default::default(), &Default::default(), &param),
ExtensionResult::Error(_)
@ -386,7 +376,7 @@ mod tests {
let extension = ShellExtension::new(&PathBuf::new());
let param =
Params::from_iter(vec![("cmd".to_string(), Value::String("exit 1".to_string()))].into_iter());
vec![("cmd".to_string(), Value::String("exit 1".to_string()))].into_iter().collect::<Params>();
assert!(matches!(
extension.calculate(&Default::default(), &Default::default(), &param),
ExtensionResult::Error(_)
@ -398,13 +388,11 @@ mod tests {
fn ignore_error() {
let extension = ShellExtension::new(&PathBuf::new());
let param = Params::from_iter(
vec![
let param = vec![
("cmd".to_string(), Value::String("exit 1".to_string())),
("ignore_error".to_string(), Value::Bool(true)),
]
.into_iter(),
);
.into_iter().collect::<Params>();
assert_eq!(
extension
.calculate(&Default::default(), &Default::default(), &param)

View File

@ -321,9 +321,7 @@ mod tests {
.map(|(name, value)| Variable {
name: (*name).to_string(),
var_type: "mock".to_string(),
params: Params::from_iter(
vec![("echo".to_string(), Value::String((*value).to_string()))].into_iter(),
),
params: vec![("echo".to_string(), Value::String((*value).to_string()))].into_iter().collect::<Params>(),
})
.collect();
Template {
@ -432,9 +430,7 @@ mod tests {
Variable {
name: "local".to_string(),
var_type: "mock".to_string(),
params: Params::from_iter(
vec![("echo".to_string(), Value::String("Bob".to_string()))].into_iter(),
),
params: vec![("echo".to_string(), Value::String("Bob".to_string()))].into_iter().collect::<Params>(),
},
Variable {
name: "var".to_string(),
@ -470,9 +466,7 @@ mod tests {
vars: vec![Variable {
name: "var".to_string(),
var_type: "match".to_string(),
params: Params::from_iter(
vec![("trigger".to_string(), Value::String("nested".to_string()))].into_iter(),
),
params: vec![("trigger".to_string(), Value::String("nested".to_string()))].into_iter().collect::<Params>(),
}],
..Default::default()
};
@ -500,9 +494,7 @@ mod tests {
vars: vec![Variable {
name: "var".to_string(),
var_type: "match".to_string(),
params: Params::from_iter(
vec![("trigger".to_string(), Value::String("nested".to_string()))].into_iter(),
),
params: vec![("trigger".to_string(), Value::String("nested".to_string()))].into_iter().collect::<Params>(),
}],
..Default::default()
};
@ -524,7 +516,7 @@ mod tests {
vars: vec![Variable {
name: "var".to_string(),
var_type: "mock".to_string(),
params: Params::from_iter(vec![("abort".to_string(), Value::Null)].into_iter()),
params: vec![("abort".to_string(), Value::Null)].into_iter().collect::<Params>(),
}],
..Default::default()
};
@ -540,7 +532,7 @@ mod tests {
vars: vec![Variable {
name: "var".to_string(),
var_type: "mock".to_string(),
params: Params::from_iter(vec![("error".to_string(), Value::Null)].into_iter()),
params: vec![("error".to_string(), Value::Null)].into_iter().collect::<Params>(),
}],
..Default::default()
};