[test] fix golden tests

Also, fix README since we merged tasty/hspec tests recently.
parent 7c5ddfa4
Pipeline #7740 passed with stages
in 60 minutes and 52 seconds
...@@ -196,7 +196,7 @@ Here are some tips: ...@@ -196,7 +196,7 @@ Here are some tips:
* Lock the hackage-index state in the `cabal.project`, so that the * Lock the hackage-index state in the `cabal.project`, so that the
solver won't try to pull newer dependencies; solver won't try to pull newer dependencies;
* Specify constraints you want directly when building like `cabal * Specify constraints you want directly when building like `cabal
v2-build --constraint tasty==x.y.z.w` v2-build --constraint hspec==x.y.z.w`
* Generate another `.freeze` with `cabal v2-freeze` once you got the * Generate another `.freeze` with `cabal v2-freeze` once you got the
new build to compile (this is good for small, incremental upgrades) new build to compile (this is good for small, incremental upgrades)
* Bounds in `.cabal` are definitely respected, but ofc the `.freeze` * Bounds in `.cabal` are definitely respected, but ofc the `.freeze`
...@@ -250,16 +250,9 @@ Or, from "outside": ...@@ -250,16 +250,9 @@ Or, from "outside":
$ nix-shell --run "cabal v2-test --test-show-details=streaming" $ nix-shell --run "cabal v2-test --test-show-details=streaming"
``` ```
If you want to run particular tests, use (for Tasty): If you want to run particular tests, use:
```shell
cabal v2-test garg-test-tasty --test-show-details=streaming --test-option=--pattern='/job status update and tracking/
```
or (for Hspec):
```shell ```shell
cabal v2-test garg-test-hspec --test-show-details=streaming --test-option=--match='/Dispatcher, Central Exchange, WebSockets/' cabal v2-test garg-test --test-show-details=streaming --test-option=--match='/job status update and tracking/
``` ```
### CI ### CI
...@@ -447,7 +440,6 @@ a useful `:ggload` macro that imports all exposed modules from the ...@@ -447,7 +440,6 @@ a useful `:ggload` macro that imports all exposed modules from the
## Running the tests <a name="running-tests"></a> ## Running the tests <a name="running-tests"></a>
Running the tests can be done via the following command: Running the tests can be done via the following command:
```shell ```shell
cabal v2-test --test-show-details=streaming --flags 'test-crypto no-phylo-debug-logs' cabal v2-test --test-show-details=streaming --flags 'test-crypto no-phylo-debug-logs'
``` ```
...@@ -458,28 +450,22 @@ The flags have the following meaning: ...@@ -458,28 +450,22 @@ The flags have the following meaning:
faster; faster;
* `no-phylo-debug-logs`: Suppresses the debugging logs which would normally be present in phylo pure (!) code. * `no-phylo-debug-logs`: Suppresses the debugging logs which would normally be present in phylo pure (!) code.
In order for some tests to run (like the phylo ones) is **required** to install the `gargantext-cli` via: **NOTE**: Using the above flags will cause rebuild, if you just build with `cabal v2-build`. Run with:
```shell
cabal v2-install gargantext:exe:gargantext
```
For tasty, if you want to run specific test (via patterns), use:
```shell ```shell
cabal v2-run garg-test-tasty -- -p '/Ngrams/ cabal v2-test --test-show-details=streaming
``` ```
so you don't rebuild.
For integration tests, do: If you want to run specific test (via patterns), use:
```shell ```shell
cabal v2-test garg-test-hspec --test-show-details=streaming --test-option=--match='/some pattern/' cabal v2-run garg-test --test-show-details=streaming --test-option=--match='/Ngrams/'
``` ```
You could also use [ghciwatch](https://mercurytechnologies.github.io/ghciwatch/) for testsing: You could also use [ghciwatch](https://mercurytechnologies.github.io/ghciwatch/) for testsing:
```shell ```shell
ghciwatch --command "cabal v2-repl garg-test-tasty" --after-startup-ghci ':set args "--pattern" "/Ngrams/"' --after-startup-ghci "Main.main" --after-reload-ghci "Main.main" --watch src --watch test ghciwatch --command "cabal v2-repl garg-test" --after-startup-ghci ':set args "--match" "/Ngrams/"' --after-startup-ghci "Main.main" --after-reload-ghci "Main.main" --watch src --watch test
``` ```
### Modifying a golden test to accept a new (expected) output ### Modifying a golden test to accept a new (expected) output
...@@ -487,11 +473,16 @@ ghciwatch --command "cabal v2-repl garg-test-tasty" --after-startup-ghci ':set a ...@@ -487,11 +473,16 @@ ghciwatch --command "cabal v2-repl garg-test-tasty" --after-startup-ghci ':set a
Some tests, like the Phylo one, use golden testing to ensure that the JSON Phylo we generate is Some tests, like the Phylo one, use golden testing to ensure that the JSON Phylo we generate is
the same as an expected one. This allows us to catch regressions in the serialisation or in the algorithm. the same as an expected one. This allows us to catch regressions in the serialisation or in the algorithm.
Sometimes, however, we genuinely want to modify the output so that it's the new reference (i.e. the new Sometimes, however, we genuinely want to modify the output so that it's the new reference (i.e. the new
golden reference). To do so, it's enough to run the testsuite passing the `--accept` flag, for example: golden reference).
If you do want to update the output, go to `test/Test/Offline/Phylo.hs` and set `doUpdateGolden = True`.
Run tests:
```shell ```shell
cabal v2-test garg-test-tasty --test-show-details=streaming --flags 'test-crypto no-phylo-debug-logs' --test-option=--pattern='/Phylo/' --test-option=--accept cabal v2-test garg-test --test-show-details=streaming --test-option=--match='/Phylo/'
``` ```
The second time you run tests, they should pass.
**Don't forget to set `doUpdateGolden = False` after updating the golden files!**
# Async workers <a name="async-workers"></a> # Async workers <a name="async-workers"></a>
......
This diff is collapsed.
This diff is collapsed.
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
module Test.Offline.Phylo (tests) where module Test.Offline.Phylo (tests) where
import CLI.Phylo.Common ( fileToList, fileToDocsDefault ) import CLI.Phylo.Common ( fileToList, fileToDocsDefault )
import Control.Monad (when)
import Data.Aeson as JSON import Data.Aeson as JSON
import Data.Aeson.Encode.Pretty qualified as JSON import Data.Aeson.Encode.Pretty qualified as JSON
import Data.Aeson.Types qualified as JSON import Data.Aeson.Types qualified as JSON
...@@ -29,6 +30,12 @@ import Test.HUnit ...@@ -29,6 +30,12 @@ import Test.HUnit
import Test.Hspec import Test.Hspec
import Test.Hspec.Golden import Test.Hspec.Golden
-- | Switch to 'True' if you want to update golden tests
doUpdateGolden :: Bool
doUpdateGolden = False
phyloTestConfig :: PhyloConfig phyloTestConfig :: PhyloConfig
phyloTestConfig = PhyloConfig { phyloTestConfig = PhyloConfig {
corpusPath = "corpus.csv" corpusPath = "corpus.csv"
...@@ -58,7 +65,7 @@ phyloGolden (fp, actualOutput) = ...@@ -58,7 +65,7 @@ phyloGolden (fp, actualOutput) =
Golden { Golden {
output = actualOutput output = actualOutput
, encodePretty = C8.unpack . BIO.toStrict , encodePretty = C8.unpack . BIO.toStrict
, writeToFile = \_ _ -> pure () , writeToFile = if doUpdateGolden then \_ new' -> BL.writeFile fp new' else (\_ _ -> pure ())
, readFromFile = BIO.readFile , readFromFile = BIO.readFile
, goldenFile = fp , goldenFile = fp
, actualFile = Nothing , actualFile = Nothing
...@@ -156,6 +163,7 @@ testSmallPhyloWithoutLinkExpectedOutput = do ...@@ -156,6 +163,7 @@ testSmallPhyloWithoutLinkExpectedOutput = do
mapList mapList
let actual = setConfig phyloTestConfig $ toPhyloWithoutLink corpus config let actual = setConfig phyloTestConfig $ toPhyloWithoutLink corpus config
expected <- setConfig phyloTestConfig <$> (readPhylo =<< getDataFileName "test-data/phylo/small-phylo.golden.json") expected <- setConfig phyloTestConfig <$> (readPhylo =<< getDataFileName "test-data/phylo/small-phylo.golden.json")
when doUpdateGolden $ BL.writeFile "test-data/phylo/small-phylo.golden.json" (JSON.encodePretty actual)
assertBool (show $ ansiWlEditExprCompact $ ediff expected actual) (expected == actual) assertBool (show $ ansiWlEditExprCompact $ ediff expected actual) (expected == actual)
testPhylo2dot2json :: IO (FilePath, GraphDataFuzzy) testPhylo2dot2json :: IO (FilePath, GraphDataFuzzy)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment