diff --git a/.hhconfig b/.hhconfig index 684213d..59fd1d3 100644 --- a/.hhconfig +++ b/.hhconfig @@ -1,6 +1,6 @@ assume_php=false enable_experimental_tc_features = no_fallback_in_namespaces, unpacking_check_arity, disallow_refs_in_array, disallow_untyped_lambda_as_non_function_type -ignored_paths = [ "vendor/.+/tests/.+", "vendor/.+/bin/.+", "tests/fixtures/.+\.tmp\..+\.hack" ] +ignored_paths = [ "vendor/.+/tests/.+", "vendor/.+/bin/.+", "testdata/fixtures/.+\.tmp\..+\.hack", "testdata/fixtures/xhp-class/.+" ] safe_array = true safe_vector_array = true disallow_destruct = true diff --git a/.travis.sh b/.travis.sh index 87c3b50..3d54ba1 100755 --- a/.travis.sh +++ b/.travis.sh @@ -17,3 +17,14 @@ hh_client vendor/bin/hacktest tests/*.hack ENABLE_HH_CLIENT_AUTOLOAD=true vendor/bin/hacktest \ tests/FallbackHandlerTest.hack + +# FactParseScanner should work with any combination of enable_xhp_class_modifier +# and disable_xhp_element_mangling +for A in false true; do + for B in false true; do + hhvm \ + -dhhvm.hack.lang.enable_xhp_class_modifier=$A \ + -dhhvm.hack.lang.disable_xhp_element_mangling=$B \ + vendor/bin/hacktest tests/ScannerTest.hack + done +done diff --git a/tests/fixtures/hh-only/extrafile.php b/testdata/fixtures/hh-only/extrafile.php similarity index 100% rename from tests/fixtures/hh-only/extrafile.php rename to testdata/fixtures/hh-only/extrafile.php diff --git a/tests/fixtures/hh-only/hh_autoload.json b/testdata/fixtures/hh-only/hh_autoload.json similarity index 100% rename from tests/fixtures/hh-only/hh_autoload.json rename to testdata/fixtures/hh-only/hh_autoload.json diff --git a/tests/fixtures/hh-only/is_dev.hack b/testdata/fixtures/hh-only/is_dev.hack similarity index 100% rename from tests/fixtures/hh-only/is_dev.hack rename to testdata/fixtures/hh-only/is_dev.hack diff --git a/tests/fixtures/hh-only/src/class.php b/testdata/fixtures/hh-only/src/class.php similarity index 100% rename from tests/fixtures/hh-only/src/class.php rename to testdata/fixtures/hh-only/src/class.php diff --git a/tests/fixtures/hh-only/src/class_in_hh.hh b/testdata/fixtures/hh-only/src/class_in_hh.hh similarity index 100% rename from tests/fixtures/hh-only/src/class_in_hh.hh rename to testdata/fixtures/hh-only/src/class_in_hh.hh diff --git a/tests/fixtures/hh-only/src/constant.php b/testdata/fixtures/hh-only/src/constant.php similarity index 100% rename from tests/fixtures/hh-only/src/constant.php rename to testdata/fixtures/hh-only/src/constant.php diff --git a/tests/fixtures/hh-only/src/enum.php b/testdata/fixtures/hh-only/src/enum.php similarity index 100% rename from tests/fixtures/hh-only/src/enum.php rename to testdata/fixtures/hh-only/src/enum.php diff --git a/tests/fixtures/hh-only/src/function.php b/testdata/fixtures/hh-only/src/function.php similarity index 100% rename from tests/fixtures/hh-only/src/function.php rename to testdata/fixtures/hh-only/src/function.php diff --git a/tests/fixtures/hh-only/src/newtype.php b/testdata/fixtures/hh-only/src/newtype.php similarity index 100% rename from tests/fixtures/hh-only/src/newtype.php rename to testdata/fixtures/hh-only/src/newtype.php diff --git a/tests/fixtures/hh-only/src/type.php b/testdata/fixtures/hh-only/src/type.php similarity index 100% rename from tests/fixtures/hh-only/src/type.php rename to testdata/fixtures/hh-only/src/type.php diff --git a/tests/fixtures/hh-only/src/xhp_class.php b/testdata/fixtures/hh-only/src/xhp_class.php similarity index 77% rename from tests/fixtures/hh-only/src/xhp_class.php rename to testdata/fixtures/hh-only/src/xhp_class.php index 68a80e6..feafd57 100644 --- a/tests/fixtures/hh-only/src/xhp_class.php +++ b/testdata/fixtures/hh-only/src/xhp_class.php @@ -10,4 +10,5 @@ namespace Facebook\AutoloadMap\TestFixtures; -abstract class :example:xhp-class {} +abstract class :xhp-class-old {} +abstract class :xhp-namespace:xhp-class-old {} diff --git a/tests/fixtures/hh-only/test-dev.php b/testdata/fixtures/hh-only/test-dev.php similarity index 100% rename from tests/fixtures/hh-only/test-dev.php rename to testdata/fixtures/hh-only/test-dev.php diff --git a/tests/fixtures/hh-only/test-prod.php b/testdata/fixtures/hh-only/test-prod.php similarity index 100% rename from tests/fixtures/hh-only/test-prod.php rename to testdata/fixtures/hh-only/test-prod.php diff --git a/tests/fixtures/hh-only/tests/testcase.php b/testdata/fixtures/hh-only/tests/testcase.php similarity index 100% rename from tests/fixtures/hh-only/tests/testcase.php rename to testdata/fixtures/hh-only/tests/testcase.php diff --git a/tests/fixtures/hh-only/vendor/hh_autoloadlh2zH4 b/testdata/fixtures/hh-only/vendor/hh_autoloadlh2zH4 similarity index 100% rename from tests/fixtures/hh-only/vendor/hh_autoloadlh2zH4 rename to testdata/fixtures/hh-only/vendor/hh_autoloadlh2zH4 diff --git a/tests/fixtures/hh-only/vendor/somevendor/someproject/composer-root/VendorComposerExampleClass.php b/testdata/fixtures/hh-only/vendor/somevendor/someproject/composer-root/VendorComposerExampleClass.php similarity index 100% rename from tests/fixtures/hh-only/vendor/somevendor/someproject/composer-root/VendorComposerExampleClass.php rename to testdata/fixtures/hh-only/vendor/somevendor/someproject/composer-root/VendorComposerExampleClass.php diff --git a/tests/fixtures/hh-only/vendor/somevendor/someproject/composer.json b/testdata/fixtures/hh-only/vendor/somevendor/someproject/composer.json similarity index 100% rename from tests/fixtures/hh-only/vendor/somevendor/someproject/composer.json rename to testdata/fixtures/hh-only/vendor/somevendor/someproject/composer.json diff --git a/tests/fixtures/hh-only/vendor/somevendor/someproject/hh-root/VendorHHExampleClass.php b/testdata/fixtures/hh-only/vendor/somevendor/someproject/hh-root/VendorHHExampleClass.php similarity index 100% rename from tests/fixtures/hh-only/vendor/somevendor/someproject/hh-root/VendorHHExampleClass.php rename to testdata/fixtures/hh-only/vendor/somevendor/someproject/hh-root/VendorHHExampleClass.php diff --git a/tests/fixtures/hh-only/vendor/somevendor/someproject/hh_autoload.json b/testdata/fixtures/hh-only/vendor/somevendor/someproject/hh_autoload.json similarity index 100% rename from tests/fixtures/hh-only/vendor/somevendor/someproject/hh_autoload.json rename to testdata/fixtures/hh-only/vendor/somevendor/someproject/hh_autoload.json diff --git a/testdata/fixtures/xhp-class/xhp_class.php b/testdata/fixtures/xhp-class/xhp_class.php new file mode 100644 index 0000000..5cf0307 --- /dev/null +++ b/testdata/fixtures/xhp-class/xhp_class.php @@ -0,0 +1,14 @@ + \escapeshellarg($x), @@ -89,7 +89,7 @@ final class RootImporterTest extends BaseTest { // If a project uses <= 1.3, their existing composer plugin will try to do // this while upgrading, and error out if it fails - so, we need to keep // suppporting it. - $root = __DIR__.'/fixtures/hh-only'; + $root = \realpath(__DIR__.'/../testdata/fixtures/hh-only'); $builder = new RootImporter($root); expect($builder)->toNotBeNull(); } diff --git a/tests/ScannerTest.hack b/tests/ScannerTest.hack index 421e542..11b2211 100644 --- a/tests/ScannerTest.hack +++ b/tests/ScannerTest.hack @@ -9,25 +9,43 @@ namespace Facebook\AutoloadMap; +use namespace HH\Lib\Dict; use type Facebook\HackTest\DataProvider; use function Facebook\FBExpect\expect; final class ScannerTest extends BaseTest { - const string FIXTURES = __DIR__.'/fixtures'; + const string FIXTURES = __DIR__.'/../testdata/fixtures'; const string HH_ONLY_SRC = self::FIXTURES.'/hh-only/src'; + const string XHP_CLASS_SRC = self::FIXTURES.'/xhp-class'; const string FIXTURES_PREFIX = "Facebook\\AutoloadMap\\TestFixtures\\"; <> public function testHHOnly(Parser $parser): void { $map = Scanner::fromTree(self::HH_ONLY_SRC, $parser)->getAutoloadMap(); + // Some of the names returned by FactParseScanner are invalid, but we only + // care about the valid ones being parsed correctly. + if (\ini_get('hhvm.hack.lang.disable_xhp_element_mangling')) { + $xhp_classes = keyset[ + 'xhp-class-old', + 'xhp-namespace\\xhp-class-old', + ]; + } else { + $xhp_classes = keyset[ + 'xhp_xhp_class_old', + 'xhp_xhp_namespace__xhp_class_old', + ]; + } + $this->assertMapMatches( - dict[ - 'ExampleClassInHH' => 'class_in_hh.hh', - 'ExampleClass' => 'class.php', - 'ExampleEnum' => 'enum.php', - 'xhp_example__xhp_class' => 'xhp_class.php', - ], + Dict\merge( + dict[ + 'ExampleClassInHH' => 'class_in_hh.hh', + 'ExampleClass' => 'class.php', + 'ExampleEnum' => 'enum.php', + ], + Dict\from_keys($xhp_classes, $_ ==> 'xhp_class.php'), + ), $map['class'], ); @@ -53,6 +71,33 @@ final class ScannerTest extends BaseTest { ); } + <> + public function testNewXHPClassSyntax(Parser $parser): void { + if (!\ini_get('hhvm.hack.lang.enable_xhp_class_modifier')) { + self::markTestSkipped('requires enable_xhp_class_modifier=true'); + } + + $map = Scanner::fromTree(self::XHP_CLASS_SRC, $parser)->getAutoloadMap(); + + if (\ini_get('hhvm.hack.lang.disable_xhp_element_mangling')) { + $xhp_classes = keyset[ + 'xhp_class_new', + 'xhp_namespace\\xhp_class_new', + ]; + } else { + $xhp_classes = keyset[ + 'xhp_class_new', + 'xhp_namespace__xhp_class_new', + ]; + } + + $this->assertMapMatches( + Dict\from_keys($xhp_classes, $_ ==> 'xhp_class.php'), + $map['class'], + self::XHP_CLASS_SRC, + ); + } + <> public function testFromTree( Parser $parser, @@ -85,9 +130,10 @@ final class ScannerTest extends BaseTest { private function assertMapMatches( dict $expected, dict $actual, + string $path_prefix = self::HH_ONLY_SRC, ): void { foreach ($expected as $name => $file) { - $a = self::HH_ONLY_SRC.'/'.$file; + $a = $path_prefix.'/'.$file; $b = idx($actual, \strtolower(self::FIXTURES_PREFIX.$name)) ?? idx($actual, self::FIXTURES_PREFIX.$name) ?? idx($actual, $name);