From 62251c102c57d4c12da6923dc0ea5747cfb3ef0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Smr=C5=BE?= Date: Tue, 7 Jun 2022 21:35:48 +0200 Subject: Source line info for test steps from parsing --- src/Main.hs | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'src/Main.hs') diff --git a/src/Main.hs b/src/Main.hs index e062dee..5e1e7b2 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -267,8 +267,8 @@ tryMatch re (x:xs) | Right (Just (_, _, _, capture)) <- regexec re x = Just ((x, | otherwise = fmap (x:) <$> tryMatch re xs tryMatch _ [] = Nothing -expect :: Process -> Regex -> Text -> [VarName] -> TestRun () -expect p re pat vars = do +expect :: SourceLine -> Process -> Regex -> [VarName] -> TestRun () +expect (SourceLine sline) p re vars = do timeout <- asks $ optTimeout . teOptions delay <- liftIO $ registerDelay $ ceiling $ 1000000 * timeout mbmatch <- atomicallyTest $ (Nothing <$ (check =<< readTVar delay)) <|> do @@ -281,19 +281,19 @@ expect p re pat vars = do case mbmatch of Just (line, capture) -> do when (length vars /= length capture) $ do - outLine OutputMatchFail (Just $ procName p) $ T.pack "mismatched number of capture variables /" `T.append` pat `T.append` T.pack "/" + outLine OutputMatchFail (Just $ procName p) $ T.pack "mismatched number of capture variables on " `T.append` sline throwError () forM_ vars $ \name -> do cur <- gets (lookup name . tsVars) when (isJust cur) $ do - outLine OutputMatchFail (Just $ procName p) $ T.pack "variable already exists: '" `T.append` textVarName name `T.append` T.pack "'" + outLine OutputMatchFail (Just $ procName p) $ T.pack "variable '" `T.append` textVarName name `T.append` T.pack "' already exists on " `T.append` sline throwError () modify $ \s -> s { tsVars = zip vars capture ++ tsVars s } outLine OutputMatch (Just $ procName p) line Nothing -> do - outLine OutputMatchFail (Just $ procName p) $ T.pack "expect failed /" `T.append` pat `T.append` T.pack "/" + outLine OutputMatchFail (Just $ procName p) $ T.pack "expect failed on " `T.append` sline throwError () allM :: Monad m => [a] -> (a -> m Bool) -> m Bool @@ -335,11 +335,10 @@ runTest out opts test = do line <- eval expr send p line - Expect pname expr@(Regex ps) captures -> do + Expect line pname expr captures -> do p <- getProcess net pname regex <- eval expr - pat <- eval (Concat ps) - expect p regex pat captures + expect line p regex captures Wait -> do outPrompt $ T.pack "Waiting..." -- cgit v1.2.3