2018-03-13 20:26:28 +03:00
|
|
|
module Analysis.Go.Spec (spec) where
|
2018-03-12 23:52:50 +03:00
|
|
|
|
2018-05-07 00:37:44 +03:00
|
|
|
import Data.Abstract.Evaluatable (EvalError(..))
|
2018-06-26 00:38:52 +03:00
|
|
|
import qualified Data.Abstract.ModuleTable as ModuleTable
|
2018-04-24 02:47:13 +03:00
|
|
|
import qualified Data.Language as Language
|
2018-05-28 16:35:42 +03:00
|
|
|
import qualified Language.Go.Assignment as Go
|
2018-03-12 23:52:50 +03:00
|
|
|
import SpecHelpers
|
|
|
|
|
|
|
|
|
2018-07-10 21:09:22 +03:00
|
|
|
spec :: TaskConfig -> Spec
|
|
|
|
spec config = parallel $ do
|
2018-06-25 18:55:54 +03:00
|
|
|
describe "Go" $ do
|
2018-03-12 23:52:50 +03:00
|
|
|
it "imports and wildcard imports" $ do
|
2018-11-09 02:22:35 +03:00
|
|
|
(_, res) <- evaluate ["main.go", "foo/foo.go", "bar/bar.go", "bar/rab.go"]
|
2018-06-26 00:38:52 +03:00
|
|
|
case ModuleTable.lookup "main.go" <$> res of
|
2018-11-29 02:47:10 +03:00
|
|
|
Right (Just (Module _ (scopeGraph, (heap, (addresses, valueRef))) :| [])) -> do
|
|
|
|
() <$ SpecHelpers.lookupDeclaration "foo" addresses heap scopeGraph `shouldBe` Just ()
|
|
|
|
(SpecHelpers.lookupDeclaration "foo" addresses heap scopeGraph >>= objectMembers heap scopeGraph . head) `shouldBe` Just ["New"]
|
|
|
|
() <$ SpecHelpers.lookupDeclaration "main" addresses heap scopeGraph `shouldBe` Just ()
|
|
|
|
() <$ SpecHelpers.lookupDeclaration "Bar" addresses heap scopeGraph `shouldBe` Just ()
|
|
|
|
() <$ SpecHelpers.lookupDeclaration "Rab" addresses heap scopeGraph `shouldBe` Just ()
|
2018-06-26 00:38:52 +03:00
|
|
|
other -> expectationFailure (show other)
|
2018-03-12 23:52:50 +03:00
|
|
|
|
|
|
|
it "imports with aliases (and side effects only)" $ do
|
2018-11-09 02:22:35 +03:00
|
|
|
(_, res) <- evaluate ["main1.go", "foo/foo.go", "bar/bar.go", "bar/rab.go"]
|
2018-06-26 00:38:52 +03:00
|
|
|
case ModuleTable.lookup "main1.go" <$> res of
|
2018-11-29 02:47:10 +03:00
|
|
|
Right (Just (Module _ (scopeGraph, (heap, (addresses, valueRef))) :| [])) -> do
|
|
|
|
const () <$> SpecHelpers.lookupDeclaration "f" addresses heap scopeGraph `shouldBe` Just ()
|
|
|
|
const () <$> SpecHelpers.lookupDeclaration "main" addresses heap scopeGraph `shouldBe` Just ()
|
2018-11-09 02:22:35 +03:00
|
|
|
-- (lookupDeclaration "f" heap >>= deNamespace heap) `shouldBe` Just ("f", ["New"])
|
2018-06-26 00:38:52 +03:00
|
|
|
other -> expectationFailure (show other)
|
2018-03-12 23:52:50 +03:00
|
|
|
|
|
|
|
where
|
|
|
|
fixtures = "test/fixtures/go/analysis/"
|
2018-06-22 22:45:42 +03:00
|
|
|
evaluate = evalGoProject . map (fixtures <>)
|
2018-08-02 17:24:55 +03:00
|
|
|
evalGoProject = testEvaluating <=< evaluateProject' config (Proxy :: Proxy 'Language.Go) goParser
|