2019-06-12 20:53:59 +03:00
|
|
|
{-# LANGUAGE ImplicitParams #-}
|
2019-06-11 01:53:20 +03:00
|
|
|
{-# OPTIONS_GHC -O0 #-}
|
2018-03-20 00:42:00 +03:00
|
|
|
module Analysis.PHP.Spec (spec) where
|
|
|
|
|
2018-06-26 00:36:32 +03:00
|
|
|
import qualified Data.Abstract.ModuleTable as ModuleTable
|
2018-12-12 01:21:57 +03:00
|
|
|
import qualified Data.Abstract.Value.Concrete as Value
|
2018-12-05 18:14:16 +03:00
|
|
|
import qualified Data.Language as Language
|
|
|
|
import SpecHelpers
|
2018-03-20 00:42:00 +03:00
|
|
|
|
|
|
|
|
2019-06-12 20:53:59 +03:00
|
|
|
spec :: (?session :: TaskSession) => Spec
|
|
|
|
spec = parallel $ do
|
2018-03-23 18:57:02 +03:00
|
|
|
describe "PHP" $ do
|
2018-11-29 21:05:54 +03:00
|
|
|
xit "evaluates include and require" $ do
|
2018-11-29 20:31:42 +03:00
|
|
|
(scopeGraph, (heap, res)) <- evaluate ["main.php", "foo.php", "bar.php"]
|
2018-06-26 00:36:32 +03:00
|
|
|
case ModuleTable.lookup "main.php" <$> res of
|
2018-12-11 21:07:45 +03:00
|
|
|
Right (Just (Module _ (scopeAndFrame, value))) -> do
|
2018-12-12 01:21:57 +03:00
|
|
|
value `shouldBe` Value.Unit
|
2019-06-16 18:14:03 +03:00
|
|
|
SpecHelpers.lookupDeclaration "bar" scopeAndFrame heap scopeGraph `shouldSatisfy` isJust
|
|
|
|
SpecHelpers.lookupDeclaration "foo" scopeAndFrame heap scopeGraph `shouldSatisfy` isJust
|
2018-06-26 00:36:32 +03:00
|
|
|
other -> expectationFailure (show other)
|
2018-03-21 02:46:32 +03:00
|
|
|
|
2018-11-29 21:05:54 +03:00
|
|
|
xit "evaluates include_once and require_once" $ do
|
2018-11-29 20:31:42 +03:00
|
|
|
(scopeGraph, (heap, res)) <- evaluate ["main_once.php", "foo.php", "bar.php"]
|
2018-06-26 00:36:32 +03:00
|
|
|
case ModuleTable.lookup "main_once.php" <$> res of
|
2018-12-11 21:07:45 +03:00
|
|
|
Right (Just (Module _ (scopeAndFrame, value))) -> do
|
2018-12-12 01:21:57 +03:00
|
|
|
value `shouldBe` Value.Unit
|
2019-06-16 18:14:03 +03:00
|
|
|
SpecHelpers.lookupDeclaration "bar" scopeAndFrame heap scopeGraph `shouldSatisfy` isJust
|
|
|
|
SpecHelpers.lookupDeclaration "foo" scopeAndFrame heap scopeGraph `shouldSatisfy` isJust
|
2018-06-26 00:36:32 +03:00
|
|
|
other -> expectationFailure (show other)
|
2018-03-23 18:57:02 +03:00
|
|
|
|
2018-11-29 21:05:54 +03:00
|
|
|
xit "evaluates namespaces" $ do
|
2018-11-29 20:31:42 +03:00
|
|
|
(scopeGraph, (heap, res)) <- evaluate ["namespaces.php"]
|
2018-06-26 00:36:32 +03:00
|
|
|
case ModuleTable.lookup "namespaces.php" <$> res of
|
2019-06-15 07:53:02 +03:00
|
|
|
Right (Just (Module _ (scopeAndFrame, _))) -> do
|
2019-06-16 18:14:03 +03:00
|
|
|
SpecHelpers.lookupDeclaration "Foo" scopeAndFrame heap scopeGraph `shouldSatisfy` isJust
|
|
|
|
SpecHelpers.lookupDeclaration "NS1" scopeAndFrame heap scopeGraph `shouldSatisfy` isJust
|
2018-05-10 17:03:59 +03:00
|
|
|
|
2018-11-08 02:27:56 +03:00
|
|
|
undefined
|
|
|
|
-- (derefQName heap ("NS1" :| []) env >>= deNamespace heap) `shouldBe` Just ("NS1", ["Sub1", "b", "c"])
|
|
|
|
-- (derefQName heap ("NS1" :| ["Sub1"]) env >>= deNamespace heap) `shouldBe` Just ("Sub1", ["Sub2"])
|
|
|
|
-- (derefQName heap ("NS1" :| ["Sub1", "Sub2"]) env >>= deNamespace heap) `shouldBe` Just ("Sub2", ["f"])
|
2018-06-26 00:36:32 +03:00
|
|
|
other -> expectationFailure (show other)
|
2018-03-20 00:42:00 +03:00
|
|
|
|
|
|
|
where
|
|
|
|
fixtures = "test/fixtures/php/analysis/"
|
2018-06-22 22:45:42 +03:00
|
|
|
evaluate = evalPHPProject . map (fixtures <>)
|
2019-06-12 20:53:59 +03:00
|
|
|
evalPHPProject = testEvaluating <=< evaluateProject' ?session (Proxy :: Proxy 'Language.PHP) phpParser
|