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

not sure how to source another file #37

Open
binaryphile opened this issue Nov 5, 2014 · 2 comments
Open

not sure how to source another file #37

binaryphile opened this issue Nov 5, 2014 · 2 comments

Comments

@binaryphile
Copy link

None of the examples show how to source a file into the test file, say for testing a set of functions.

I tried simply using "source ../lib/functions.sh" at the start of the test script, but got "/usr/local/bin/roundup: 3: ./functions-test.sh: source: not found".

Changing the line to ". ../lib/functions.sh" got further, but errored with:

". ../lib/functions.sh

  • function myfunc {
    /usr/local/bin/roundup: 3: ../lib/functions.sh: function: not found"

I also tried adding both of these to a before() call, but neither worked.

How are you supposed to source functions for testing when they're defined in other files?

@bmizerany
Copy link
Owner

roundup runs in /tmp. You need to source the explicit path. I'm not sure what the best way to do this is. Sorry.

@paulwib
Copy link

paulwib commented Apr 22, 2015

There are various ways you can get the directory of the test file itself so you can source scripts in relative paths. One that works for me is:

TEST_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants