2018-03-16 21:09:41 +03:00
|
|
|
{-# LANGUAGE OverloadedLists, TypeApplications #-}
|
2018-03-13 20:26:28 +03:00
|
|
|
module Analysis.Go.Spec (spec) where
|
2018-03-12 23:52:50 +03:00
|
|
|
|
2018-03-13 20:26:28 +03:00
|
|
|
import Data.Abstract.Value
|
|
|
|
import Data.Map
|
2018-03-13 20:59:06 +03:00
|
|
|
|
2018-03-12 23:52:50 +03:00
|
|
|
import SpecHelpers
|
|
|
|
|
|
|
|
|
|
|
|
spec :: Spec
|
|
|
|
spec = parallel $ do
|
|
|
|
describe "evalutes Go" $ do
|
|
|
|
it "imports and wildcard imports" $ do
|
2018-03-14 21:38:49 +03:00
|
|
|
env <- evaluate "main.go"
|
2018-03-16 21:09:41 +03:00
|
|
|
let expectedEnv =
|
2018-03-12 23:52:50 +03:00
|
|
|
[ (qualifiedName ["foo", "New"], addr 0)
|
2018-03-13 23:09:04 +03:00
|
|
|
, (qualifiedName ["Rab"], addr 1)
|
|
|
|
, (qualifiedName ["Bar"], addr 2)
|
|
|
|
, (qualifiedName ["main"], addr 3)
|
2018-03-12 23:52:50 +03:00
|
|
|
]
|
2018-03-14 21:38:49 +03:00
|
|
|
env `shouldBe` expectedEnv
|
2018-03-12 23:52:50 +03:00
|
|
|
|
|
|
|
it "imports with aliases (and side effects only)" $ do
|
2018-03-14 21:38:49 +03:00
|
|
|
env <- evaluate "main1.go"
|
2018-03-16 21:09:41 +03:00
|
|
|
let expectedEnv =
|
2018-03-12 23:52:50 +03:00
|
|
|
[ (qualifiedName ["f", "New"], addr 0)
|
2018-03-13 23:09:04 +03:00
|
|
|
, (qualifiedName ["main"], addr 3) -- addr 3 is due to side effects of
|
|
|
|
-- eval'ing `import _ "./bar"` which
|
|
|
|
-- used addr 1 & 2.
|
2018-03-12 23:52:50 +03:00
|
|
|
]
|
2018-03-14 21:38:49 +03:00
|
|
|
env `shouldBe` expectedEnv
|
2018-03-12 23:52:50 +03:00
|
|
|
|
|
|
|
where
|
|
|
|
addr = Address . Precise
|
|
|
|
fixtures = "test/fixtures/go/analysis/"
|
2018-03-15 17:23:50 +03:00
|
|
|
evaluate entry = snd . fst . fst . fst . fst <$>
|
2018-03-15 23:04:36 +03:00
|
|
|
evaluateFiles goParser
|
2018-03-12 23:52:50 +03:00
|
|
|
[ fixtures <> entry
|
|
|
|
, fixtures <> "foo/foo.go"
|
|
|
|
, fixtures <> "bar/bar.go"
|
2018-03-13 23:09:04 +03:00
|
|
|
, fixtures <> "bar/rab.go"
|
2018-03-12 23:52:50 +03:00
|
|
|
]
|