Commit 8d07ed51 authored by Alfredo Di Napoli's avatar Alfredo Di Napoli

Port golden-file-diff to CLI

parent a4c1fbec
module Main where module CLI.FileDiff where
import Prelude import CLI.Types
import Data.List qualified as L
import Data.Text qualified as T
import Data.Text.IO qualified as TIO
import Data.TreeDiff.Class import Data.TreeDiff.Class
import Data.TreeDiff.Pretty import Data.TreeDiff.Pretty
import qualified Data.Text as T import Gargantext.Prelude (HasCallStack, unless, exitFailure)
import qualified Data.Text.IO as TIO import Options.Applicative
import System.Environment (getArgs) import Prelude
import System.Exit (exitFailure)
import Control.Monad (unless)
import qualified Data.List as L
-- | Renders in a pretty way the content of two golden files. The -- | Renders in a pretty way the content of two golden files. The
-- first file should contain the expected output, the second the -- first file should contain the expected output, the second the
-- actual data generated by the test suite. -- actual data generated by the test suite.
main :: IO () fileDiffCLI :: GoldenFileDiffArgs -> IO ()
main = do fileDiffCLI (GoldenFileDiffArgs refPath newPath) = do
(refPath:newPath:_) <- getArgs
ref <- T.lines <$> TIO.readFile refPath ref <- T.lines <$> TIO.readFile refPath
new <- T.lines <$> TIO.readFile newPath new <- T.lines <$> TIO.readFile newPath
...@@ -25,3 +24,17 @@ main = do ...@@ -25,3 +24,17 @@ main = do
unless (L.null differences) $ do unless (L.null differences) $ do
putStrLn $ show $ ansiWlEditExpr $ ediff' (map fst differences) (map snd differences) putStrLn $ show $ ansiWlEditExpr $ ediff' (map fst differences) (map snd differences)
exitFailure exitFailure
fileDiffCmd :: HasCallStack => Mod CommandFields CLI
fileDiffCmd = command "golden-file-diff" (info (helper <*> fmap CLISub filediff_p) (progDesc "Compare the output of two golden files."))
filediff_p :: Parser CLICmd
filediff_p = fmap CCMD_golden_file_diff $ GoldenFileDiffArgs
<$> ( strOption ( long "expected"
<> metavar "FILEPATH"
<> help "Path to the file containing the expected output."
) )
<*> ( strOption ( long "actual"
<> metavar "FILEPATH"
<> help "Path to the file containing the actual output."
) )
...@@ -63,6 +63,11 @@ data UpgradeArgs = UpgradeArgs ...@@ -63,6 +63,11 @@ data UpgradeArgs = UpgradeArgs
{ upgrade_ini :: !FilePath { upgrade_ini :: !FilePath
} deriving (Show, Eq) } deriving (Show, Eq)
data GoldenFileDiffArgs = GoldenFileDiffArgs
{ gdf_expected :: !FilePath
, gdf_actual :: !FilePath
} deriving (Show, Eq)
data CLICmd data CLICmd
= CCMD_clean_csv_corpus = CCMD_clean_csv_corpus
| CCMD_filter_terms_and_cooc !CorpusFile !TermListFile !OutputFile | CCMD_filter_terms_and_cooc !CorpusFile !TermListFile !OutputFile
...@@ -74,6 +79,7 @@ data CLICmd ...@@ -74,6 +79,7 @@ data CLICmd
| CCMD_phylo !PhyloArgs | CCMD_phylo !PhyloArgs
| CCMD_phylo_profile | CCMD_phylo_profile
| CCMD_upgrade !UpgradeArgs | CCMD_upgrade !UpgradeArgs
| CCMD_golden_file_diff !GoldenFileDiffArgs
deriving (Show, Eq) deriving (Show, Eq)
data CLI = data CLI =
......
...@@ -30,6 +30,7 @@ import CLI.Invitations (invitationsCLI, invitationsCmd) ...@@ -30,6 +30,7 @@ import CLI.Invitations (invitationsCLI, invitationsCmd)
import CLI.Phylo (phyloCLI, phyloCmd) import CLI.Phylo (phyloCLI, phyloCmd)
import CLI.Phylo.Profile (phyloProfileCLI, phyloProfileCmd) import CLI.Phylo.Profile (phyloProfileCLI, phyloProfileCmd)
import CLI.Upgrade (upgradeCLI, upgradeCmd) import CLI.Upgrade (upgradeCLI, upgradeCmd)
import CLI.FileDiff (fileDiffCLI, fileDiffCmd)
runCLI :: CLI -> IO () runCLI :: CLI -> IO ()
runCLI = \case runCLI = \case
...@@ -53,6 +54,8 @@ runCLI = \case ...@@ -53,6 +54,8 @@ runCLI = \case
-> phyloProfileCLI -> phyloProfileCLI
CLISub (CCMD_upgrade args) CLISub (CCMD_upgrade args)
-> upgradeCLI args -> upgradeCLI args
CLISub (CCMD_golden_file_diff args)
-> fileDiffCLI args
main :: IO () main :: IO ()
main = runCLI =<< execParser opts main = runCLI =<< execParser opts
...@@ -72,5 +75,6 @@ allOptions = subparser ( ...@@ -72,5 +75,6 @@ allOptions = subparser (
invitationsCmd <> invitationsCmd <>
phyloCmd <> phyloCmd <>
phyloProfileCmd <> phyloProfileCmd <>
upgradeCmd upgradeCmd <>
fileDiffCmd
) )
...@@ -700,6 +700,7 @@ executable gargantext-cli ...@@ -700,6 +700,7 @@ executable gargantext-cli
other-modules: other-modules:
CLI.Admin CLI.Admin
CLI.CleanCsvCorpus CLI.CleanCsvCorpus
CLI.FileDiff
CLI.FilterTermsAndCooc CLI.FilterTermsAndCooc
CLI.Import CLI.Import
CLI.Init CLI.Init
...@@ -736,6 +737,7 @@ executable gargantext-cli ...@@ -736,6 +737,7 @@ executable gargantext-cli
, split ^>= 0.2.3.4 , split ^>= 0.2.3.4
, text ^>= 1.2.4.1 , text ^>= 1.2.4.1
, time ^>= 1.9.3 , time ^>= 1.9.3
, tree-diff
, unordered-containers ^>= 0.2.16.0 , unordered-containers ^>= 0.2.16.0
, vector ^>= 0.7.3 , vector ^>= 0.7.3
...@@ -983,16 +985,3 @@ benchmark garg-bench ...@@ -983,16 +985,3 @@ benchmark garg-bench
ghc-options: "-with-rtsopts=-T -A32m" ghc-options: "-with-rtsopts=-T -A32m"
if impl(ghc >= 8.6) if impl(ghc >= 8.6)
ghc-options: "-with-rtsopts=--nonmoving-gc" ghc-options: "-with-rtsopts=--nonmoving-gc"
executable garg-golden-file-diff
import:
defaults
, optimized
main-is: Main.hs
hs-source-dirs:
bin/gargantext-golden-file-diff
build-depends:
base
, text
, tree-diff
default-language: Haskell2010
...@@ -15,7 +15,18 @@ import qualified Data.Text.Encoding as TE ...@@ -15,7 +15,18 @@ import qualified Data.Text.Encoding as TE
tests :: TestTree tests :: TestTree
tests = testGroup "Lancaster" [ tests = testGroup "Lancaster" [
goldenVsStringDiff "test vector works" (\ref new -> ["cabal", "v2-run", "-v0", "garg-golden-file-diff", "--", ref, new]) "test-data/stemming/lancaster.txt" mkTestVector goldenVsStringDiff "test vector works" (\ref new -> [
"cabal"
, "v2-run"
, "-v0"
, "--"
, "gargantext-cli"
, "golden-file-diff"
, "--expected"
, ref
, "--actual"
, new
]) "test-data/stemming/lancaster.txt" mkTestVector
] ]
......
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