You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#!/usr/bin/env bashlog_success() {
echo"another log_success() function from $BASH_SOURCE file that behaves differently"
}
test.sh
#!/usr/bin/env bashsource assert.sh # this file contains `log_success` functionsource 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...
Example of an undefined behavior:
my_funcs.sh
test.sh
Output:
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...
assert.sh/assert.sh
Lines 23 to 27 in a845148
The text was updated successfully, but these errors were encountered: