torokmark / assert.sh Goto Github PK
View Code? Open in Web Editor NEW:exclamation: Assertion lib for shell script users
Home Page: https://torokmark.github.io/assert.sh
License: MIT License
:exclamation: Assertion lib for shell script users
Home Page: https://torokmark.github.io/assert.sh
License: MIT License
Example of an undefined behavior:
my_funcs.sh
#!/usr/bin/env bash
log_success() {
echo "another log_success() function from $BASH_SOURCE file that behaves differently"
}
test.sh
#!/usr/bin/env bash
source assert.sh # this file contains `log_success` function
source my_funcs.sh # this file also contains `log_success` function
# Example from README
expected="Hello"
actual="Hello"
assert_eq "$expected" "$actual"
if [ "$?" == 0 ]; then
log_success "assert_eq returns 0 if two words are equal"
else
log_failure "assert_eq should return 0"
fi
Output:
$ ./test.sh
another log_success() function from my_funcs.sh file that behaves differently
To fix this the tester will be forced to rename all files where log_success
function is used.
In advanced and much complex languages this is solved by using namespace mechanism. Since bash does not have something simillar we can craft namespaces simply by appending postfixes. I offer something like this to make the name as unique as possible:
log_success__torokmark () {
...
}
It is still comfortable when using any editor with an autocomplete engine.
Same story with tput codes inside variables with kinda generic names...
Lines 23 to 27 in a845148
If the haystack is empty
, the assert_contain
/ assert_not_contain
return unexpected results:
Method | Haystack | Needle | Exit Code |
---|---|---|---|
assert_contain |
"" | needle |
0 |
assert_not_contain |
"" | needle |
1 |
Implying "" contains needle
.
Hello,
assert_not_empty
uses third parameter as message but second one seems not used (https://github.com/torokmark/assert.sh/blob/master/assert.sh#L188)
This prevent assert_not_empty
function to be written as follow
assert_not_empty "my string" "This is the message"
And must be written with a second empty parameter, exactly like assert_not_eq
assert_not_empty "my string" "" "This is the message"
root@xiaorui:~# assert_true false "cause error"
root@xiaorui:~# echo $?
1
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.