mirror of
https://github.com/github/semantic.git
synced 2024-11-28 01:47:01 +03:00
Remove aLaCarteLanguageModes from tests and benchmarks
This commit is contained in:
parent
7348d95c46
commit
ba9715281c
@ -9,7 +9,7 @@ import Control.Carrier.Reader
|
||||
import Control.Exception (throwIO)
|
||||
import Control.Monad
|
||||
import Data.Foldable
|
||||
import Data.Language (PerLanguageModes (..), aLaCarteLanguageModes, preciseLanguageModes)
|
||||
import Data.Language (PerLanguageModes (..), preciseLanguageModes)
|
||||
import Gauge
|
||||
import System.FilePath.Glob
|
||||
import qualified System.Path as Path
|
||||
@ -32,21 +32,18 @@ benchmarks = bgroup "tagging"
|
||||
pythonBenchmarks :: Benchmark
|
||||
pythonBenchmarks = bgroup "python"
|
||||
[ bench "precise" $ runTagging preciseLanguageModes pyDir "*.py"
|
||||
, bench "a la carte" $ runTagging aLaCarteLanguageModes pyDir "*.py"
|
||||
]
|
||||
where pyDir = Path.relDir "tmp/python-examples/keras/keras"
|
||||
|
||||
goBenchmarks :: Benchmark
|
||||
goBenchmarks = bgroup "go"
|
||||
[ bench "precise" $ runTagging preciseLanguageModes dir "*.go"
|
||||
, bench "a la carte" $ runTagging aLaCarteLanguageModes dir "*.go"
|
||||
]
|
||||
where dir = Path.relDir "tmp/go-examples/go/src/database/sql"
|
||||
|
||||
rubyBenchmarks :: Benchmark
|
||||
rubyBenchmarks = bgroup "ruby"
|
||||
[ bench "precise" $ runTagging preciseLanguageModes dir "*.rb"
|
||||
, bench "a la carte" $ runTagging aLaCarteLanguageModes dir "*.rb"
|
||||
]
|
||||
where dir = Path.relDir "tmp/ruby-examples/ruby_spec/command_line"
|
||||
|
||||
|
@ -18,7 +18,7 @@ import Control.Monad
|
||||
import Data.Blob
|
||||
import Data.Foldable
|
||||
import Data.Int
|
||||
import Data.Language (LanguageMode (..), PerLanguageModes (..), aLaCarteLanguageModes, preciseLanguageModes)
|
||||
import Data.Language (LanguageMode (..), PerLanguageModes (..), preciseLanguageModes)
|
||||
import Data.List
|
||||
import qualified Data.Text as Text
|
||||
import Data.Traversable
|
||||
@ -162,21 +162,9 @@ buildExamples session lang tsDir = do
|
||||
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.testCaseSteps (Path.toString file) $ \step -> do
|
||||
-- Use alacarte language mode
|
||||
step "a la carte"
|
||||
alacarte <- runTask session (runParse (parseSymbolsFilePath aLaCarteLanguageModes file))
|
||||
assertOK "a la carte" alacarte
|
||||
|
||||
-- Test out precise language mode
|
||||
step "precise"
|
||||
pure . HUnit.testCase (Path.toString file) $ do
|
||||
precise <- runTask session (runParse (parseSymbolsFilePath preciseLanguageModes file))
|
||||
assertOK "precise" precise
|
||||
|
||||
-- Compare the two
|
||||
step "compare"
|
||||
assertMatch alacarte precise
|
||||
|
||||
pure (Tasty.testGroup (languageName lang) trees)
|
||||
|
||||
where
|
||||
@ -185,88 +173,10 @@ buildExamples session lang tsDir = do
|
||||
[x] | (e:_) <- toList (x^.errors) -> HUnit.assertFailure (msg <> " parse errors " <> show e)
|
||||
_ -> pure ()
|
||||
|
||||
assertMatch a b = case (a, b) of
|
||||
(Right a, Right b) -> case (toList (a^.files), toList (b^.files)) of
|
||||
([x], [y]) | e1:_ <- toList (x^.errors)
|
||||
, e2:_ <- toList (y^.errors)
|
||||
-> HUnit.assertFailure ("Parse errors (both) " <> show e1 <> show e2)
|
||||
(_, [y]) | e:_ <- toList (y^.errors)
|
||||
-> HUnit.assertFailure ("Parse errors (precise) " <> show e)
|
||||
([x], _) | e:_ <- toList (x^.errors)
|
||||
-> HUnit.assertFailure ("Parse errors (a la carte) " <> show e)
|
||||
([x], [y]) -> do
|
||||
-- Check paths
|
||||
HUnit.assertEqual "Expected paths to be equal" (x^.path) (y^.path)
|
||||
|
||||
-- Check symbols
|
||||
let aLaCarteSymbols = sort . filterALaCarteSymbols (languageName lang) $ toListOf (symbols . traverse . symbol) x
|
||||
preciseSymbols = sort . filterALaCarteSymbols (languageName lang) $ toListOf (symbols . traverse . symbol) y
|
||||
delta = aLaCarteSymbols \\ preciseSymbols
|
||||
invDelta = preciseSymbols \\ aLaCarteSymbols
|
||||
msg = "Found in a la carte, but not precise: "
|
||||
<> show delta
|
||||
<> "\n"
|
||||
<> "Found in precise but not a la carte: "
|
||||
<> show invDelta
|
||||
<> "\n"
|
||||
<> "Expected: " <> show aLaCarteSymbols <> "\n"
|
||||
<> "But got:" <> show preciseSymbols
|
||||
HUnit.assertBool ("Expected symbols to be equal.\n" <> msg) (null delta)
|
||||
HUnit.assertBool ("Expected symbols to be equal.\n" <> msg) (null invDelta)
|
||||
|
||||
-- Check details
|
||||
let aLaCarteSymbols = sortOn sSym . filter (okALaCarteSymbol (languageName lang) . view symbol) $ toList (x^.symbols)
|
||||
preciseSymbols = sortOn sSym . filter (okALaCarteSymbol (languageName lang) . view symbol) $ toList (y^.symbols)
|
||||
for_ (zip aLaCarteSymbols preciseSymbols) $ \ (left, right) -> do
|
||||
let lineNo = ":" <> show (left^.P.span^.start^.line)
|
||||
-- lSpan = " [" <> show (startRow left) <> ", " <> show (left^.P.span^.start^.column) <> "]"
|
||||
-- rSpan = " [" <> show (startRow right) <> ", " <> show (right^.P.span^.start^.column) <> "]"
|
||||
HUnit.assertEqual (Text.unpack (x^.path) <> lineNo) (left^.symbol) (right^.symbol)
|
||||
HUnit.assertEqual (Text.unpack (x^.path) <> lineNo) (Text.unpack (left^.symbol) <> span left) (Text.unpack (right^.symbol) <> span right)
|
||||
|
||||
-- HUnit.assertEqual (Text.unpack (x^.path) <> lineNo) (left^.line) (right^.line)
|
||||
-- HUnit.assertBool (Text.unpack (x^.path) <> lineNo) (Text.isPrefixOf (left^.line) (right^.line))
|
||||
-- if left^.kind == "Method"
|
||||
-- then HUnit.assertEqual (Text.unpack (x^.path) <> lineNo) (left^.line) (right^.line)
|
||||
-- -- -- then HUnit.assertBool (Text.unpack (x^.path) <> lineNo) (Text.isPrefixOf (left^.line) (right^.line))
|
||||
-- else pure ()
|
||||
|
||||
_ -> HUnit.assertFailure "Expected 1 file in each response"
|
||||
(Left e1, Left e2) -> HUnit.assertFailure ("Unable to parse (both)" <> show (displayException e1) <> show (displayException e2))
|
||||
(_, Left e) -> HUnit.assertFailure ("Unable to parse (precise)" <> show (displayException e))
|
||||
(Left e, _) -> HUnit.assertFailure ("Unable to parse (a la carte)" <> show (displayException e))
|
||||
|
||||
sSym x = SortableSymbol (x^.symbol) (x^.P.span^.start^.line) (x^.P.span^.start^.column) (x^.P.span^.end^.line) (x^.P.span^.end^.column)
|
||||
span x = " [" <> show (x^.P.span^.start^.line) <> ", " <> show (x^.P.span^.start^.column) <>
|
||||
" - " <> show (x^.P.span^.end^.line) <> ", " <> show (x^.P.span^.end^.column) <> "]"
|
||||
|
||||
data SortableSymbol = SortableSymbol Text.Text Int32 Int32 Int32 Int32
|
||||
deriving (Eq, Show, Ord)
|
||||
|
||||
|
||||
okALaCarteSymbol :: String -> Text.Text -> Bool
|
||||
okALaCarteSymbol "typescript" symbol = symbol `notElem` blacklist
|
||||
where
|
||||
blacklist = ["require"]
|
||||
okALaCarteSymbol "ruby" symbol = not (instanceVariable symbol || builtInMethod symbol)
|
||||
where
|
||||
instanceVariable = Text.isPrefixOf "@"
|
||||
builtInMethod x = x `elem` blacklist
|
||||
blacklist =
|
||||
[ "alias"
|
||||
, "load"
|
||||
, "require_relative"
|
||||
, "require"
|
||||
, "super"
|
||||
, "undef"
|
||||
, "defined?"
|
||||
, "lambda"
|
||||
]
|
||||
okALaCarteSymbol _ _ = True
|
||||
|
||||
filterALaCarteSymbols :: String -> [Text.Text] -> [Text.Text]
|
||||
filterALaCarteSymbols lang = filter (okALaCarteSymbol lang)
|
||||
|
||||
testOptions :: Config.Options
|
||||
testOptions = defaultOptions
|
||||
{ optionsFailOnWarning = flag FailOnWarning True
|
||||
@ -274,6 +184,7 @@ testOptions = defaultOptions
|
||||
}
|
||||
|
||||
main :: IO ()
|
||||
-- main = putStrLn "nothing"
|
||||
main = withOptions testOptions $ \ config logger statter -> do
|
||||
void $ Process.system "script/clone-example-repos"
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user