Comments (8)
I use zsh.
I see.
I cloned your example and it indeed failed with zsh (when SHARNESS_TEST_SRCDIR
is not manually set). The problem seems to be that when zsh support was added (in 00cb93e) that changed the semantics if $0
.
I've pushed a fix for this, so SHARNESS_TEST_SRCDIR
should be set correctly by default in zsh too.
I presume this should fix the situation for your use case.
I still think the variable should be renamed to SHARNESS_SRCDIR
though.
from sharness.
I think the problem is, I'm not running sharness from bash. For reference see the commit message of 0bc8705 where @felipec explains it already.
There seems to be no easy portable solution to this. Every shell needs its own approach. The best I could find where ideas from this lengthy stackoverflow discussion: https://unix.stackexchange.com/q/4650
from sharness.
@LeSpocky The commit 0bc8705 explains how this feature works automatically if you are running bash, prior to v1.2.0 the documentation said that you had to manually set SHARNESS_TEST_SRCDIR
.
Your script needs to set SHARNESS_TEST_SRCDIR
, then include $SHARNESS_TEST_SRCDIR/sharness.sh
, which will include $SHARNESS_TEST_SRCDIR/lib-sharness/functions.sh
automatically.
This was the case before v1.2.0 for all shells, now it's only for shells that are not bash (or zsh). I presume your script isn't doing that.
from sharness.
Okay, I build a simple case to reproduce this and put it here: https://github.com/LeSpocky/sharness-issue-124
The initial commit shows what I was trying before, the second one follows your suggestion. Output before:
adahl@ada ../data/adahl/src/tmp/sharness-issue-124 (git)-[master] % sh ./simple.t
./simple.t: 7: test_set_prereq: not found
ok 1 - Simple successful test
# passed all 1 test(s)
1..1
adahl@ada ../data/adahl/src/tmp/sharness-issue-124 (git)-[master] % zsh ./simple.t
./simple.t:7: command not found: test_set_prereq
ok 1 - Simple successful test
# passed all 1 test(s)
1..1
adahl@ada ../data/adahl/src/tmp/sharness-issue-124 (git)-[master] % bash ./simple.t
ok 1 - Simple successful test
# passed all 1 test(s)
1..1
Afterwards everything is fine. In my opinion the underlying problem is a documentation issue. See this section from API.md:
SHARNESS_TEST_SRCDIR
Public: Source directory of test code and sharness library. This directory may be different
from the directory in which tests are being run.
This is not the directory a user would put test code in. It's the directory of the sharness source code. The word "TEST" in variable name and "test code" in explanation is misleading here! Also: there's a hint missing, that you MUST set this, if you don't put your tests in the sharness directory.
from sharness.
This is not the directory a user would put test code in. It's the directory of the sharness source code. The word "TEST" in variable name and "test code" in explanation is misleading here!
Right. It should probably be called SHARNESS_SRCDIR
.
And the documentation should say "Source directory of the sharness library".
Also: there's a hint missing, that you MUST set this, if you don't put your tests in the sharness directory.
Well, if you if you don't use bash or zsh. I think most people use bash or zsh, so most people don't need to set this.
So, perhaps the documentation should say it's a good practice to set this variable, but not strictly necessary in most cases.
from sharness.
Well, if you if you don't use bash or zsh. I think most people use bash or zsh, so most people don't need to set this.
I use zsh. And as you can see in my example output above, setting the variable is needed in zsh, otherwise you get the error. The hack which works for bash doesn't seem to do in zsh. Here the line with the error shown again, when run in zsh without setting the variable:
adahl@ada ../data/adahl/src/tmp/sharness-issue-124 (git)-[master] % zsh ./simple.t
./simple.t:7: command not found: test_set_prereq
ok 1 - Simple successful test
# passed all 1 test(s)
1..1
from sharness.
Related Issues (20)
- SHARNESS_TEST_SRCDIR and extensions HOT 3
- Sharness self-test fails HOT 2
- Can't locate object method "follower" via package "IO::Pty"
- test_expect_failure test 2 = 2 does not fail with prove HOT 4
- trash dir as home dir when run on Windows HOT 1
- testing scripts with sourced functions HOT 1
- Make a release v1.2 HOT 1
- Usage with `prove` would need more documentation HOT 6
- make test fails with unliked SHELL_PATH HOT 9
- add --tee option from git test-lib.sh HOT 1
- sharness.sh is executable? HOT 3
- Release tarballs are not signed HOT 4
- Clarify purpose of "aggregate-results.sh" HOT 12
- Cleanup actions are only run if no tests failed HOT 8
- Additional test function for string comparison? HOT 5
- Document usage of "trash" directory HOT 2
- Document how to release a new Sharness version HOT 2
- Line feed regression HOT 3
- Lots of dangling branches HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sharness.