Skip to content

Commit

Permalink
regression tests
Browse files Browse the repository at this point in the history
Summary:
1. new test case `cpp-xlang` contains manually annotated C++ and thrift files. Generated test output contains correct thrift xrefs
2. added new test runner which runs two indexers, the one in the test driver + an extra-one supplied as parameter
3. added new routing rules in repomapping, as we need to route cpp and thrift requests to different dbs
4. revert the thrift annotations from `fbcode/glean/lang/codemarkup/tests/clang/glass/namespace1/`, as it's subsumed by `cpp-xlang`

For 2, I initially tried to generalize the Driver type so it supports a list of indexers but I couldn't find a satisfying solution, and it would have required a lot of refactoring.

Reviewed By: simonmar

Differential Revision: D56188923

fbshipit-source-id: d480c5d2f65aa988f19c7b52985607b168e9d332
  • Loading branch information
Philippe Bidinger authored and facebook-github-bot committed Apr 29, 2024
1 parent f1ecc67 commit a69dada
Show file tree
Hide file tree
Showing 95 changed files with 2,088 additions and 3,955 deletions.
15 changes: 6 additions & 9 deletions glean/glass/Glean/Glass/Repos.hs
Original file line number Diff line number Diff line change
Expand Up @@ -176,15 +176,12 @@ normalizeLanguages l = l
-- | Select universe of glean repo,(db/language) pairs.
-- Either just the test dbs, or all the non-test dbs.
listGleanIndices :: RepoMapping -> Bool -> [(RepoName, (GleanDBName, Language))]
listGleanIndices RepoMapping{..} testsOnly
| not testsOnly = concatMap flatten $ -- only non-test repos
Map.toList (Map.delete testRepo gleanIndices)
| otherwise = map (testRepo,) $ -- just the test repos
Map.findWithDefault [] testRepo gleanIndices
where
testRepo = RepoName "test"

flatten (repo,langs) = map (repo,) langs
listGleanIndices RepoMapping{..} testsOnly =
let testRepos = [RepoName "test", RepoName "test-xlang"]
flatten (repo,langs) = map (repo,) langs
flattened = concatMap flatten $ Map.toList gleanIndices
isTest = \(repo, _) -> elem repo testRepos in
filter (if testsOnly then isTest else not . isTest) flattened

-- Do something simple to map SCS repo to Glean repos
-- Names from configerator/scm/myles/service as a start
Expand Down
24 changes: 24 additions & 0 deletions glean/glass/test/regression/Glean/Glass/Regression/CppXLang.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{-
Copyright (c) Meta Platforms, Inc. and affiliates.
All rights reserved.
This source code is licensed under the BSD-style license found in the
LICENSE file in the root directory of this source tree.
-}

module Glean.Glass.Regression.CppXLang (main) where

import qualified Glean.Clang.Test.DerivePass as DerivePass

import qualified Glean.Regression.Driver.DeriveForCodemarkup as Code
import Glean.Indexer.Fbthrift as Fbthrift (indexer)
import Glean.Glass.Regression.Snapshot (mainGlassSnapshotXLang)

main :: IO ()
main = mainGlassSnapshotXLang
testName
testPath (d, "test-xlang-source") (Fbthrift.indexer, "test-xlang-target")
where
d = DerivePass.driver Code.codemarkupDerivePasses
testName = "glass-regression-cpp-xlang"
testPath = "glean/glass/test/regression/tests/cpp-xlang"
20 changes: 20 additions & 0 deletions glean/glass/test/regression/lib/Glean/Glass/Regression/Snapshot.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
module Glean.Glass.Regression.Snapshot (
mainGlassSnapshot,
mainGlassSnapshotGeneric,
mainGlassSnapshotXLang,
Cfg(..),
Output, Getter
) where
Expand Down Expand Up @@ -46,6 +47,7 @@ import qualified Thrift.Protocol
import qualified Thrift.Protocol.JSON as Thrift

import Glean ( Repo )
import Glean.Indexer
import Glean.LocalOrRemote ( LocalOrRemote )
import Glean.Util.Some ( Some(..) )
import Glean.Regression.Test
Expand Down Expand Up @@ -139,6 +141,24 @@ mainGlassSnapshot_ testName testRoot driver extraOpts extras = do
withOutput (Just out) f = f out
withOutput Nothing f = withSystemTempDirectory testName f

mainGlassSnapshotXLang
:: String
-> FilePath
-> (Glean.Driver opt, Text)
-> (Indexer opts, Text)
-> IO ()
mainGlassSnapshotXLang testName testRoot driver indexer = do
cfgReplace <- any (`elem` ["--replace", "--replace-all"]) <$> getArgs
qs <- findQueries testRoot
withOutput cfgOutput $ \temp ->
mainTestIndexXlang driver indexer testName $
\get -> TestList [testAll cfgReplace temp qs get]
where
cfgOutput = Nothing

withOutput (Just out) f = f out
withOutput Nothing f = withSystemTempDirectory testName f

testAll :: Bool -> FilePath -> Map.Map String FilePath -> Getter -> Test
testAll cfgReplace outDir queries getter = TestList
[ mkTest cfgReplace getter name qfile outDir
Expand Down
286 changes: 286 additions & 0 deletions glean/glass/test/regression/tests/cpp-xlang/documentSymbolIndex.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,286 @@
[
"@generated",
{
"digest": {
"hash": "c19eedb242a1867935300bf022d4b8ab3d92ae00",
"size": 420
},
"referenced_file_digests": {
"test-xlang": {
"test.cpp": {
"hash": "c19eedb242a1867935300bf022d4b8ab3d92ae00",
"size": 420
},
"test.h": {
"hash": "d31759d38b8e2df1b27e81d34d0d077bf3c73c8d",
"size": 324
}
}
},
"revision": "testhash",
"size": 7,
"symbols": {
"12": [
{
"attributes": {
"symbolDefinitionType": {
"aInteger": 2
},
"symbolKind": {
"aInteger": 14
},
"symbolLanguage": {
"aInteger": 1
},
"symbolName": {
"aString": "thrift1"
},
"symbolParent": {
"aString": ""
},
"symbolSignature": {
"aString": "void thrift1()"
}
},
"range": {
"columnBegin": 6,
"columnEnd": 13,
"lineBegin": 12,
"lineEnd": 12
},
"sym": "test-xlang/cpp//thrift1/.f//.decl"
}
],
"15": [
{
"attributes": {
"symbolDefinitionType": {
"aInteger": 1
},
"symbolKind": {
"aInteger": 14
},
"symbolLanguage": {
"aInteger": 1
},
"symbolName": {
"aString": "thriftCaller"
},
"symbolParent": {
"aString": ""
},
"symbolSignature": {
"aString": "void thriftCaller()"
}
},
"range": {
"columnBegin": 6,
"columnEnd": 18,
"lineBegin": 15,
"lineEnd": 15
},
"sym": "test-xlang/cpp//thriftCaller/.f/"
}
],
"16": [
{
"attributes": {
"symbolDefinitionType": {
"aInteger": 2
},
"symbolKind": {
"aInteger": 14
},
"symbolLanguage": {
"aInteger": 1
},
"symbolName": {
"aString": "thrift1"
},
"symbolParent": {
"aString": ""
},
"symbolSignature": {
"aString": "void thrift1()"
}
},
"range": {
"columnBegin": 3,
"columnEnd": 10,
"lineBegin": 16,
"lineEnd": 16
},
"sym": "test-xlang/cpp//thrift1/.f//.decl",
"target": {
"filepath": "test.cpp",
"range": {
"columnBegin": 6,
"columnEnd": 13,
"lineBegin": 12,
"lineEnd": 12
},
"repository": "test-xlang"
}
},
{
"attributes": {
"crossLanguage": {
"aString": "thrift"
},
"symbolIdl": {
"aString": "thrift"
},
"symbolLanguage": {
"aInteger": 9
},
"symbolName": {
"aString": "thrift1"
},
"symbolParent": {
"aString": "TestService"
},
"symbolSignature": {
"aString": "function test::TestService::thrift1"
}
},
"range": {
"columnBegin": 3,
"columnEnd": 10,
"lineBegin": 16,
"lineEnd": 16
},
"sym": "test-xlang/thrift/test.thrift/TestService/thrift1",
"target": {
"filepath": "test.thrift",
"range": {
"columnBegin": 3,
"columnEnd": 5,
"lineBegin": 39,
"lineEnd": 41
},
"repository": "test-xlang"
}
}
],
"17": [
{
"attributes": {
"symbolDefinitionType": {
"aInteger": 2
},
"symbolKind": {
"aInteger": 14
},
"symbolLanguage": {
"aInteger": 1
},
"symbolName": {
"aString": "thrift2"
},
"symbolParent": {
"aString": ""
},
"symbolSignature": {
"aString": "void thrift2()"
}
},
"range": {
"columnBegin": 3,
"columnEnd": 10,
"lineBegin": 17,
"lineEnd": 17
},
"sym": "test-xlang/cpp//thrift2/.f//.decl",
"target": {
"filepath": "test.h",
"range": {
"columnBegin": 6,
"columnEnd": 13,
"lineBegin": 11,
"lineEnd": 11
},
"repository": "test-xlang"
}
},
{
"attributes": {
"crossLanguage": {
"aString": "thrift"
},
"symbolIdl": {
"aString": "thrift"
},
"symbolLanguage": {
"aInteger": 9
},
"symbolName": {
"aString": "thrift2"
},
"symbolParent": {
"aString": "TestService"
},
"symbolSignature": {
"aString": "function test::TestService::thrift2"
}
},
"range": {
"columnBegin": 3,
"columnEnd": 10,
"lineBegin": 17,
"lineEnd": 17
},
"sym": "test-xlang/thrift/test.thrift/TestService/thrift2",
"target": {
"filepath": "test.thrift",
"range": {
"columnBegin": 3,
"columnEnd": 5,
"lineBegin": 43,
"lineEnd": 45
},
"repository": "test-xlang"
}
}
],
"9": [
{
"attributes": {
"symbolDefinitionType": {
"aInteger": 1
},
"symbolKind": {
"aInteger": 4
},
"symbolLanguage": {
"aInteger": 8
},
"symbolName": {
"aString": "test.h"
},
"symbolParent": {
"aString": ""
}
},
"range": {
"columnBegin": 1,
"columnEnd": 18,
"lineBegin": 9,
"lineEnd": 9
},
"sym": "test-xlang/pp/test.h",
"target": {
"filepath": "test.h",
"range": {
"columnBegin": 1,
"columnEnd": 1,
"lineBegin": 1,
"lineEnd": 1
},
"repository": "test-xlang"
}
}
]
},
"truncated": false
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
action: documentSymbolIndex
args: {"include_refs":true,"filepath":"test.cpp","repository":"test-xlang"}
Loading

0 comments on commit a69dada

Please sign in to comment.