Skip to content

Commit 1dc1a3a

Browse files
author
Patrick Thomson
committed
Give the Bazel shim a better name, because we'll use this in Cabal
1 parent 68cb87d commit 1dc1a3a

File tree

7 files changed

+65
-58
lines changed

7 files changed

+65
-58
lines changed

semantic/BUILD.bazel

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ haskell_binary(
124124

125125
haskell_library(
126126
name = "fixtureshim",
127-
srcs = ["test/System/Path/Bazel.hs"],
127+
srcs = ["test/System/Path/Fixture.hs"],
128128
deps = [
129129
"//:base",
130130
"@stackage//:bazel-runfiles",
@@ -139,7 +139,7 @@ haskell_test(
139139
exclude = [
140140
"test/fixtures/**/*.hs",
141141
"test/Examples.hs",
142-
"test/System/Path/Bazel.hs",
142+
"test/System/Path/Fixture.hs",
143143
],
144144
),
145145
compiler_flags = STANDARD_GHC_WARNINGS + STANDARD_EXECUTABLE_FLAGS + [

semantic/test/Examples.hs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import System.Path ((</>))
2828
import qualified System.Path as Path
2929
import qualified System.Path.Directory as Path
3030
import qualified System.Process as Process
31-
import qualified System.Path.Bazel as Fixture
31+
import qualified System.Path.Fixture as Fixture
3232
import qualified Bazel.Runfiles as Runfiles
3333
import qualified Test.Tasty as Tasty
3434
import qualified Test.Tasty.HUnit as HUnit
@@ -131,7 +131,7 @@ typescriptSkips = Path.relFile <$>
131131
, "npm/node_modules/request/node_modules/har-validator/node_modules/ajv/dist/regenerator.min.js"
132132
]
133133

134-
buildExamples :: Fixture.HasBazel => TaskSession -> LanguageExample -> Path.AbsRelDir -> IO Tasty.TestTree
134+
buildExamples :: Fixture.HasFixture => TaskSession -> LanguageExample -> Path.AbsRelDir -> IO Tasty.TestTree
135135
buildExamples session lang tsDir = do
136136
let fileSkips = fmap (tsDir </>) (languageSkips lang)
137137
dirSkips = fmap (tsDir </>) (languageDirSkips lang)
@@ -170,6 +170,7 @@ main = withOptions testOptions $ \ config logger statter -> do
170170

171171
rf <- Runfiles.create
172172
let ?runfiles = rf
173+
let ?project = Path.relDir "semantic"
173174

174175
let session = TaskSession config "-" False logger statter
175176

semantic/test/Semantic/CLI/Spec.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ import Serializing.Format
1212
import System.IO.Unsafe
1313
import System.Path ((</>))
1414
import qualified System.Path as Path
15-
import qualified System.Path.Bazel as Path
15+
import qualified System.Path.Fixture as Path
1616
import qualified System.Path.Directory as Path
1717

1818
import SpecHelpers
1919
import Test.Tasty
2020
import Test.Tasty.Golden
2121

2222
-- TODO: Fix this, or throw it out entirely.
23-
testTree :: Path.HasBazel => TestTree
23+
testTree :: Path.HasFixture => TestTree
2424
testTree = testGroup "Semantic.CLI"
2525
[ testGroup "parseTermBuilder" $ fmap testForParseFixture parseFixtures
2626
]

semantic/test/Spec.hs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,15 @@ import qualified Semantic.CLI.Spec
1313
import qualified Semantic.IO.Spec
1414
import qualified Semantic.Stat.Spec
1515
import qualified Bazel.Runfiles as Bazel
16-
import qualified System.Path.Bazel as Path
16+
import qualified System.Path as Path
17+
import qualified System.Path.Fixture as Fixture
1718
import Semantic.Config (defaultOptions, optionsLogLevel)
1819
import Semantic.Task (withOptions, TaskSession(..))
1920
import Test.Hspec
2021
import Test.Tasty as Tasty
2122
import Test.Tasty.Hspec as Tasty
2223

23-
tests :: (?session :: TaskSession, Path.HasBazel) => [TestTree]
24+
tests :: (?session :: TaskSession, Fixture.HasFixture) => [TestTree]
2425
tests =
2526
[ Data.Language.Spec.testTree
2627
, Data.Semigroup.App.Spec.testTree
@@ -31,7 +32,7 @@ tests =
3132

3233
-- We can't bring this out of the IO monad until we divest
3334
-- from hspec, since testSpec operates in IO.
34-
allTests :: (?session :: TaskSession, Path.HasBazel) => IO TestTree
35+
allTests :: (?session :: TaskSession, Fixture.HasFixture) => IO TestTree
3536
allTests = do
3637
asTastySpecs <- Tasty.testSpecs legacySpecs
3738
let allSpecs = tests <> asTastySpecs
@@ -43,7 +44,7 @@ allTests = do
4344
-- documentation: "hspec and tasty serve similar purposes; consider
4445
-- using one or the other.") Instead, create a new TestTree value
4546
-- in your spec module and add it to the above 'tests' list.
46-
legacySpecs :: Path.HasBazel => Spec
47+
legacySpecs :: Fixture.HasFixture => Spec
4748
legacySpecs = parallel $ do
4849
describe "Data.Graph" Data.Graph.Spec.spec
4950
describe "Data.Functor.Classes.Generic" Data.Functor.Classes.Generic.Spec.spec
@@ -58,4 +59,5 @@ main = do
5859
withOptions defaultOptions { optionsLogLevel = Nothing } $ \ config logger statter ->
5960
let ?session = TaskSession config "-" False logger statter
6061
?runfiles = runfiles
62+
?project = Path.relDir "semantic"
6163
in allTests >>= defaultMain

semantic/test/System/Path/Bazel.hs

Lines changed: 0 additions & 31 deletions
This file was deleted.

semantic/test/System/Path/Fixture.hs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{-# LANGUAGE ConstraintKinds #-}
2+
{-# LANGUAGE ImplicitParams #-}
3+
4+
module System.Path.Fixture
5+
( absFile,
6+
absRelFile,
7+
bazelDir,
8+
HasFixture,
9+
absRelDir,
10+
)
11+
where
12+
13+
import qualified Bazel.Runfiles as Bazel
14+
import Data.Proxy
15+
import GHC.Stack
16+
import GHC.TypeLits
17+
import qualified System.Path as Path
18+
19+
type HasFixture =
20+
( ?runfiles :: Bazel.Runfiles,
21+
?project :: Path.RelDir,
22+
HasCallStack
23+
)
24+
25+
absFile :: (HasFixture) => String -> Path.AbsFile
26+
absFile x = Path.absFile (Bazel.rlocation ?runfiles ("semantic/" <> Path.toString ?project <> x))
27+
28+
absRelFile :: (HasFixture) => String -> Path.AbsRelFile
29+
absRelFile = Path.toAbsRel . absFile
30+
31+
bazelDir :: HasFixture => String -> Path.AbsDir
32+
bazelDir x = Path.absDir (Bazel.rlocation ?runfiles ("semantic/" <> Path.toString ?project <> x))
33+
34+
absRelDir :: HasFixture => String -> Path.AbsRelDir
35+
absRelDir = Path.toAbsRel . bazelDir

semantic/test/Tags/Spec.hs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,82 +7,82 @@ import Semantic.Api.Symbols
77
import Source.Loc
88
import SpecHelpers
99
import qualified System.Path as Path
10-
import qualified System.Path.Bazel as Path
10+
import qualified System.Path.Fixture as Fixture
1111
import Tags.Tagging.Precise
1212

13-
spec :: Path.HasBazel => Spec
13+
spec :: Fixture.HasFixture => Spec
1414
spec = do
1515
describe "go" $ do
1616
it "produces tags for functions with docs (TODO)" $
17-
parseTestFile [P.FUNCTION] (Path.bazelFile "test/fixtures/go/tags/simple_functions.go") `shouldReturn`
17+
parseTestFile [P.FUNCTION] (Fixture.absFile "test/fixtures/go/tags/simple_functions.go") `shouldReturn`
1818
[ Tag "TestFromBits" P.FUNCTION P.DEFINITION (Loc (Range 56 68) (Span (Pos 6 6) (Pos 6 18))) "func TestFromBits(t *testing.T) {" Nothing
1919
, Tag "Hi" P.FUNCTION P.DEFINITION (Loc (Range 99 101) (Span (Pos 10 6) (Pos 10 8))) "func Hi() {" Nothing ]
2020

2121
it "produces tags for methods" $
22-
parseTestFile [] (Path.bazelFile "test/fixtures/go/tags/method.go") `shouldReturn`
22+
parseTestFile [] (Fixture.absFile "test/fixtures/go/tags/method.go") `shouldReturn`
2323
[ Tag "CheckAuth" P.METHOD P.DEFINITION (Loc (Range 39 48) (Span (Pos 3 21) (Pos 3 30))) "func (c *apiClient) CheckAuth(req *http.Request, user, repo string) (*authenticatedActor, error) {}" Nothing]
2424

2525
it "produces tags for calls" $
26-
parseTestFile [P.CALL] (Path.bazelFile "test/fixtures/go/tags/simple_functions.go") `shouldReturn`
26+
parseTestFile [P.CALL] (Fixture.absFile "test/fixtures/go/tags/simple_functions.go") `shouldReturn`
2727
[ Tag "Hi" P.CALL P.REFERENCE (Loc (Range 86 88) (Span (Pos 7 2) (Pos 7 4))) "Hi()" Nothing]
2828

2929
describe "javascript and typescript" $ do
3030
it "produces tags for functions with docs (TODO)" $
31-
parseTestFile [] (Path.bazelFile "test/fixtures/javascript/tags/simple_function_with_docs.js") `shouldReturn`
31+
parseTestFile [] (Fixture.absFile "test/fixtures/javascript/tags/simple_function_with_docs.js") `shouldReturn`
3232
[ Tag "myFunction" P.FUNCTION P.DEFINITION (Loc (Range 31 41) (Span (Pos 2 10) (Pos 2 20))) "function myFunction() {" Nothing ]
3333

3434
it "produces tags for classes" $
35-
parseTestFile [] (Path.bazelFile "test/fixtures/typescript/tags/class.ts") `shouldReturn`
35+
parseTestFile [] (Fixture.absFile "test/fixtures/typescript/tags/class.ts") `shouldReturn`
3636
[ Tag "FooBar" P.CLASS P.DEFINITION (Loc (Range 6 12) (Span (Pos 1 7) (Pos 1 13))) "class FooBar {}" Nothing ]
3737

3838
it "produces tags for modules" $
39-
parseTestFile [] (Path.bazelFile "test/fixtures/typescript/tags/module.ts") `shouldReturn`
39+
parseTestFile [] (Fixture.absFile "test/fixtures/typescript/tags/module.ts") `shouldReturn`
4040
[ Tag "APromise" P.MODULE P.DEFINITION (Loc (Range 7 15) (Span (Pos 1 8) (Pos 1 16))) "module APromise { }" Nothing ]
4141

4242
describe "python" $ do
4343
it "produces tags for functions" $
44-
parseTestFile [] (Path.bazelFile "test/fixtures/python/tags/simple_functions.py") `shouldReturn`
44+
parseTestFile [] (Fixture.absFile "test/fixtures/python/tags/simple_functions.py") `shouldReturn`
4545
[ Tag "Foo" P.FUNCTION P.DEFINITION (Loc (Range 4 7) (Span (Pos 1 5) (Pos 1 8))) "def Foo(x):" Nothing
4646
, Tag "Bar" P.FUNCTION P.DEFINITION (Loc (Range 74 77) (Span (Pos 7 5) (Pos 7 8))) "def Bar():" Nothing
4747
, Tag "local" P.FUNCTION P.DEFINITION (Loc (Range 89 94) (Span (Pos 8 9) (Pos 8 14))) "def local():" Nothing
4848
]
4949

5050
it "produces tags for functions with docs" $
51-
parseTestFile [] (Path.bazelFile "test/fixtures/python/tags/simple_function_with_docs.py") `shouldReturn`
51+
parseTestFile [] (Fixture.absFile "test/fixtures/python/tags/simple_function_with_docs.py") `shouldReturn`
5252
[ Tag "Foo" P.FUNCTION P.DEFINITION (Loc (Range 4 7) (Span (Pos 1 5) (Pos 1 8))) "def Foo(x):" (Just "\"\"\"This is the foo function\"\"\"") ]
5353

5454
it "produces tags for classes" $
55-
parseTestFile [] (Path.bazelFile "test/fixtures/python/tags/class.py") `shouldReturn`
55+
parseTestFile [] (Fixture.absFile "test/fixtures/python/tags/class.py") `shouldReturn`
5656
[ Tag "Foo" P.CLASS P.DEFINITION (Loc (Range 6 9) (Span (Pos 1 7) (Pos 1 10))) "class Foo:" (Just "\"\"\"The Foo class\"\"\"")
5757
, Tag "f" P.FUNCTION P.DEFINITION (Loc (Range 43 44) (Span (Pos 3 9) (Pos 3 10))) "def f(self):" (Just "\"\"\"The f method\"\"\"")
5858
]
5959

6060
it "produces tags for multi-line functions" $
61-
parseTestFile [P.FUNCTION] (Path.bazelFile "test/fixtures/python/tags/multiline.py") `shouldReturn`
61+
parseTestFile [P.FUNCTION] (Fixture.absFile "test/fixtures/python/tags/multiline.py") `shouldReturn`
6262
[ Tag "Foo" P.FUNCTION P.DEFINITION (Loc (Range 4 7) (Span (Pos 1 5) (Pos 1 8))) "def Foo(x," Nothing ]
6363

6464
describe "ruby" $ do
6565
it "produces tags for methods" $
66-
parseTestFile [P.METHOD] (Path.bazelFile "test/fixtures/ruby/tags/simple_method.rb") `shouldReturn`
66+
parseTestFile [P.METHOD] (Fixture.absFile "test/fixtures/ruby/tags/simple_method.rb") `shouldReturn`
6767
[ Tag "foo" P.METHOD P.DEFINITION (Loc (Range 4 7) (Span (Pos 1 5) (Pos 1 8))) "def foo" Nothing ]
6868

6969
it "produces tags for sends" $
70-
parseTestFile [P.CALL] (Path.bazelFile "test/fixtures/ruby/tags/simple_method.rb") `shouldReturn`
70+
parseTestFile [P.CALL] (Fixture.absFile "test/fixtures/ruby/tags/simple_method.rb") `shouldReturn`
7171
[ Tag "puts" P.CALL P.REFERENCE (Loc (Range 10 14) (Span (Pos 2 3) (Pos 2 7))) "puts \"hi\"" Nothing
7272
, Tag "bar" P.CALL P.REFERENCE (Loc (Range 24 27) (Span (Pos 3 5) (Pos 3 8))) "a.bar" Nothing
7373
, Tag "a" P.CALL P.REFERENCE (Loc (Range 22 23) (Span (Pos 3 3) (Pos 3 4))) "a" Nothing
7474
]
7575

7676
it "produces tags for methods with docs (TODO)" $
77-
parseTestFile [] (Path.bazelFile "test/fixtures/ruby/tags/simple_method_with_docs.rb") `shouldReturn`
77+
parseTestFile [] (Fixture.absFile "test/fixtures/ruby/tags/simple_method_with_docs.rb") `shouldReturn`
7878
[ Tag "foo" P.METHOD P.DEFINITION (Loc (Range 18 21) (Span (Pos 2 5) (Pos 2 8))) "def foo" Nothing ]
7979

8080
it "correctly tags files containing multibyte UTF-8 characters (TODO)" $
81-
parseTestFile [] (Path.bazelFile "test/fixtures/ruby/tags/unicode_identifiers.rb") `shouldReturn`
81+
parseTestFile [] (Fixture.absFile "test/fixtures/ruby/tags/unicode_identifiers.rb") `shouldReturn`
8282
[ Tag "日本語" P.METHOD P.DEFINITION (Loc (Range 20 29) (Span (Pos 2 5) (Pos 2 14))) "def 日本語" Nothing]
8383

8484
it "produces tags for methods and classes with docs (TODO)" $
85-
parseTestFile [P.MODULE, P.CLASS, P.METHOD] (Path.bazelFile "test/fixtures/ruby/tags/class_module.rb") `shouldReturn`
85+
parseTestFile [P.MODULE, P.CLASS, P.METHOD] (Fixture.absFile "test/fixtures/ruby/tags/class_module.rb") `shouldReturn`
8686
[ Tag "Foo" P.MODULE P.DEFINITION (Loc (Range 21 24) (Span (Pos 2 8) (Pos 2 11))) "module Foo" Nothing
8787
, Tag "Bar" P.CLASS P.DEFINITION (Loc (Range 50 53) (Span (Pos 5 9) (Pos 5 12))) "class Bar" Nothing
8888
, Tag "baz" P.METHOD P.DEFINITION (Loc (Range 81 84) (Span (Pos 8 9) (Pos 8 12))) "def baz(a)" Nothing

0 commit comments

Comments
 (0)