You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When I develop executables as part of a Haskell project, I have to do and repeat some manual tests to ensure that the executable behaviour is correct (e.g. status code, error message, output ...). This is tedious, and I think it could be automated nicely with shelltestrunner.
My proposal would be to support shelltestrunner in Cabal file as a test-suite.
Example of a Cabal test-suite with shelltestrunner support:
FWIW, I do basically the same thing now (this is my ShellTests.hs):
moduleMainwhereimportSystem.Process (
CreateProcess( env ),
createProcess,
shell,
waitForProcess )
importSystem.Exit ( exitWith )
main::IO()
main =do-- Get a CreateProcess object corresponding to our shell command.let createproc = shell "shelltest test/shell/*.test"-- But clear its environment before running the command.let empty_env_createproc = createproc { env =Just[] }
-- Ignore stdin/stdout/stderr...
(_,_,_,hproc) <- createProcess empty_env_createproc
-- Now run the ProcessHandle and exit with its result.
result <- waitForProcess hproc
exitWith result
Granted that yours looks a lot nicer. Depending on libraries with cabal works a lot better than depending on executables, too. For example, hackage can't tell you that my project depends on "the shelltest executable being in $PATH".
Yep, still using it, but struggling to remember what this issue is about =)
I think all the original report is asking for is a way to "do what the shelltest program would do," but within a library function. If there was a shelltest function provided by a library under Test.ShellTest, then you could use the sample code in the first comment rather than the real code in my previous comment.
Here's a sketch:
Refactor the bulk of shelltest's main function into Test.ShellTest.shelltest
Update shelltest's main to call that new function.
Ship Test.ShellTest as a public library.
Then anyone who wants to use shelltest as part of a cabal test suite can call the library function instead of the executable (which is a bit more trouble).
Ah, build-tool-depends does indeed solve half of the problem. I am somehow just learning about it today. But keep in mind that this issue predates cabal-2.0 =)
Using system "shelltestrunner" isn't a great solution though. It's not really portable -- you have to feed it a command that will work on every possible shell, including Windows' cmd.exe -- and it's also a bit inefficient in that it creates a whole new shell process (sourcing .rc files and whatnot) to launch the command.
With shelltestrunner, I usually have multiple .test files in some subdirectory of tests/. What I'd like to do is to use a portable solution to find them all...
Activity
simonmichael commentedon Dec 30, 2017
Sounds nice! Would you like to make a start on it ?
fmind commentedon Jan 10, 2018
At the moment, the whole project is in one file.
I would need to split it into an executable and a library.
Do you think it makes sense ? Is it something acceptable ?
simonmichael commentedon Jan 10, 2018
orlitzky commentedon Jan 26, 2018
FWIW, I do basically the same thing now (this is my ShellTests.hs):
Granted that yours looks a lot nicer. Depending on libraries with cabal works a lot better than depending on executables, too. For example, hackage can't tell you that my project depends on "the shelltest executable being in
$PATH".simonmichael commentedon Oct 19, 2020
Thanks for this idea back in 2017. Are you still using it ? Is there anything we need to do here ?
simonmichael commentedon Oct 19, 2020
Perhaps add as a reproducible cookbook example to the https://github.com/simonmichael/shelltestrunner/blob/master/README.md ?
orlitzky commentedon Oct 19, 2020
Yep, still using it, but struggling to remember what this issue is about =)
I think all the original report is asking for is a way to "do what the shelltest program would do," but within a library function. If there was a
shelltestfunction provided by a library underTest.ShellTest, then you could use the sample code in the first comment rather than the real code in my previous comment.Here's a sketch:
mainfunction intoTest.ShellTest.shelltestmainto call that new function.Test.ShellTestas a public library.Then anyone who wants to use shelltest as part of a cabal test suite can call the library function instead of the executable (which is a bit more trouble).
simonmichael commentedon Oct 19, 2020
Ah, so make shelltestrunner usable as a haskel library ? That I can understand, thanks for clarifying. I agree this could be useful.
andreasabel commentedon Nov 13, 2021
In general, an executable can be used in a testsuite by
cabal testif it is declared as build dependency.For an example, testing "myself" (
agda2lagda) usinggoldplate, see: https://github.com/andreasabel/agda2lagda/blob/93d317c87bddf973e3fa6abd5bf24dcfa9a797f0/agda2lagda.cabal#L104-L115So, add
build-tool-depends: shelltestrunner:shelltestrunnerto the testsuite stanza. Then you cansystem "shelltestrunner" ...in the Main of the testsuite. (Example: https://github.com/andreasabel/agda2lagda/blob/93d317c87bddf973e3fa6abd5bf24dcfa9a797f0/test/Tests.hs#L5)orlitzky commentedon Nov 13, 2021
Ah, build-tool-depends does indeed solve half of the problem. I am somehow just learning about it today. But keep in mind that this issue predates cabal-2.0 =)
Using
system "shelltestrunner"isn't a great solution though. It's not really portable -- you have to feed it a command that will work on every possible shell, including Windows' cmd.exe -- and it's also a bit inefficient in that it creates a whole new shell process (sourcing.rcfiles and whatnot) to launch the command.With shelltestrunner, I usually have multiple
.testfiles in some subdirectory oftests/. What I'd like to do is to use a portable solution to find them all...and then test them within the same process, without involving an OS shell at all, e.g. (in pseudocode):
orlitzky commentedon Nov 29, 2021
This was premature ☠️
The "configure" phase happily proceeds when the required
build-tool-dependsare missing. In this case...returns success (zero) on the command-line, rather than dying immediately as it would if a required library were absent.
andreasabel commentedon Nov 29, 2021
I have not tested this since I am always using the
cabalcommand. Is there an issue on this problem in the cabal issue tracker?orlitzky commentedon Nov 29, 2021
This one is similar in spirit: haskell/cabal#5464