Commit bc5677de authored by jameslahm's avatar jameslahm Committed by V8 LUCI CQ

[test] Move cctest/parsing to unittests/parser

This CL moves cctest/parsing/{test-parse-decision,
test-scanner-streams, test-scanner} to unittests/{
parse-decision-unittest, scanner-streams-unittest,
scanner-unittest}.

Bug: v8:12781
Change-Id: I2adfeaf2ccc796f17d6b7010c77b1f65c6ce593e
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3612668
Commit-Queue: 王澳 <wangao.james@bytedance.com>
Reviewed-by: 's avatarLeszek Swirski <leszeks@chromium.org>
Cr-Commit-Position: refs/heads/main@{#80588}
parent 2a606bdb
......@@ -161,10 +161,7 @@ v8_source_set("cctest_sources") {
"interpreter/test-source-positions.cc",
"libplatform/test-tracing.cc",
"manually-externalized-buffer.h",
"parsing/test-parse-decision.cc",
"parsing/test-preparser.cc",
"parsing/test-scanner-streams.cc",
"parsing/test-scanner.cc",
"print-extension.cc",
"print-extension.h",
"profiler-extension.cc",
......
......@@ -411,7 +411,10 @@ v8_source_set("unittests_sources") {
"objects/value-serializer-unittest.cc",
"objects/weakarraylist-unittest.cc",
"parser/ast-value-unittest.cc",
"parser/parse-decision-unittest.cc",
"parser/preparser-unittest.cc",
"parser/scanner-streams-unittest.cc",
"parser/scanner-unittest.cc",
"profiler/circular-queue-unittest.cc",
"profiler/strings-storage-unittest.cc",
"regexp/regexp-unittest.cc",
......
......@@ -17,11 +17,22 @@
#include "src/objects/objects-inl.h"
#include "src/objects/shared-function-info-inl.h"
#include "src/utils/utils.h"
#include "test/cctest/cctest.h"
#include "test/unittests/test-utils.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace v8 {
namespace internal {
class ParseDecisionTest : public TestWithContext {
public:
Local<v8::Script> Compile(const char* source) {
return v8::Script::Compile(
context(),
v8::String::NewFromUtf8(isolate(), source).ToLocalChecked())
.ToLocalChecked();
}
};
namespace {
// Record the 'compiled' state of all top level functions.
......@@ -43,28 +54,24 @@ void GetTopLevelFunctionInfo(
} // anonymous namespace
TEST(GetTopLevelFunctionInfo) {
TEST_F(ParseDecisionTest, GetTopLevelFunctionInfo) {
if (!FLAG_lazy) return;
Isolate* isolate = CcTest::i_isolate();
HandleScope scope(isolate);
LocalContext env;
HandleScope scope(i_isolate());
const char src[] = "function foo() { var a; }\n";
std::unordered_map<std::string, bool> is_compiled;
GetTopLevelFunctionInfo(v8_compile(src), &is_compiled);
GetTopLevelFunctionInfo(Compile(src), &is_compiled);
// Test that our helper function GetTopLevelFunctionInfo does what it claims:
DCHECK(is_compiled.find("foo") != is_compiled.end());
DCHECK(is_compiled.find("bar") == is_compiled.end());
}
TEST(EagerlyCompileImmediateUseFunctions) {
TEST_F(ParseDecisionTest, EagerlyCompileImmediateUseFunctions) {
if (!FLAG_lazy) return;
Isolate* isolate = CcTest::i_isolate();
HandleScope scope(isolate);
LocalContext env;
HandleScope scope(i_isolate());
// Test parenthesized, exclaimed, and regular functions. Make sure these
// occur both intermixed and after each other, to make sure the 'reset'
......@@ -80,7 +87,7 @@ TEST(EagerlyCompileImmediateUseFunctions) {
"function normal4() { var h; }\n";
std::unordered_map<std::string, bool> is_compiled;
GetTopLevelFunctionInfo(v8_compile(src), &is_compiled);
GetTopLevelFunctionInfo(Compile(src), &is_compiled);
DCHECK(is_compiled["parenthesized"]);
DCHECK(is_compiled["parenthesized2"]);
......@@ -92,16 +99,14 @@ TEST(EagerlyCompileImmediateUseFunctions) {
DCHECK(!is_compiled["normal4"]);
}
TEST(CommaFunctionSequence) {
TEST_F(ParseDecisionTest, CommaFunctionSequence) {
if (!FLAG_lazy) return;
Isolate* isolate = CcTest::i_isolate();
HandleScope scope(isolate);
LocalContext env;
HandleScope scope(i_isolate());
const char src[] = "!function a(){}(),function b(){}(),function c(){}();";
std::unordered_map<std::string, bool> is_compiled;
GetTopLevelFunctionInfo(v8_compile(src), &is_compiled);
GetTopLevelFunctionInfo(Compile(src), &is_compiled);
DCHECK(is_compiled["a"]);
DCHECK(is_compiled["b"]);
......
......@@ -5,42 +5,47 @@
// Tests v8::internal::Scanner. Note that presently most unit tests for the
// Scanner are in cctest/test-parsing.cc, rather than here.
#include "src/parsing/scanner.h"
#include "src/handles/handles-inl.h"
#include "src/objects/objects-inl.h"
#include "src/parsing/parse-info.h"
#include "src/parsing/scanner-character-streams.h"
#include "src/parsing/scanner.h"
#include "test/cctest/cctest.h"
#include "test/unittests/test-utils.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace v8 {
namespace internal {
namespace {
const char src_simple[] = "function foo() { var x = 2 * a() + b; }";
struct ScannerTestHelper {
ScannerTestHelper() = default;
ScannerTestHelper(ScannerTestHelper&& other) V8_NOEXCEPT
: stream(std::move(other.stream)),
scanner(std::move(other.scanner)) {}
class ScannerTest : public TestWithIsolate {
public:
struct ScannerTestHelper {
ScannerTestHelper() = default;
ScannerTestHelper(ScannerTestHelper&& other) V8_NOEXCEPT
: stream(std::move(other.stream)),
scanner(std::move(other.scanner)) {}
std::unique_ptr<Utf16CharacterStream> stream;
std::unique_ptr<Scanner> scanner;
std::unique_ptr<Utf16CharacterStream> stream;
std::unique_ptr<Scanner> scanner;
Scanner* operator->() const { return scanner.get(); }
Scanner* get() const { return scanner.get(); }
Scanner* operator->() const { return scanner.get(); }
Scanner* get() const { return scanner.get(); }
};
ScannerTestHelper make_scanner(const char* src) {
ScannerTestHelper helper;
helper.stream = ScannerStream::ForTesting(src);
helper.scanner = std::unique_ptr<Scanner>(new Scanner(
helper.stream.get(),
UnoptimizedCompileFlags::ForTest(
reinterpret_cast<i::Isolate*>(v8::Isolate::GetCurrent()))));
helper.scanner->Initialize();
return helper;
}
};
namespace {
ScannerTestHelper make_scanner(const char* src) {
ScannerTestHelper helper;
helper.stream = ScannerStream::ForTesting(src);
helper.scanner = std::unique_ptr<Scanner>(
new Scanner(helper.stream.get(),
UnoptimizedCompileFlags::ForTest(CcTest::i_isolate())));
helper.scanner->Initialize();
return helper;
}
const char src_simple[] = "function foo() { var x = 2 * a() + b; }";
} // anonymous namespace
......@@ -48,7 +53,7 @@ ScannerTestHelper make_scanner(const char* src) {
// names. That should have the same result, but has much nicer error messaages.
#define CHECK_TOK(a, b) CHECK_EQ(Token::Name(a), Token::Name(b))
TEST(Bookmarks) {
TEST_F(ScannerTest, Bookmarks) {
// Scan through the given source and record the tokens for use as reference
// below.
std::vector<Token::Value> tokens;
......@@ -84,7 +89,7 @@ TEST(Bookmarks) {
}
}
TEST(AllThePushbacks) {
TEST_F(ScannerTest, AllThePushbacks) {
const struct {
const char* src;
const Token::Value tokens[5]; // Large enough for any of the test cases.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment