Skip to content

Commit

Permalink
Fixed tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
apognu committed Aug 16, 2024
1 parent 986af2e commit e0364aa
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/greeter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,16 @@ impl Greeter {

// If the `--cmd` argument is provided, it will override the selected session.
if let Some(command) = self.option("cmd") {
let envs = self.options_multi("env");

if let Some(envs) = envs {
for env in envs {
if !env.contains('=') {
return Err(format!("malformed environment variable definition for '{env}'").into());
}
}
}

self.session_source = SessionSource::DefaultCommand(command, self.options_multi("env"));
}

Expand Down Expand Up @@ -689,6 +699,10 @@ mod test {
&[
"--cmd",
"uname",
"--env",
"A=B",
"--env",
"C=D=E",
"--asterisks",
"--asterisks-char",
".",
Expand All @@ -704,7 +718,13 @@ mod test {
],
true,
Some(|greeter| {
assert!(matches!(&greeter.session_source, SessionSource::Command(cmd) if cmd == "uname"));
assert!(matches!(&greeter.session_source, SessionSource::DefaultCommand(cmd, Some(env)) if cmd == "uname" && env.len() == 2));

if let SessionSource::DefaultCommand(_, Some(env)) = &greeter.session_source {
assert_eq!(env[0], "A=B");
assert_eq!(env[1], "C=D=E");
}

assert!(matches!(&greeter.secret_display, SecretDisplay::Character(c) if c == "."));
assert_eq!(greeter.prompt_padding(), 0);
assert_eq!(greeter.window_padding(), 1);
Expand Down Expand Up @@ -735,6 +755,8 @@ mod test {
(&["--issue", "--greeting", "Hello, world!"], false, None),
(&["--kb-command", "F2", "--kb-sessions", "F2"], false, None),
(&["--time-format", "%i %"], false, None),
(&["--cmd", "cmd", "--env"], false, None),
(&["--cmd", "cmd", "--env", "A"], false, None),
];

for (opts, valid, check) in table {
Expand Down

0 comments on commit e0364aa

Please sign in to comment.