2018-03-20 00:42:00 +03:00
|
|
|
module Analysis.PHP.Spec (spec) where
|
|
|
|
|
2018-05-28 22:44:48 +03:00
|
|
|
import Control.Abstract
|
2018-05-10 17:03:59 +03:00
|
|
|
import Data.Abstract.Environment as Env
|
2018-05-07 00:37:44 +03:00
|
|
|
import Data.Abstract.Evaluatable (EvalError(..))
|
2018-04-24 02:47:13 +03:00
|
|
|
import qualified Data.Language as Language
|
2018-06-26 00:36:32 +03:00
|
|
|
import qualified Data.Abstract.ModuleTable as ModuleTable
|
2018-05-28 16:35:42 +03:00
|
|
|
import qualified Language.PHP.Assignment as PHP
|
2018-03-20 00:42:00 +03:00
|
|
|
import SpecHelpers
|
|
|
|
|
|
|
|
|
2018-07-10 21:09:22 +03:00
|
|
|
spec :: TaskConfig -> Spec
|
|
|
|
spec config = parallel $ do
|
2018-03-23 18:57:02 +03:00
|
|
|
describe "PHP" $ do
|
|
|
|
it "evaluates include and require" $ do
|
2018-06-26 22:14:28 +03:00
|
|
|
(_, (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-09-15 01:04:08 +03:00
|
|
|
Right (Just (Module _ (_, (env, addr)) :| [])) -> do
|
2018-06-26 00:36:32 +03:00
|
|
|
heapLookupAll addr heap `shouldBe` Just [unit]
|
|
|
|
Env.names env `shouldBe` [ "bar", "foo" ]
|
|
|
|
other -> expectationFailure (show other)
|
2018-03-21 02:46:32 +03:00
|
|
|
|
2018-03-23 18:57:02 +03:00
|
|
|
it "evaluates include_once and require_once" $ do
|
2018-06-26 22:14:28 +03:00
|
|
|
(_, (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-09-15 01:04:08 +03:00
|
|
|
Right (Just (Module _ (_, (env, addr)) :| [])) -> do
|
2018-06-26 00:36:32 +03:00
|
|
|
heapLookupAll addr heap `shouldBe` Just [unit]
|
|
|
|
Env.names env `shouldBe` [ "bar", "foo" ]
|
|
|
|
other -> expectationFailure (show other)
|
2018-03-23 18:57:02 +03:00
|
|
|
|
|
|
|
it "evaluates namespaces" $ do
|
2018-06-26 22:14:28 +03:00
|
|
|
(_, (heap, res)) <- evaluate ["namespaces.php"]
|
2018-06-26 00:36:32 +03:00
|
|
|
case ModuleTable.lookup "namespaces.php" <$> res of
|
2018-09-15 01:04:08 +03:00
|
|
|
Right (Just (Module _ (_, (env, addr)) :| [])) -> do
|
2018-06-26 00:36:32 +03:00
|
|
|
Env.names env `shouldBe` [ "Foo", "NS1" ]
|
2018-05-10 17:03:59 +03:00
|
|
|
|
2018-07-19 10:03:17 +03:00
|
|
|
(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 <>)
|
2018-08-02 17:24:55 +03:00
|
|
|
evalPHPProject = testEvaluating <=< evaluateProject' config (Proxy :: Proxy 'Language.PHP) phpParser
|