Skip to content

Commit

Permalink
first test for shellname module and typos correction
Browse files Browse the repository at this point in the history
  • Loading branch information
bexxmodd committed Jul 19, 2021
1 parent e70236c commit 15b79f1
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
14 changes: 8 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ fn execute_shell(shell_name: &mut ShellName) {
eprintln!("{}: command not found!", cmd);
}
} else {
// execute command that has no redirections
// execute command that has no redirection
let cmd = cmd_line.get_args();
if let Err(_) = process::Command::new(&cmd[0])
.args(&cmd[1..])
Expand All @@ -93,6 +93,8 @@ fn execute_shell(shell_name: &mut ShellName) {
}
}

/// Implementation of a Linux's `cd` command,
/// which stands for change directory.
pub fn change_directory(shell_name: &mut ShellName, line: &mut Tokenizer) {
let path = line.next();

Expand All @@ -116,7 +118,7 @@ pub fn change_directory(shell_name: &mut ShellName, line: &mut Tokenizer) {
}

/// If user supplies piped command this function splits it into
/// two processes, executes them and pipes one being intput to the pipe
/// two processes, executes them and pipes one being input to the pipe
/// and the other being output from the pipe, which ends up displayed
pub fn piped_cmd_execution(cmd_line: &mut Tokenizer) -> Result<(), io::Error> {
let mut tokens_before_pipe = cmd_line.commands_before_pipe();
Expand All @@ -132,7 +134,7 @@ pub fn piped_cmd_execution(cmd_line: &mut Tokenizer) -> Result<(), io::Error> {
process::Command::new(&after_pipe_cmd[0])
};

// check if we have any arguments othwerise execute command
// check if we have any arguments otherwise execute command
if after_pipe_cmd.len() > 0 {
proc.args(&after_pipe_cmd[1..]);
}
Expand All @@ -159,7 +161,7 @@ pub fn piped_cmd_execution(cmd_line: &mut Tokenizer) -> Result<(), io::Error> {
}

/// If the user command has stream redirection this function is used
/// to accomodate that. This is done by creating a redirection and returing
/// to accommodate that. This is done by creating a redirection and returning
/// a command which can then be spawned as a child processes
pub fn redirect_cmd_execution(cmd_line: &mut Tokenizer) -> Result<process::Command, io::Error> {
let mut redirection_count = [0; 2];
Expand Down Expand Up @@ -204,11 +206,11 @@ pub fn redirect_cmd_execution(cmd_line: &mut Tokenizer) -> Result<process::Comma
}
}

// check flags that we don't have excessive number of redirections
// check flags that we don't have excessive number of redirection
if redirection_count[0] > 1 || redirection_count[1] > 1 {
return Err(io::Error::new(
io::ErrorKind::InvalidInput,
"Invalid instructions for redication",
"Invalid instructions for redirection",
));
}

Expand Down
11 changes: 11 additions & 0 deletions src/shellname.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,14 @@ fn build_user_minishell() -> String {

username
}

#[cfg(test)]
mod test {
use super::*;

#[test]
fn generate_shellname() {
let sh = ShellName::new("home");
assert_eq!("home".to_string(), sh.current_dir);
}
}
2 changes: 1 addition & 1 deletion src/tokenizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub struct Tokenizer {
}

impl Tokenizer {
/// constractor
/// constructor
pub fn new(line: &str) -> Self {
Tokenizer {
current: Some(line.to_string()),
Expand Down

0 comments on commit 15b79f1

Please sign in to comment.