/* +----------------------------------------------------------------------+ | HipHop for PHP | +----------------------------------------------------------------------+ | Copyright (c) 2010- Facebook, Inc. (http://www.facebook.com) | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | http://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | license@php.net so we can mail you a copy immediately. | +----------------------------------------------------------------------+ */ #include #include #include #include #include #include /////////////////////////////////////////////////////////////////////////////// TestCodeError::TestCodeError() { Option::IncludeRoots["$_SERVER['PHP_ROOT']"] = ""; } bool TestCodeError::RunTests(const std::string &which) { bool ret = true; #define CODE_ERROR_ENTRY(x) RUN_TEST(Test ## x); #include "../compiler/analysis/core_code_error.inc" #undef CODE_ERROR_ENTRY return ret; } bool TestCodeError::Verify(Compiler::ErrorType type, const char *src, const char *file, int line, bool exists) { WithOpt w0(Option::RecordErrors); WithOpt w1(Option::WholeProgram); WithOpt w2(Option::ParseTimeOpts); Compiler::ClearErrors(); Type::ResetTypeHintTypes(); Type::InitTypeHintMap(); BuiltinSymbols::LoadSuperGlobals(); AnalysisResultPtr ar(new AnalysisResult()); // for TestPHPIncludeFileNotInLib Compiler::Parser::ParseString("analyzeProgram(); ar->inferTypes(); ar->analyzeProgramFinal(); if (Compiler::HasError(type) != exists) { std::ostringstream error; JSON::CodeError::OutputStream out(error, ar); Compiler::SaveErrors(out); printf("%s:%d: parsing %s\ncode error missing\n%s\n", file, line, src, error.str().c_str()); return false; } return true; } /////////////////////////////////////////////////////////////////////////////// bool TestCodeError::TestBadPHPIncludeFile() { VE(BadPHPIncludeFile, "a; }"); */ VE(UseUndeclaredVariable, "a(); }"); // negatve cases VEN(UnknownObjectMethod, "a(); }"); VEN(UnknownObjectMethod, "a();}"); return true; } bool TestCodeError::TestInvalidMagicMethod() { VE(InvalidMagicMethod, "> class C {}"); VE(DeclaredAttributeTwice, "> function f() {}"); return true; } bool TestCodeError::TestBadDefine() { VE(BadDefine, "t();"); VE(TooFewArgument, "t(1);"); VE(TooFewArgument, "t(1);}"); VE(TooManyArgument, "a;}} A::test();"); VE(MissingObjectContext, "a();}} A::test();"); // negative case VEN(MissingObjectContext, "foo(1); } }"); VEN(BadPassByReference, "f());" "set_to_null($obj->m);" "set_to_null(A::$n);"); VEN(BadPassByReference, "$ar = array(" " array('10', 11, 100, 100, 'a')," " array( 1, 2, '2', 3, 1)" " );" "array_multisort($ar[0], SORT_ASC, SORT_STRING," " $ar[1], SORT_NUMERIC, SORT_DESC);"); return true; } bool TestCodeError::TestConditionalClassLoading() { VE(ConditionalClassLoading, "