Git Product home page Git Product logo

Comments (8)

felipec avatar felipec commented on July 29, 2024 1

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.

LeSpocky avatar LeSpocky commented on July 29, 2024

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.

felipec avatar felipec commented on July 29, 2024

@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.

LeSpocky avatar LeSpocky commented on July 29, 2024

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.

felipec avatar felipec commented on July 29, 2024

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.

LeSpocky avatar LeSpocky commented on July 29, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.