mirror of
https://github.com/github/semantic.git
synced 2024-11-24 08:54:07 +03:00
Pass the task config stuff around as a single datum.
This commit is contained in:
parent
90cb86d027
commit
b33daf0ce1
@ -11,8 +11,8 @@ import SpecHelpers
|
||||
languages :: [FilePath]
|
||||
languages = ["go", "javascript", "json", "python", "ruby", "typescript"]
|
||||
|
||||
spec :: Config -> LogQueue -> StatQueue -> Spec
|
||||
spec config logger statter = parallel $ do
|
||||
spec :: TaskConfig -> Spec
|
||||
spec config = parallel $ do
|
||||
for_ languages $ \language -> do
|
||||
let dir = "test/fixtures" </> language </> "corpus"
|
||||
it (language <> " corpus exists") $ examples dir `shouldNotReturn` []
|
||||
@ -23,8 +23,8 @@ spec config logger statter = parallel $ do
|
||||
runTestsIn directory pending = do
|
||||
examples <- runIO $ examples directory
|
||||
traverse_ (runTest pending) examples
|
||||
runTest pending ParseExample{..} = it ("parses " <> file) $ maybe (testParse config logger statter file parseOutput) pendingWith (lookup parseOutput pending)
|
||||
runTest pending DiffExample{..} = it ("diffs " <> diffOutput) $ maybe (testDiff config logger statter (both fileA fileB) diffOutput) pendingWith (lookup diffOutput pending)
|
||||
runTest pending ParseExample{..} = it ("parses " <> file) $ maybe (testParse config file parseOutput) pendingWith (lookup parseOutput pending)
|
||||
runTest pending DiffExample{..} = it ("diffs " <> diffOutput) $ maybe (testDiff config (both fileA fileB) diffOutput) pendingWith (lookup diffOutput pending)
|
||||
|
||||
data Example = DiffExample { fileA :: FilePath, fileB :: FilePath, diffOutput :: FilePath }
|
||||
| ParseExample { file :: FilePath, parseOutput :: FilePath }
|
||||
@ -81,14 +81,14 @@ examples directory = do
|
||||
normalizeName :: FilePath -> FilePath
|
||||
normalizeName path = dropExtension $ dropExtension path
|
||||
|
||||
testParse :: Config -> LogQueue -> StatQueue -> FilePath -> FilePath -> Expectation
|
||||
testParse config logger statter path expectedOutput = do
|
||||
actual <- verbatim <$> parseFilePath config logger statter path
|
||||
testParse :: TaskConfig -> FilePath -> FilePath -> Expectation
|
||||
testParse config path expectedOutput = do
|
||||
actual <- verbatim <$> parseFilePath config path
|
||||
expected <- verbatim <$> B.readFile expectedOutput
|
||||
actual `shouldBe` expected
|
||||
|
||||
testDiff :: Config -> LogQueue -> StatQueue -> Both FilePath -> FilePath -> Expectation
|
||||
testDiff config logger statter paths expectedOutput = do
|
||||
actual <- verbatim <$> diffFilePaths config logger statter paths
|
||||
testDiff :: TaskConfig -> Both FilePath -> FilePath -> Expectation
|
||||
testDiff config paths expectedOutput = do
|
||||
actual <- verbatim <$> diffFilePaths config paths
|
||||
expected <- verbatim <$> B.readFile expectedOutput
|
||||
actual `shouldBe` expected
|
||||
|
@ -24,6 +24,7 @@ import qualified Semantic.Spec
|
||||
import qualified Semantic.CLI.Spec
|
||||
import qualified Semantic.IO.Spec
|
||||
import qualified Semantic.Stat.Spec
|
||||
import SpecHelpers (TaskConfig(..))
|
||||
import Semantic.Config (defaultConfig, defaultOptions, withTelemetry)
|
||||
import Semantic.Telemetry (TelemetryQueues(..))
|
||||
import qualified Proto3.Roundtrip
|
||||
@ -33,6 +34,7 @@ main :: IO ()
|
||||
main = do
|
||||
config <- defaultConfig defaultOptions
|
||||
withTelemetry config $ \ (TelemetryQueues logger statter _) -> hspec $ do
|
||||
let args = TaskConfig config logger statter
|
||||
describe "Semantic.Stat" Semantic.Stat.Spec.spec
|
||||
parallel $ do
|
||||
describe "Analysis.Go" Analysis.Go.Spec.spec
|
||||
@ -57,5 +59,5 @@ main = do
|
||||
describe "Semantic" Semantic.Spec.spec
|
||||
describe "Semantic.CLI" Semantic.CLI.Spec.spec
|
||||
describe "Semantic.IO" Semantic.IO.Spec.spec
|
||||
describe "Integration" (Integration.Spec.spec config logger statter)
|
||||
describe "Integration" (Integration.Spec.spec args)
|
||||
describe "Protobuf roundtripping" Proto3.Roundtrip.spec
|
||||
|
@ -11,6 +11,7 @@ module SpecHelpers
|
||||
, TermEvaluator(..)
|
||||
, Verbatim(..)
|
||||
, toList
|
||||
, TaskConfig(..)
|
||||
, Config
|
||||
, LogQueue
|
||||
, StatQueue
|
||||
@ -75,13 +76,15 @@ import Control.Exception (displayException)
|
||||
|
||||
runBuilder = toStrict . toLazyByteString
|
||||
|
||||
data TaskConfig = TaskConfig Config LogQueue StatQueue
|
||||
|
||||
-- | Returns an s-expression formatted diff for the specified FilePath pair.
|
||||
diffFilePaths :: Config -> LogQueue -> StatQueue -> Both FilePath -> IO ByteString
|
||||
diffFilePaths config logger statter paths = readFilePair paths >>= runTaskWithConfig config logger statter . runDiff SExpressionDiffRenderer . pure >>= either (die . displayException) (pure . runBuilder)
|
||||
diffFilePaths :: TaskConfig -> Both FilePath -> IO ByteString
|
||||
diffFilePaths (TaskConfig config logger statter) paths = readFilePair paths >>= runTaskWithConfig config logger statter . runDiff SExpressionDiffRenderer . pure >>= either (die . displayException) (pure . runBuilder)
|
||||
|
||||
-- | Returns an s-expression parse tree for the specified FilePath.
|
||||
parseFilePath :: Config -> LogQueue -> StatQueue -> FilePath -> IO ByteString
|
||||
parseFilePath config logger statter path = (fromJust <$> IO.readFile (file path)) >>= runTaskWithConfig config logger statter . runParse SExpressionTermRenderer . pure >>= either (die . displayException) (pure . runBuilder)
|
||||
parseFilePath :: TaskConfig -> FilePath -> IO ByteString
|
||||
parseFilePath (TaskConfig config logger statter) path = (fromJust <$> IO.readFile (file path)) >>= runTaskWithConfig config logger statter . runParse SExpressionTermRenderer . pure >>= either (die . displayException) (pure . runBuilder)
|
||||
|
||||
-- | Read two files to a BlobPair.
|
||||
readFilePair :: Both FilePath -> IO BlobPair
|
||||
|
Loading…
Reference in New Issue
Block a user