mirror of
https://github.com/github/semantic.git
synced 2024-12-27 00:44:57 +03:00
Iterate on test example output and asserts
This commit is contained in:
parent
5f451450d6
commit
024313ccd7
@ -15,9 +15,12 @@ import Data.Blob
|
|||||||
import qualified Data.ByteString.Lazy.Char8 as BLC
|
import qualified Data.ByteString.Lazy.Char8 as BLC
|
||||||
import qualified Data.ByteString.Streaming.Char8 as ByteStream
|
import qualified Data.ByteString.Streaming.Char8 as ByteStream
|
||||||
import Data.Foldable
|
import Data.Foldable
|
||||||
|
import Data.Either
|
||||||
import Data.Function ((&))
|
import Data.Function ((&))
|
||||||
import Data.Language (LanguageMode (..), PerLanguageModes (..))
|
import Data.Language (LanguageMode (..), PerLanguageModes (..))
|
||||||
|
import Data.List
|
||||||
import Data.Set (Set)
|
import Data.Set (Set)
|
||||||
|
-- import qualified Data.Set as Set
|
||||||
import qualified Streaming.Prelude as Stream
|
import qualified Streaming.Prelude as Stream
|
||||||
import System.FilePath.Glob
|
import System.FilePath.Glob
|
||||||
import System.Path ((</>))
|
import System.Path ((</>))
|
||||||
@ -78,27 +81,38 @@ buildExamples session lang tsDir = do
|
|||||||
-- Use alacarte language mode (this is the control)
|
-- Use alacarte language mode (this is the control)
|
||||||
step "a la carte"
|
step "a la carte"
|
||||||
alacarte <- runTask session (runParse (parseSymbolsFilePath aLaCarteLanguageModes file))
|
alacarte <- runTask session (runParse (parseSymbolsFilePath aLaCarteLanguageModes file))
|
||||||
assertOK alacarte knownFailures
|
HUnit.assertBool "a la carte parsing failed" (isRight alacarte)
|
||||||
|
|
||||||
-- Test out precise language mode (treatment)
|
-- Test out precise language mode (treatment)
|
||||||
step "precise"
|
step "precise"
|
||||||
precise <- runTask session (runParse (parseSymbolsFilePath preciseLanguageModes file))
|
precise <- runTask session (runParse (parseSymbolsFilePath preciseLanguageModes file))
|
||||||
assertOK precise knownFailures
|
HUnit.assertBool "precise parsing failed" (isRight precise)
|
||||||
|
|
||||||
-- Compare the control and treatment
|
step "compare"
|
||||||
case (alacarte, precise) of
|
assertMatch file knownFailures alacarte precise
|
||||||
(Right a, Right b) -> a HUnit.@=? b
|
|
||||||
_ -> pure ()
|
|
||||||
|
|
||||||
pure (Tasty.testGroup (languageName lang) trees)
|
pure (Tasty.testGroup (languageName lang) trees)
|
||||||
|
|
||||||
where
|
where
|
||||||
assertOK res _ = case res of
|
assertMatch _ _ a b = case (a, b) of
|
||||||
Left e -> HUnit.assertFailure (show (displayException e))
|
(Right a, Right b) -> case (toList (a^.files), toList (b^.files)) of
|
||||||
Right res -> case toList (res^.files) of
|
([x], _) | (e:_) <- toList (x^.errors) -> HUnit.assertFailure (show e)
|
||||||
[x] | (e:_) <- toList (x^.errors) -> HUnit.assertFailure (show e)
|
(_, [y]) | (e:_) <- toList (y^.errors) -> HUnit.assertFailure (show e)
|
||||||
[_] -> pure ()
|
([x], [y]) -> do
|
||||||
_ -> HUnit.assertFailure "Expected 1 file in response"
|
HUnit.assertEqual "Expected paths to be equal" (x^.path) (y^.path)
|
||||||
|
let xSymbols = sort $ toListOf (symbols . traverse . symbol) x
|
||||||
|
let ySymbols = sort $ toListOf (symbols . traverse . symbol) y
|
||||||
|
HUnit.assertEqual "Expected symbols to be equal" xSymbols ySymbols
|
||||||
|
pure ()
|
||||||
|
_ -> HUnit.assertFailure "Expected 1 file in each response"
|
||||||
|
(Left e, _) -> HUnit.assertFailure (show (displayException e))
|
||||||
|
(_, Left e) -> HUnit.assertFailure (show (displayException e))
|
||||||
|
-- assertOK res path knownFailures = case res of
|
||||||
|
-- Left e -> if Set.member path knownFailures then pure() else HUnit.assertFailure (show (displayException e))
|
||||||
|
-- Right res -> case toList (res^.files) of
|
||||||
|
-- [x] | (e:_) <- toList (x^.errors) -> HUnit.assertFailure (show e)
|
||||||
|
-- [_] -> pure ()
|
||||||
|
-- _ -> HUnit.assertFailure "Expected 1 file in response"
|
||||||
|
|
||||||
aLaCarteLanguageModes :: PerLanguageModes
|
aLaCarteLanguageModes :: PerLanguageModes
|
||||||
aLaCarteLanguageModes = PerLanguageModes
|
aLaCarteLanguageModes = PerLanguageModes
|
||||||
@ -152,4 +166,8 @@ parseSymbolsFilePath ::
|
|||||||
=> PerLanguageModes
|
=> PerLanguageModes
|
||||||
-> Path.RelFile
|
-> Path.RelFile
|
||||||
-> m ParseTreeSymbolResponse
|
-> m ParseTreeSymbolResponse
|
||||||
parseSymbolsFilePath languageModes path = readBlob (fileForTypedPath path) >>= runReader languageModes . parseSymbols . pure @[]
|
parseSymbolsFilePath languageModes path
|
||||||
|
= readBlob (fileForTypedPath path)
|
||||||
|
>>= runReader languageModes . parseSymbols . pure @[]
|
||||||
|
-- >>= serialize Format.JSON
|
||||||
|
-- >>= pure . toLazyByteString
|
||||||
|
Loading…
Reference in New Issue
Block a user