Closed ornamentist closed 3 years ago
Hi there!
To "get started", you just need the one file called Spec.hs
with this line and nothing else:
{-# OPTIONS_GHC -F -pgmF sydtest-discover #-}
That'll give you a main = sydTest spec
in that file, where spec
is also defined in that file as the collection of all test suites in the test dir.
IF you want to use sydtest with your own options (sydTestWith
), you can instead put this in Spec.hs
but still nothing else:
{-# OPTIONS_GHC -F -pgmF sydtest-discover -optF --no-main #-}
This will then only generate a spec
, but no main
so that you can write your own main
in a separate module.
The point of sydtest-discover
is that you don't have to combine top-level spec
s anywhere, you can just use the one that's generated in the Spec
module.
You can find examples here: https://github.com/NorfairKing/smos/blob/release/smos-data-gen/test/Spec.hs
Does that answer your question?
Yep -- now I see my misunderstandings.
That example was very useful thanks.
Once I have a conforming Spec.hs and project.cabal file I should be able to do a cabal test {test suite name}
and sydtest-discover
will do the discovery/generate stage and cabal will run those generated tests?
@ornamentist I have no idea how cabal works but stack just does it all correctly for you yes.
I might have to move to Stack, as Cabal is not finding the tests.
I'd like to clone and build that example test suite ( https://github.com/NorfairKing/smos/blob/release/smos-data-gen) to see a working package in operation. Do I need to use nix or some other tool before doing a stack test
on it?
Do I need to use nix or some other tool before doing a stack test on it?
You can follow this guide: https://docs.smos.online/installation/stack
Could I summarize and clarify the file names and conventions needed to use
sydtest-discover
?With this stack setup:
I need to add this line to
test/Spec.hs
:Then when I run
stack test
(or in my casecabal test
)sydtest-discover
will find source files in thetest
directory tree matching*Spec.hs
and include them in the test run?if I need a custom test
main
, then I need to add to each test file intest/**.hs
the line:And also change
main: Spec.hs
in the stack/cabal settings to sayMain.hs
. In that file I can doWhere
Spec.hs
is a file in thetest
directory. If I need multiple test files in thetest
directory then I need to combine their top-level exportedspec
values in theMain
module in some way?And many also thanks for creating a such a comprehensive testing framework!