mirror of
https://github.com/github/semantic.git
synced 2024-11-26 09:07:39 +03:00
WIP commit to make parse_examples work
This commit is contained in:
parent
20b7982649
commit
8437814fcf
@ -239,3 +239,7 @@ exports_files(["src/node-types.json"])
|
||||
commit = "41a408d5b996ef54d8b9e1b9a2469fad00c1b52b",
|
||||
remote = "https://github.com/tree-sitter/tree-sitter-php.git",
|
||||
)
|
||||
|
||||
load("//:build/example_repos.bzl", "declare_example_repos")
|
||||
|
||||
declare_example_repos()
|
||||
|
38
build/example_repos.bzl
Normal file
38
build/example_repos.bzl
Normal file
@ -0,0 +1,38 @@
|
||||
load(
|
||||
"@bazel_tools//tools/build_defs/repo:git.bzl",
|
||||
"git_repository",
|
||||
"new_git_repository",
|
||||
)
|
||||
|
||||
all_example_repos = {
|
||||
"golang": {
|
||||
"data": ["src/**/*.go"],
|
||||
"commit": "870e12d7bfaea70fb0d743842f5864eb059cb939",
|
||||
"repo": "golang/go",
|
||||
"since": "1533485518 -0700",
|
||||
},
|
||||
"moby": {
|
||||
"data": ["**/*.go"],
|
||||
"commit": "f57f260b49b6142366e6bc1274204ee0a1205945",
|
||||
"repo": "moby/moby",
|
||||
"since": "1533485518 -0700",
|
||||
},
|
||||
}
|
||||
|
||||
def example_repo(name, data, commit, repo):
|
||||
new_git_repository(
|
||||
name = name,
|
||||
build_file_content = """
|
||||
filegroup(
|
||||
name = "src",
|
||||
data = glob({}),
|
||||
visibility = ["//visibility:public"]
|
||||
)
|
||||
""".format(data),
|
||||
commit = commit,
|
||||
remote = "https://github.com/{}.git".format(repo),
|
||||
)
|
||||
|
||||
def declare_example_repos():
|
||||
for k, v in all_example_repos.items():
|
||||
example_repo(name = k, data = v["data"], commit = v["commit"], repo = v["repo"])
|
@ -118,6 +118,16 @@ haskell_binary(
|
||||
],
|
||||
)
|
||||
|
||||
haskell_library(
|
||||
name = "fixtureshim",
|
||||
srcs = ["test/System/Path/Bazel.hs"],
|
||||
deps = [
|
||||
"//:base",
|
||||
"@stackage//:bazel-runfiles",
|
||||
"@stackage//:pathtype",
|
||||
],
|
||||
)
|
||||
|
||||
haskell_test(
|
||||
name = "spec",
|
||||
srcs = glob(
|
||||
@ -125,6 +135,7 @@ haskell_test(
|
||||
exclude = [
|
||||
"test/fixtures/**/*.hs",
|
||||
"test/Examples.hs",
|
||||
"test/System/Path/Bazel.hs",
|
||||
],
|
||||
),
|
||||
compiler_flags = STANDARD_GHC_WARNINGS + STANDARD_EXECUTABLE_FLAGS + [
|
||||
@ -140,6 +151,7 @@ haskell_test(
|
||||
"test/fixtures/cli/*.json",
|
||||
]),
|
||||
deps = semantic_common_dependencies + [
|
||||
":fixtureshim",
|
||||
"//:base",
|
||||
"//semantic",
|
||||
"//semantic-proto",
|
||||
@ -166,7 +178,9 @@ haskell_test(
|
||||
|
||||
haskell_test(
|
||||
name = "parse-examples",
|
||||
srcs = ["test/Examples.hs"],
|
||||
srcs = [
|
||||
"test/Examples.hs",
|
||||
],
|
||||
compiler_flags = STANDARD_GHC_WARNINGS + STANDARD_EXECUTABLE_FLAGS + [
|
||||
"-XStrictData",
|
||||
],
|
||||
@ -178,8 +192,12 @@ haskell_test(
|
||||
"test/fixtures/javascript/**/*.js",
|
||||
"test/fixtures/typescript/**/*.ts",
|
||||
"test/fixtures/cli/*.json",
|
||||
]),
|
||||
]) + [
|
||||
"@golang//:src",
|
||||
"@moby//:src",
|
||||
],
|
||||
deps = semantic_common_dependencies + [
|
||||
":fixtureshim",
|
||||
"//:base",
|
||||
"//semantic",
|
||||
"//semantic-proto",
|
||||
|
@ -1,5 +1,6 @@
|
||||
{-# LANGUAGE AllowAmbiguousTypes #-}
|
||||
{-# LANGUAGE FlexibleContexts #-}
|
||||
{-# LANGUAGE ImplicitParams #-}
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
{-# LANGUAGE RecordWildCards #-}
|
||||
{-# LANGUAGE TypeApplications #-}
|
||||
@ -25,7 +26,10 @@ import Data.Traversable
|
||||
import System.FilePath.Glob
|
||||
import System.Path ((</>))
|
||||
import qualified System.Path as Path
|
||||
import qualified System.Path.Directory as Path
|
||||
import qualified System.Process as Process
|
||||
import qualified System.Path.Bazel as Fixture
|
||||
import qualified Bazel.Runfiles as Runfiles
|
||||
import qualified Test.Tasty as Tasty
|
||||
import qualified Test.Tasty.HUnit as HUnit
|
||||
|
||||
@ -127,23 +131,29 @@ typescriptSkips = Path.relFile <$>
|
||||
, "npm/node_modules/request/node_modules/har-validator/node_modules/ajv/dist/regenerator.min.js"
|
||||
]
|
||||
|
||||
buildExamples :: TaskSession -> LanguageExample -> Path.RelDir -> IO Tasty.TestTree
|
||||
buildExamples :: Fixture.HasBazel => TaskSession -> LanguageExample -> Path.RelDir -> IO Tasty.TestTree
|
||||
buildExamples session lang tsDir = do
|
||||
let fileSkips = fmap (tsDir </>) (languageSkips lang)
|
||||
dirSkips = fmap (tsDir </>) (languageDirSkips lang)
|
||||
files <- globDir1 (compile (languageExtension lang)) (Path.toString tsDir)
|
||||
let paths = filter (\x -> Path.takeDirectory x `notElem` dirSkips) . filter (`notElem` fileSkips) $ Path.relFile <$> files
|
||||
trees <- for paths $ \file -> do
|
||||
pure . HUnit.testCase (Path.toString file) $ do
|
||||
precise <- runTask session (runParse (parseSymbolsFilePath preciseLanguageModes file))
|
||||
assertOK "precise" precise
|
||||
pure (Tasty.testGroup (languageName lang) trees)
|
||||
pure $ Tasty.testGroup "examples"
|
||||
[ HUnit.testCase "golang" $ do
|
||||
for_ goFileSkips $ \fp -> do
|
||||
does <- Path.doesFileExist fp
|
||||
HUnit.assertBool ("Can't find " <> Path.toString fp) does
|
||||
]
|
||||
-- let fileSkips = fmap (tsDir </>) (languageSkips lang)
|
||||
-- dirSkips = fmap (tsDir </>) (languageDirSkips lang)
|
||||
-- files <- globDir1 (compile (languageExtension lang)) (Path.toString tsDir)
|
||||
-- let paths = filter (\x -> Path.takeDirectory x `notElem` dirSkips) . filter (`notElem` fileSkips) $ Path.relFile <$> files
|
||||
-- trees <- for paths $ \file -> do
|
||||
-- pure . HUnit.testCase (Path.toString file) $ do
|
||||
-- precise <- runTask session (runParse (parseSymbolsFilePath preciseLanguageModes file))
|
||||
-- assertOK "precise" precise
|
||||
-- pure (Tasty.testGroup (languageName lang) trees)
|
||||
|
||||
where
|
||||
assertOK msg = either (\e -> HUnit.assertFailure (msg <> " failed to parse" <> show e)) (refuteErrors msg)
|
||||
refuteErrors msg a = case toList (a^.files) of
|
||||
[x] | (e:_) <- toList (x^.errors) -> HUnit.assertFailure (msg <> " parse errors " <> show e)
|
||||
_ -> pure ()
|
||||
-- where
|
||||
-- assertOK msg = either (\e -> HUnit.assertFailure (msg <> " failed to parse" <> show e)) (refuteErrors msg)
|
||||
-- refuteErrors msg a = case toList (a^.files) of
|
||||
-- [x] | (e:_) <- toList (x^.errors) -> HUnit.assertFailure (msg <> " parse errors " <> show e)
|
||||
-- _ -> pure ()
|
||||
|
||||
data SortableSymbol = SortableSymbol Text.Text Int32 Int32 Int32 Int32
|
||||
deriving (Eq, Show, Ord)
|
||||
@ -160,6 +170,9 @@ main :: IO ()
|
||||
main = withOptions testOptions $ \ config logger statter -> do
|
||||
void $ Process.system "script/clone-example-repos"
|
||||
|
||||
rf <- Runfiles.create
|
||||
let ?runfiles = rf
|
||||
|
||||
let session = TaskSession config "-" False logger statter
|
||||
|
||||
allTests <- forConcurrently examples $ \lang@LanguageExample{..} -> do
|
||||
|
@ -4,6 +4,7 @@
|
||||
module System.Path.Bazel
|
||||
( bazelFile,
|
||||
bazelFile',
|
||||
absRelFile,
|
||||
bazelDir,
|
||||
HasBazel,
|
||||
)
|
||||
@ -18,8 +19,9 @@ type HasBazel = (?runfiles :: Bazel.Runfiles, HasCallStack)
|
||||
bazelFile :: (HasBazel) => String -> Path.AbsFile
|
||||
bazelFile x = Path.absFile (Bazel.rlocation ?runfiles ("semantic/semantic/" <> x))
|
||||
|
||||
bazelFile' :: (HasBazel) => String -> Path.AbsRelFile
|
||||
bazelFile', absRelFile :: (HasBazel) => String -> Path.AbsRelFile
|
||||
bazelFile' = Path.toAbsRel . bazelFile
|
||||
absRelFile = bazelFile'
|
||||
|
||||
bazelDir :: HasBazel => String -> Path.AbsDir
|
||||
bazelDir x = Path.absDir (Bazel.rlocation ?runfiles ("semantic/semantic/" <> x))
|
||||
|
Loading…
Reference in New Issue
Block a user