summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Config.hs11
-rw-r--r--src/Main.hs3
-rw-r--r--src/Run.hs16
-rw-r--r--src/TestMode.hs14
-rw-r--r--test/asset/run/erebos-tester-select1.yaml2
-rw-r--r--test/asset/run/erebos-tester-select2.yaml8
-rw-r--r--test/script/run.et47
-rw-r--r--test/script/shell.et12
8 files changed, 93 insertions, 20 deletions
diff --git a/src/Config.hs b/src/Config.hs
index adf0321..af2161a 100644
--- a/src/Config.hs
+++ b/src/Config.hs
@@ -9,6 +9,7 @@ import Control.Monad.Combinators
import Data.ByteString.Lazy qualified as BS
import Data.Scientific
+import Data.Text (Text)
import Data.Text qualified as T
import Data.YAML
@@ -21,6 +22,8 @@ data Config = Config
{ configDir :: FilePath
, configTool :: Maybe FilePath
, configTests :: [ Pattern ]
+ , configSelect :: Maybe [ Text ]
+ , configExclude :: [ Text ]
, configTimeout :: Maybe Scientific
}
deriving (Show)
@@ -33,6 +36,14 @@ instance FromYAML (FilePath -> Config) where
, m .:? "tests" .!= [] -- list of patterns
]
)
+ configSelect <- foldr1 (<|>)
+ [ fmap (Just . (: [])) (m .: "select") -- single item
+ , m .:? "select" -- list of items
+ ]
+ configExclude <- foldr1 (<|>)
+ [ fmap (: []) (m .: "exclude") -- single item
+ , m .:? "exclude" .!= [] -- list of items
+ ]
configTimeout <- fmap fromNumber <$> m .:! "timeout"
return $ \configDir -> Config {..}
diff --git a/src/Main.hs b/src/Main.hs
index b2e4171..7adf71d 100644
--- a/src/Main.hs
+++ b/src/Main.hs
@@ -196,7 +196,8 @@ main = do
let tfSelect = if null otests then Nothing else Just otests
tfExclude = optExclude opts
- tests <- exitOnError $ filterTests TestFilter {..} lm
+ tfilter = maybe mempty testFilterFromConfig config <> TestFilter {..}
+ tests <- exitOnError $ filterTests tfilter lm
tcpdump <- case optCmdlineTcpdump opts of
TcpdumpAuto -> findExecutable "tcpdump"
diff --git a/src/Run.hs b/src/Run.hs
index e1bab46..f3805ea 100644
--- a/src/Run.hs
+++ b/src/Run.hs
@@ -7,6 +7,7 @@ module Run (
evalGlobalDefs,
TestFilter(..),
+ testFilterFromConfig,
filterTests,
) where
@@ -37,6 +38,7 @@ import System.Posix.Process
import System.Posix.Signals
import System.Process
+import Config
import GDB
import Network
import Network.Ip
@@ -185,6 +187,20 @@ data TestFilter = TestFilter
, tfExclude :: [ Text ]
}
+instance Semigroup TestFilter where
+ a <> b
+ | isJust (tfSelect b) = b
+ | otherwise = a { tfExclude = tfExclude a <> tfExclude b }
+
+instance Monoid TestFilter where
+ mempty = TestFilter Nothing []
+
+testFilterFromConfig :: Config -> TestFilter
+testFilterFromConfig Config {..} = TestFilter
+ { tfSelect = configSelect
+ , tfExclude = configExclude
+ }
+
filterTests :: TestFilter -> LoadedModules -> Either CustomTestError [ Test ]
filterTests TestFilter {..} LoadedModules {..} = do
let allTests = concatMap (\m -> ( moduleName m, ) <$> moduleTests m) lmModules
diff --git a/src/TestMode.hs b/src/TestMode.hs
index 6a74b10..22d8237 100644
--- a/src/TestMode.hs
+++ b/src/TestMode.hs
@@ -25,7 +25,6 @@ import Output
import Parser
import Run
import Script.Expr
-import Script.Module
import Test
@@ -109,7 +108,6 @@ commands =
[ ( "load", cmdLoad )
, ( "load-config", cmdLoadConfig )
, ( "run", cmdRun )
- , ( "run-all", cmdRunAll )
]
showError :: Text -> CustomTestError -> Command
@@ -157,19 +155,13 @@ cmdRun :: Command
cmdRun = do
params <- asks tmiParams
let ( select, exclude ) = fmap (map (T.drop 1)) $ partition (("^" /=) . T.take 1) params
+ pfilter = (TestFilter (if select == [ "*" ] then Nothing else Just select) exclude)
+ cfilter <- asks $ maybe mempty testFilterFromConfig . tmiConfig
Just lm <- gets tmsModules
- case filterTests (TestFilter (if select == [ "*" ] then Nothing else Just select) exclude) lm of
+ case filterTests (cfilter <> pfilter) lm of
Left err -> showError "run-failed" err
Right tests -> do
forM_ tests $ \test -> do
res <- runSingleTest test
cmdOut $ "run-test-result " <> testName test <> " " <> (if res then "done" else "failed")
cmdOut "run-done"
-
-cmdRunAll :: Command
-cmdRunAll = do
- Just LoadedModules {..} <- gets tmsModules
- forM_ (concatMap moduleTests lmModules) $ \test -> do
- res <- runSingleTest test
- cmdOut $ "run-test-result " <> testName test <> " " <> (if res then "done" else "failed")
- cmdOut "run-all-done"
diff --git a/test/asset/run/erebos-tester-select1.yaml b/test/asset/run/erebos-tester-select1.yaml
new file mode 100644
index 0000000..62e0ead
--- /dev/null
+++ b/test/asset/run/erebos-tester-select1.yaml
@@ -0,0 +1,2 @@
+tests: ./tags.et
+exclude: B
diff --git a/test/asset/run/erebos-tester-select2.yaml b/test/asset/run/erebos-tester-select2.yaml
new file mode 100644
index 0000000..52310be
--- /dev/null
+++ b/test/asset/run/erebos-tester-select2.yaml
@@ -0,0 +1,8 @@
+tests: ./tags.et
+select:
+ - T2
+ - A
+ - B
+exclude:
+ - A1
+ - C
diff --git a/test/script/run.et b/test/script/run.et
index 97f4dd8..87218c0 100644
--- a/test/script/run.et
+++ b/test/script/run.et
@@ -81,14 +81,14 @@ test RunConfig:
with p:
send "load-config"
expect /load-config-done/
- send "run-all"
+ send "run *"
expect /run-test-result AlwaysSucceeds done/
expect /run-test-result AlwaysFails failed/
expect /child-stdin p abcdef/
expect /child-stdout p abcdef/
expect /match p abcdef/
expect /run-test-result ExpectEcho done/
- expect /run-all-done/
+ expect /run-done/
test GetSysInfo:
@@ -282,3 +282,46 @@ test RunTagExclude:
local:
expect /run-(.*)/ capture done
guard (done == "done")
+
+
+test RunExcludeConfig1:
+ node n
+ local:
+ shell on n:
+ cp ${scripts.path}/erebos-tester-select1.yaml erebos-tester.yaml
+ cp ${scripts.path}/tags.et .
+
+ spawn as p on n
+ with p:
+ send "load-config"
+ expect /load-config-done/
+ send "run *"
+ expect /run-test-result T1 done/
+ expect /run-test-result T2 done/
+ expect /run-test-result A1 done/
+ expect /run-test-result A2 done/
+ expect /run-test-result C1 done/
+ expect /run-test-result C2 done/
+ local:
+ expect /run-(.*)/ capture done
+ guard (done == "done")
+
+test RunExcludeConfig2:
+ node n
+ local:
+ shell on n:
+ cp ${scripts.path}/erebos-tester-select2.yaml erebos-tester.yaml
+ cp ${scripts.path}/tags.et .
+
+ spawn as p on n
+ with p:
+ send "load-config"
+ expect /load-config-done/
+ send "run *"
+ expect /run-test-result T2 done/
+ expect /run-test-result A2 done/
+ expect /run-test-result B1 done/
+ expect /run-test-result B2 done/
+ local:
+ expect /run-(.*)/ capture done
+ guard (done == "done")
diff --git a/test/script/shell.et b/test/script/shell.et
index 282df37..00826c8 100644
--- a/test/script/shell.et
+++ b/test/script/shell.et
@@ -11,12 +11,12 @@ test ShellSpawn:
guard (done == "load-done")
flush
- send "run-all"
+ send "run *"
expect /run-test-result ShellTrue done/
expect /child-fail sh failed at: .*: false/
expect /child-fail sh exit code: 1/
expect /run-test-result ShellFalse failed/
- expect /run-all-done/
+ expect /run-done/
def expect_next_stdout from p (expected):
@@ -32,7 +32,7 @@ test ShellEcho:
guard (done == "load-done")
flush
- send "run-all"
+ send "run *"
expect_next_stdout from p:
"a b c"
@@ -57,7 +57,7 @@ test ShellEcho:
with p:
expect /run-test-result Echo done/
- expect /run-all-done/
+ expect /run-done/
test ShellPipe:
@@ -69,7 +69,7 @@ test ShellPipe:
guard (done == "load-done")
flush
- send "run-all"
+ send "run *"
expect_next_stdout from p:
"bc"
@@ -97,4 +97,4 @@ test ShellPipe:
expect /run-test-result PipeRedirect done/
with p:
- expect /run-all-done/
+ expect /run-done/