Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test-syntax.jade: Update run' helper and add evl' helper #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion docs/writing-tests/test-syntax.jade
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,14 @@ block docs-content

Each line of the output is also stored in the `$lines` array, allowing you to run assertions against individual lines.

The command can use complex constructs like `;`, `|`, `||`, `&&`, redirections, etc. but they should be quoted.

feature.bump
:marked
```zunit
@test 'Test command output' {
# Run the command, including arguments
run ls ~/my-dir
run ls ~/my-dir \| head -n 3

assert $state equals 0

Expand All @@ -107,6 +109,35 @@ block docs-content
}
```

section
:marked
### Evaluating code

With the use of the eval-like `evl` helper you can run e.g. functions and test for various side-effects, like a value of a global parameter. So it not only allows you to make assertions on its exit status and output, but also on the changed state of Zshell.

Like with the `run` helper, the command's exit code is stored in the `$state` variable.

The full output of the command is stored in `$output`.

Each line of the output is also stored in the `$lines` array, allowing you to run assertions against individual lines.

The command can use complex constructs like `;`, `|`, `||`, `&&`, redirections, etc. but they should be quoted.

feature.bump
:marked
```zunit
@test 'Test command output' {
# Run the function through eval
# It returns in $reply array
evl a-function-returning-in-reply arg1 arg2

assert $state equals 0

assert "${reply[1]}" equals 'my-answer-1'
assert "${reply[2]}" equals 'my-answer-2'
}
```

section
:marked
### Skipping tests
Expand Down