Skip to content

Instantly share code, notes, and snippets.

@caitp
Created April 26, 2016 16:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save caitp/59d1939d60d40906e8c0aa1ff61cca1a to your computer and use it in GitHub Desktop.
Save caitp/59d1939d60d40906e8c0aa1ff61cca1a to your computer and use it in GitHub Desktop.
auto CheckObjectEq = [&env](
v8::Local<v8::Value> expected, v8::Local<v8::Value> actual,
const char* expected_str, const char* actual_str, int line) {
v8::String::Utf8Value details(
actual->ToDetailString(env.local()).ToLocalChecked());
if (!actual->IsObject()) {
V8_Fatal(__FILE__, line, "Expected %s to be an Object, but found %s",
actual_str, *details);
}
if (actual != expected) {
v8::String::Utf8Value actual_json(
v8::JSON::Stringify(env.local(), v8::Local<v8::Object>::Cast(actual))
.ToLocalChecked());
v8::String::Utf8Value expected_json(
v8::JSON::Stringify(env.local(),
v8::Local<v8::Object>::Cast(expected))
.ToLocalChecked());
V8_Fatal(__FILE__, line, "%p != %p (Expected %s (%s) to be %s (%s))",
*actual, *expected, actual_str, *actual_json, expected_str,
*expected_json);
}
};
#define CHECK_OBJ_EQ(expected, actual) \
CheckObjectEq(expected, actual, #expected, #actual, __LINE__)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment