From 68bc0f68d5466a74678736feccad4d0fd5e2cfeb Mon Sep 17 00:00:00 2001 From: Timothy Clem Date: Thu, 20 Feb 2020 10:38:52 -0800 Subject: [PATCH] Bring back tree-sitter corpus tests for go --- .github/workflows/haskell.yml | 1 + semantic-ast/src/AST/Test.hs | 10 ++++++++-- semantic-go/semantic-go.cabal | 2 +- semantic-go/src/Language/Go/AST.hs | 3 ++- semantic-go/test/Test.hs | 3 ++- 5 files changed, 14 insertions(+), 5 deletions(-) diff --git a/.github/workflows/haskell.yml b/.github/workflows/haskell.yml index 1016153e2..b98095165 100644 --- a/.github/workflows/haskell.yml +++ b/.github/workflows/haskell.yml @@ -61,6 +61,7 @@ jobs: cabal v2-build --project-file=cabal.project.ci cabal v2-run --project-file=cabal.project.ci semantic:test cabal v2-run --project-file=cabal.project.ci semantic-core:test + cabal v2-run --project-file=cabal.project.ci semantic-go:test cabal v2-run --project-file=cabal.project.ci semantic-python:test:compiling cabal v2-run --project-file=cabal.project.ci semantic-python:test:graphing cd semantic-source; cabal v2-run --project-file=cabal.project.ci semantic-source:test; cd .. diff --git a/semantic-ast/src/AST/Test.hs b/semantic-ast/src/AST/Test.hs index f673c442e..876e39823 100644 --- a/semantic-ast/src/AST/Test.hs +++ b/semantic-ast/src/AST/Test.hs @@ -2,6 +2,7 @@ module AST.Test ( CorpusExample(..) , readCorpusFiles + , readCorpusFiles' , parseCorpusFile , testCorpus ) where @@ -22,7 +23,7 @@ import System.FilePath.Glob import Test.Tasty import Test.Tasty.HUnit -testCorpus :: (ByteString -> IO (Either String (t a))) -> Path.RelFile -> IO TestTree +testCorpus :: (ByteString -> IO (Either String (t a))) -> Path.AbsRelFile -> IO TestTree testCorpus parse path = do xs <- parseCorpusFile path case xs of @@ -50,10 +51,15 @@ readCorpusFiles parent = do files <- globDir1 (compile "**/*.txt") (Path.toString dir) pure (Path.relPath <$> files) +readCorpusFiles' :: Path.AbsDir -> IO [Path.AbsRelFile] +readCorpusFiles' dir = do + files <- globDir1 (compile "**/*.txt") (Path.toString dir) + pure (Path.file <$> files) + data CorpusExample = CorpusExample { name :: String, code :: ByteString } deriving (Eq, Show) -parseCorpusFile :: Path.RelFile -> IO (Either String [CorpusExample]) +parseCorpusFile :: Path.AbsRelFile -> IO (Either String [CorpusExample]) parseCorpusFile path = do c <- Data.ByteString.readFile (Path.toString path) pure $ parseOnly corpusParser c diff --git a/semantic-go/semantic-go.cabal b/semantic-go/semantic-go.cabal index 03baa3119..6b25ca4cc 100644 --- a/semantic-go/semantic-go.cabal +++ b/semantic-go/semantic-go.cabal @@ -31,7 +31,7 @@ common haskell , template-haskell ^>= 2.15 , text ^>= 1.2.3 , tree-sitter ^>= 0.9 - , tree-sitter-go ^>= 0.5.0.0 + , tree-sitter-go ^>= 0.5.0.1 ghc-options: -Weverything diff --git a/semantic-go/src/Language/Go/AST.hs b/semantic-go/src/Language/Go/AST.hs index 361c3c4c4..98b48f9ea 100644 --- a/semantic-go/src/Language/Go/AST.hs +++ b/semantic-go/src/Language/Go/AST.hs @@ -12,11 +12,12 @@ module Language.Go.AST ( module Language.Go.AST +, Go.getTestCorpusDir ) where import Prelude hiding (False, Float, Integer, Rational, String, True) import AST.GenerateSyntax import Language.Haskell.TH.Syntax (runIO) -import qualified TreeSitter.Go as Go (getNodeTypesPath, tree_sitter_go) +import qualified TreeSitter.Go as Go (getNodeTypesPath, getTestCorpusDir, tree_sitter_go) runIO Go.getNodeTypesPath >>= astDeclarationsForLanguage Go.tree_sitter_go diff --git a/semantic-go/test/Test.hs b/semantic-go/test/Test.hs index 2c04d8cc4..9a205ba5b 100644 --- a/semantic-go/test/Test.hs +++ b/semantic-go/test/Test.hs @@ -10,7 +10,8 @@ import Test.Tasty main :: IO () main - = readCorpusFiles (Path.relDir "tree-sitter-go/vendor/tree-sitter-go/corpus") + = Path.absDir <$> Go.getTestCorpusDir + >>= readCorpusFiles' >>= traverse (testCorpus parse) >>= defaultMain . tests where parse = parseByteString @Go.SourceFile @() tree_sitter_go