kward / shunit2

shUnit2 is a xUnit based unit test framework for Bourne based shell scripts.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Is alias supported in setUp?

gqqnbig opened this issue · comments

commented
#!/bin/bash

oneTimeSetUp() {
  alias hello='echo hello'
}

testMakeNewSale() {
  hello
}

source shunit2

I run it by ./makeNewSaleTest.sh. The error is

testMakeNewSale
./makeNewSaleTest.sh: line 14: hello: command not found
shunit2:ERROR testMakeNewSale() returned non-zero return code.

Ran 1 test.

FAILED (failures=0)

Is alias supported in setUp/oneTimeSetUp?

shunit2 version is master (47be8b2).

alias is not supported within shell scripts, only on the command-line.

An alternative solution to what you are trying might be:

#!/bin/bash

oneTimeSetUp() {
  hello='echo hello'
}

testMakeNewSale() {
  ${hello}  # hello is a variable, and its value must be retrieved as such.
}

source shunit2