#![allow(deprecated)]
#![allow(clippy::unwrap_used)] #![allow(clippy::expect_used)]
use assert_cmd::Command;
use predicates::prelude::*;
fn bashrs_repl() -> Command {
let mut cmd = assert_cmd::cargo_bin_cmd!("bashrs");
cmd.arg("repl");
cmd
}
#[test]
fn test_repl_008_001_echo_simple() {
bashrs_repl()
.write_stdin("echo hello\nquit\n")
.assert()
.success()
.stdout(predicate::str::contains("hello"));
}
#[test]
fn test_repl_008_001_echo_multiple_args() {
bashrs_repl()
.write_stdin("echo hello world\nquit\n")
.assert()
.success()
.stdout(predicate::str::contains("hello world"));
}
#[test]
fn test_repl_008_001_pwd() {
bashrs_repl()
.write_stdin("pwd\nquit\n")
.assert()
.success()
.stdout(predicate::str::contains("/"));
}
#[test]
fn test_repl_008_001_date() {
bashrs_repl()
.write_stdin("date +%Y\nquit\n")
.assert()
.success()
.stdout(predicate::str::contains("202")); }
#[test]
fn test_repl_008_001_execute_with_variables() {
bashrs_repl()
.write_stdin("greeting=hello\necho $greeting\nquit\n")
.assert()
.success()
.stdout(predicate::str::contains("Variable set"))
.stdout(predicate::str::contains("hello"));
}
#[test]
fn test_repl_008_001_execute_multiple_variables() {
bashrs_repl()
.write_stdin("x=foo\ny=bar\necho $x $y\nquit\n")
.assert()
.success()
.stdout(predicate::str::contains("foo bar"));
}
#[test]
fn test_repl_008_001_execute_braced_variable() {
bashrs_repl()
.write_stdin("name=Alice\necho Hello ${name}!\nquit\n")
.assert()
.success()
.stdout(predicate::str::contains("Hello Alice!"));
}
#[test]
fn test_repl_008_001_nonexistent_command() {
bashrs_repl()
.write_stdin("nonexistent_command_xyz\nquit\n")
.assert()
.success() .stdout(predicate::str::contains("not found").or(predicate::str::contains("No such")));
}
#[test]
fn test_repl_008_001_command_error() {
bashrs_repl()
.write_stdin("ls /nonexistent_directory_xyz\nquit\n")
.assert()
.success() .stdout(predicate::str::contains("No such file"));
}
#[test]
fn test_repl_008_001_multiple_commands() {
bashrs_repl()
.write_stdin("echo first\necho second\necho third\nquit\n")
.assert()
.success()
.stdout(predicate::str::contains("first"))
.stdout(predicate::str::contains("second"))
.stdout(predicate::str::contains("third"));
}
#[test]
fn test_repl_008_001_pipe_command() {
bashrs_repl()
.write_stdin("echo hello world | head -1\nquit\n")
.assert()
.success()
.stdout(predicate::str::contains("hello world"));
}
#[test]
fn test_repl_008_001_mode_switching() {
bashrs_repl()
.write_stdin(":mode normal\necho test\n:mode purify\nmkdir /tmp/test\nquit\n")
.assert()
.success()
.stdout(predicate::str::contains("test"))
.stdout(predicate::str::contains("Purified"));
}
#[test]
fn test_repl_008_001_normal_after_lint() {
bashrs_repl()
.write_stdin(":mode lint\ncat file | grep x\n:mode normal\necho back to normal\nquit\n")
.assert()
.success()
.stdout(predicate::str::contains("back to normal"));
}
#[test]
fn test_repl_008_001_stdout_capture() {
bashrs_repl()
.write_stdin("echo 'Line 1'\necho 'Line 2'\necho 'Line 3'\nquit\n")
.assert()
.success()
.stdout(predicate::str::contains("Line 1"))
.stdout(predicate::str::contains("Line 2"))
.stdout(predicate::str::contains("Line 3"));
}
#[test]
fn test_repl_008_001_empty_output() {
bashrs_repl().write_stdin("true\nquit\n").assert().success();
}
#[test]
fn test_repl_008_001_complete_workflow() {
bashrs_repl()
.write_stdin("version=1.0.0\necho Release: $version\n:vars\nquit\n")
.assert()
.success()
.stdout(predicate::str::contains("Variable set"))
.stdout(predicate::str::contains("Release: 1.0.0"))
.stdout(predicate::str::contains("version"));
}
#[test]
fn test_repl_008_001_execute_after_history() {
bashrs_repl()
.write_stdin("echo test1\necho test2\n:history\necho test3\nquit\n")
.assert()
.success()
.stdout(predicate::str::contains("test1"))
.stdout(predicate::str::contains("test2"))
.stdout(predicate::str::contains("Command History"))
.stdout(predicate::str::contains("test3"));
}
#[test]
fn test_repl_008_001_special_characters() {
bashrs_repl()
.write_stdin("echo 'hello!@#$%'\nquit\n")
.assert()
.success()
.stdout(predicate::str::contains("hello!@#$%"));
}