haskell / cabal

Official upstream development repository for Cabal and cabal-install
https://haskell.org/cabal
Other
1.6k stars 690 forks source link

Hspec support request #9343

Open peterbecich opened 10 months ago

peterbecich commented 10 months ago

Describe the feature request I have a feature request in Hspec to make it easier to run specific tests with Cabal: https://github.com/hspec/hspec/issues/862

Hspec needs to know if it is run by Cabal.

@sol suggests this can be implemented if cabal test sets the environment variable CABAL_TEST_COMMAND=cabal

Additional context

Currently a failing test will print:

To rerun use: --match "/someFailingTest/"

To use this suggestion with Cabal, it must be modified to this:

cabal test --test-options="--match \"/someFailingTest/\""

With this environment variable, Hspec will print out this feedback for Cabal.

Bodigrim commented 10 months ago

Why could not hspec determine its parent process? E. g., https://hackage.haskell.org/package/unix-2.8.3.0/docs/System-Posix-Process-ByteString.html#v:getParentProcessID.

geekosaur commented 10 months ago

Finding its ppid is POSIX-portable; finding out anything about its parent isn't (/proc doesn't always exist and when it does isn't necessarily Linux-compatible).

geekosaur commented 10 months ago

Also note that Windows is a wildcard here.

Bodigrim commented 10 months ago

True, and nevertheless pretty much every OS provides means to determine a parent process. We might lack a crossplatform Haskell library to do this reliably, in which case it would be better to write one instead of establishing an ad-hoc communication channel between cabal and hspec. (But I've been just passing by, nevermind)

gbaz commented 10 months ago

note that running a testsuite already does affect the environment, in that it ensures datadir is set. Testing for this is slightly ad-hoc as opposed to a distinguished variable, but it has the great advantage of already existing and working!

https://github.com/haskell/cabal/blob/9f373253b9032ae32ead9f5ca17e49d192f9b8b9/Cabal/src/Distribution/Simple/Test/ExeV10.hs#L87

andreabedini commented 10 months ago

@peterbecich a totally under-engineered option is to expand the message to the user:

To rerun use: --match "/someFailingTest/".
If you are using cabal use: cabal test --test-options="--match \"/someFailingTest/\""

(maybe --test-options='--match "/someFailingTest/"' would also work?)