forked from facebook/hermes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDebuggerTest.cpp
More file actions
53 lines (43 loc) · 1.45 KB
/
Copy pathDebuggerTest.cpp
File metadata and controls
53 lines (43 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the LICENSE
* file in the root directory of this source tree.
*/
#ifdef HERMES_ENABLE_DEBUGGER
#include <gtest/gtest.h>
#include <hermes/DebuggerAPI.h>
#include <hermes/hermes.h>
#include <memory>
using namespace facebook::hermes;
using namespace facebook::hermes::debugger;
struct TestEventObserver : public debugger::EventObserver {
std::vector<PauseReason> pauseReasons;
Command didPause(Debugger &debugger) override {
pauseReasons.push_back(debugger.getProgramState().getPauseReason());
return Command::continueExecution();
}
};
struct DebuggerAPITest : public ::testing::Test {
void eval(const std::string &code) {
rt->global().getPropertyAsFunction(*rt, "eval").call(*rt, code);
}
std::shared_ptr<HermesRuntime> rt;
TestEventObserver observer;
DebuggerAPITest() : rt(makeHermesRuntime()) {
rt->getDebugger().setEventObserver(&observer);
}
};
TEST_F(DebuggerAPITest, SetAgentTest) {
// A basic test that exercises setting the debugger event observer by virtue
// of running the DebuggerAPITest constructor.
}
TEST_F(DebuggerAPITest, BasicPauseTest) {
// Test that a basic Pause scenario works.
eval("var x = 5; debugger; x=8; debugger;");
EXPECT_EQ(
std::vector<PauseReason>(
{PauseReason::DebuggerStatement, PauseReason::DebuggerStatement}),
observer.pauseReasons);
}
#endif