Under Construction
Check back soon for the first release of
Expect
v2
Expect
v2
Pre-Alpha
TODO
Text, List, Array only (no explicit support for numbers or files/paths/directories)
Filters
- Inspect
- Split
- Join
- First
- Last
- At Index
- Output
- Exitcode
- Stdout
- Stderr
Matchers
- Equal
- Empty
- Contain
- Wildcard
- Length
- Match
- Fail
- Succeed
Expect
v2
TODO
- Checked means that it’s done for text, list, int, number, array, path, file, and directory
Filters
- Inspect
- Size
- Split
- Join
- First
- Last
- At Index
- Lines
- Chars
- Uppercase
- Lowercase
+
-
/
x
- bc
- Output
- Exitcode
- Stdout
- Stderr
- Files
- Directories
- Entries
- File to Text
Matchers
- Equal
- Empty
- Contain
- Wildcard
- Length
- Truthy
- Falsy
- Match
- Starts With
- Ends With
- Fails
- Succeeds
- Exists
- Readable
- Writeable
- Executable
- Newer Than
- Older Than
- Pipe
- Socket
- Symlink
Non-Goals for v2
map
andeach
andwhere
won’t be supportedall
andany
won’t be supported for asserting all or any items in a collection- Built-in support for
startWith
asstartingWith
orstartsWith
won’t be availableNo support for combined words, aliases need to be created manually for
v2
🧐 Expect
Modern assertions for Shell Scripting in the 2020s
Download the latest version or install via:
curl -o- https://expect.specs.sh/install.sh | bash
Expectations for Everyone
Choose your own preferred syntax for test assertions:
output="$( ls dir 2>&1 )" # Example of a command that fails exitcode=$?
Classic-style Assertions
assertEquals 2 $exitcode assertContains "No such file or directory" "$output"
BASH-style Assertions
[: $exitcode -eq 2 ] [[: "$output" = "*No such file or directory*" ]]
expect
-style Assertions
expect { ls dir } to fail with exitcode = 2 \ and stdout containing "No such file or directory"
assertThat
-style Assertions
assertThat { ls dir } fails with exitcode = 2 \ and stdout contains "No such file or directory"
should
-style Assertions
:{ ls dir } should fail with exitcode = 2 \ and stdout containing "No such file or directory"
The Expect
library brings all of these lovely assertions styles that you love to BASH! 💖
All running on top of the same core code which provides lovely assertion failure messages.
Documentation
- Download / Install
- Getting Started
- Filters
- Matchers
- Common
- Text
- Command
- Files and Directories
- Custom
Download / Install
Download the latest version or install via:
curl -o- https://expect.specs.sh/install.sh | bash
Output
Expect 2.0.0 successfully installed 🧐 Downloaded files (and example syntax) » assertThat.sh - assertThat { ls } contains "assertThat.sh" » assertions.sh - assertContains "assertions.sh" "$( ls )" » brackets.sh - [[: "$( ls )" = "*brackets.sh*" ]] » expect.sh - expect { ls } to contain "expect.sh" » should.sh - :{ ls } should contain "should.sh" To get started, source any of the provided files in your tests. Visit https://expect.specs.sh for documentation
Getting Started
Filters
Expect
provides a number of built-in helper functions to allow expectations such as:
# Get the first line in a string
expect { cat README } lines first to contain "Hello"
# Split a string into a list using a separator
{{ "Hello, world!" }} uppercase split " " first should equal "HELLO,"
# Join a string from a list using
assertThat [ Hello World ] join ":" equals "Hello:World"
# Work with array variables
items=( A B C )
expect items array last to equal "C"
Built-in Helpers
Click or tap one of the options below for description and examples:
Array
... helloArray
... helloMatchers
Click or tap one of the options below for description and examples: