Skip to content

Commit

Permalink
Fix linux tests build
Browse files Browse the repository at this point in the history
Summary:
Move JSON parsing into the JSON helper, fixing
the linux test build.

Differential Revision: D56733388
  • Loading branch information
Matt Blagden authored and facebook-github-bot committed Apr 30, 2024
1 parent 0888914 commit 190dc20
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
5 changes: 1 addition & 4 deletions unittests/API/CDPAgentTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -364,9 +364,6 @@ void CDPAgentTest::expectErrorMessageContaining(
void CDPAgentTest::expectHeapSnapshot(
int messageID,
bool ignoreTrackingNotifications) {
JSLexer::Allocator jsonAlloc;
JSONFactory factory(jsonAlloc);

// Expect chunk notifications until the snapshot object is complete. Fail if
// the object is invalid (e.g. truncated data, excess data, malformed JSON).
// There is no indication of how many segments there will be, so just receive
Expand All @@ -383,7 +380,7 @@ void CDPAgentTest::expectHeapSnapshot(

ASSERT_EQ(method, "HeapProfiler.addHeapSnapshotChunk");
snapshot << jsonScope_.getString(note, {"params", "chunk"});
} while (!parseStrAsJsonObj(snapshot.str(), factory).has_value());
} while (!jsonScope_.tryParseObject(snapshot.str()).has_value());

// Expect the snapshot response after all chunks have been received.
ensureOkResponse(waitForMessage(), messageID);
Expand Down
4 changes: 4 additions & 0 deletions unittests/API/CDPJSONHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,10 @@ JSONObject *JSONScope::parseObject(const std::string &json) {
return mustParseStrAsJsonObj(json, private_->factory);
}

std::optional<JSONObject *> JSONScope::tryParseObject(const std::string &json) {
return parseStrAsJsonObj(json, private_->factory);
}

std::string JSONScope::getString(
JSONObject *obj,
std::vector<std::string> paths) {
Expand Down
1 change: 1 addition & 0 deletions unittests/API/CDPJSONHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ struct JSONScope {

JSONValue *parse(const std::string &str);
JSONObject *parseObject(const std::string &str);
std::optional<JSONObject *> tryParseObject(const std::string &json);
std::string getString(JSONObject *obj, std::vector<std::string> paths);
long long getNumber(JSONObject *obj, std::vector<std::string> paths);
bool getBoolean(JSONObject *obj, std::vector<std::string> paths);
Expand Down

0 comments on commit 190dc20

Please sign in to comment.