Skip to content

Commit

Permalink
Added from_file to TestBuilder and minor fix in if parser
Browse files Browse the repository at this point in the history
  • Loading branch information
prsabahrami committed Sep 28, 2024
1 parent 76cb033 commit 8b7dfd9
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 2 deletions.
2 changes: 1 addition & 1 deletion crates/deno_task_shell/src/grammar.pest
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ if_clause = !{
}

else_part = !{
Elif ~ conditional_expression ~ Then ~ complete_command ~ linebreak ~ else_part? |
Elif ~ conditional_expression ~ linebreak ~ Then ~ complete_command ~ linebreak ~ else_part? |
Else ~ linebreak ~ complete_command
}

Expand Down
11 changes: 11 additions & 0 deletions crates/tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -905,7 +905,18 @@ async fn if_clause() {
.assert_stdout("FOO is 1\n")
.run()
.await;

TestBuilder::new()
.from_file("../../scripts/if_else.sh")
.assert_exit_code(0)
.assert_stdout("FOO is 2\n")
.assert_stdout("FOO is 2\n")
.assert_stdout("FOO is 2\n")
.assert_stdout("FOO is 2\n")
.run()
.await;
}

#[cfg(test)]
fn no_such_file_error_text() -> &'static str {
if cfg!(windows) {
Expand Down
4 changes: 4 additions & 0 deletions crates/tests/src/test_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ impl TestBuilder {
self
}

pub fn from_file(&mut self, path: &str) -> &mut Self {
self.command(fs::read_to_string(path).unwrap().as_str())
}

pub fn stdin(&mut self, stdin: &str) -> &mut Self {
self.stdin = stdin.as_bytes().to_vec();
self
Expand Down
35 changes: 34 additions & 1 deletion scripts/if_else.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,41 @@
FOO=2
if [[ $FOO -eq 1 ]]; then
if [[ $FOO -eq 1 ]];
then
echo "FOO is 1";
elif [[ $FOO -eq 2 ]];
then
echo "FOO is 2";
else
echo "FOO is not 1 or 2";
fi

FOO=2
if [[ $FOO -eq 1 ]]; then
echo "FOO is 1"
elif [[ $FOO -eq 2 ]]; then
echo "FOO is 2"
else
echo "FOO is not 1 or 2"
fi

FOO=2
if [[ $FOO -eq 1 ]];
then
echo "FOO is 1";
elif [[ $FOO -eq 2 ]];
then
echo "FOO is 2";
else
echo "FOO is not 1 or 2";
fi

FOO=2
if [[ $FOO -eq 1 ]]
then
echo "FOO is 1";
elif [[ $FOO -eq 2 ]]
then
echo "FOO is 2";
else
echo "FOO is not 1 or 2";
fi

0 comments on commit 8b7dfd9

Please sign in to comment.