Skip to content

Commit 4b75bf2

Browse files
author
Patrick Thomson
committed
Start abstracting away the details of language tests.
1 parent 79ae94b commit 4b75bf2

File tree

7 files changed

+62
-29
lines changed

7 files changed

+62
-29
lines changed

WORKSPACE

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,8 @@ new_git_repository(
215215
name = "tree-sitter-ruby",
216216
build_file_content = """
217217
exports_files(["src/node-types.json"])
218+
219+
filegroup(name = "corpus", srcs = glob(['**/corpus/*.txt']), visibility = ["//visibility:public"])
218220
""",
219221
commit = "eb2b6225bfb80010f2e4cbd27db8c6f3775230b5",
220222
remote = "https://github.com/tree-sitter/tree-sitter-ruby.git",
@@ -235,6 +237,8 @@ new_git_repository(
235237
name = "tree-sitter-php",
236238
build_file_content = """
237239
exports_files(["src/node-types.json"])
240+
241+
filegroup(name = "corpus", srcs = glob(['**/corpus/*.txt']), visibility = ["//visibility:public"])
238242
""",
239243
commit = "41a408d5b996ef54d8b9e1b9a2469fad00c1b52b",
240244
remote = "https://github.com/tree-sitter/tree-sitter-php.git",

build/common.bzl

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ package(default_visibility = ["//visibility:public"])
4040
4141
exports_files(glob(["{}"]))
4242
43-
filegroup(name = "corpus", srcs = glob(['corpus/*.txt']))
43+
filegroup(name = "corpus", srcs = glob(['**/corpus/*.txt']))
4444
""".format(nodetypespath),
4545
strip_prefix = "{}-{}".format(name, version),
4646
urls = ["https://github.com/tree-sitter/{}/archive/v{}.tar.gz".format(name, version)],
@@ -90,3 +90,25 @@ def semantic_language_library(language, name, srcs, nodetypes = "", **kwargs):
9090
"@stackage//:tree-sitter-" + language,
9191
],
9292
)
93+
94+
def semantic_language_parsing_test(language):
95+
haskell_test(
96+
name = "test",
97+
srcs = ["test/PreciseTest.hs"],
98+
data = ["@tree-sitter-{}//:corpus".format(language)],
99+
deps = [
100+
":semantic-{}".format(language),
101+
"//:base",
102+
"//:bytestring",
103+
"//:text",
104+
"//semantic:fixtureshim",
105+
"//semantic-ast",
106+
"@stackage//:bazel-runfiles",
107+
"@stackage//:hedgehog",
108+
"@stackage//:pathtype",
109+
"@stackage//:tasty",
110+
"@stackage//:tasty-hedgehog",
111+
"@stackage//:tasty-hunit",
112+
"@stackage//:tree-sitter-" + language,
113+
],
114+
)

semantic-go/BUILD.bazel

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package(default_visibility = ["//visibility:public"])
33
load(
44
"//:build/common.bzl",
55
"semantic_language_library",
6+
"semantic_language_parsing_test",
67
)
78
load(
89
"@rules_haskell//haskell:defs.bzl",
@@ -15,22 +16,4 @@ semantic_language_library(
1516
language = "go",
1617
)
1718

18-
haskell_test(
19-
name = "test",
20-
srcs = ["test/PreciseTest.hs"],
21-
data = ["@tree-sitter-go//:corpus"],
22-
deps = [
23-
":semantic-go",
24-
"//:base",
25-
"//:bytestring",
26-
"//:text",
27-
"//semantic:fixtureshim",
28-
"//semantic-ast",
29-
"@stackage//:bazel-runfiles",
30-
"@stackage//:hedgehog",
31-
"@stackage//:pathtype",
32-
"@stackage//:tasty",
33-
"@stackage//:tasty-hedgehog",
34-
"@stackage//:tasty-hunit",
35-
],
36-
)
19+
semantic_language_parsing_test(language = "go")

semantic-php/BUILD.bazel

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@ package(default_visibility = ["//visibility:public"])
33
load(
44
"//:build/common.bzl",
55
"semantic_language_library",
6+
"semantic_language_parsing_test",
67
)
78

89
semantic_language_library(
910
name = "semantic-php",
1011
srcs = glob(["src/**/*.hs"]),
1112
language = "php",
1213
)
14+
15+
semantic_language_parsing_test(language = "php")

semantic-ruby/BUILD.bazel

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package(default_visibility = ["//visibility:public"])
33
load(
44
"//:build/common.bzl",
55
"semantic_language_library",
6+
"semantic_language_parsing_test",
67
)
78

89
semantic_language_library(
@@ -12,4 +13,4 @@ semantic_language_library(
1213
nodetypes = "@tree-sitter-ruby//:src/node-types.json",
1314
)
1415

15-
haskell_test
16+
semantic_language_parsing_test(language = "ruby")

semantic-ruby/test/PreciseTest.hs

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,31 @@
1-
{-# LANGUAGE DisambiguateRecordFields, OverloadedStrings, TypeApplications #-}
1+
{-# LANGUAGE DisambiguateRecordFields, OverloadedStrings, TypeApplications, ImplicitParams #-}
22
module Main (main) where
33

44
import TreeSitter.Ruby
55
import AST.TestHelpers
66
import AST.Unmarshal
7-
import qualified Language.Ruby.AST as Rb
7+
import qualified Language.Ruby.AST as Ruby
88
import qualified System.Path as Path
99
import Test.Tasty
10+
import qualified Bazel.Runfiles as Runfiles
11+
import qualified System.Path.Fixture as Fixture
12+
import System.IO
13+
import Control.Concurrent
1014

1115
main :: IO ()
12-
main
13-
= Path.absDir <$> Rb.getTestCorpusDir
14-
>>= readCorpusFiles'
15-
>>= traverse (testCorpus parse)
16-
>>= defaultMain . tests
17-
where parse = parseByteString @Rb.Program @() tree_sitter_ruby
16+
main = do
17+
rf <- Runfiles.create
18+
-- dirs <- Path.absDir <$> Ruby.getTestCorpusDir
19+
let ?project = Path.relDir "semantic-ruby"
20+
?runfiles = rf
21+
let dirs = Fixture.bazelDir "/../external/tree-sitter-ruby/test/corpus"
22+
hFlush stdout
23+
threadDelay 0
24+
25+
readCorpusFiles' dirs
26+
>>= traverse (testCorpus parse)
27+
>>= defaultMain . tests
28+
where parse = parseByteString @Ruby.Program @() tree_sitter_ruby
1829

1930
tests :: [TestTree] -> TestTree
2031
tests = testGroup "tree-sitter-ruby corpus tests"

semantic/test/System/Path/Fixture.hs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ module System.Path.Fixture
77
bazelDir,
88
HasFixture,
99
absRelDir,
10+
delay,
1011
)
1112
where
1213

@@ -15,13 +16,21 @@ import Data.Proxy
1516
import GHC.Stack
1617
import GHC.TypeLits
1718
import qualified System.Path as Path
19+
import Control.Concurrent
20+
import System.IO
1821

1922
type HasFixture =
2023
( ?runfiles :: Bazel.Runfiles,
2124
?project :: Path.RelDir,
2225
HasCallStack
2326
)
2427

28+
delay :: String -> IO ()
29+
delay s = do
30+
putStrLn s
31+
hFlush stdout
32+
threadDelay 10000000
33+
2534
absFile :: (HasFixture) => String -> Path.AbsFile
2635
absFile x = Path.absFile (Bazel.rlocation ?runfiles ("semantic/" <> Path.toString ?project <> x))
2736

0 commit comments

Comments
 (0)