2019-01-21 14:03:30 -05:00
|
|
|
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
|
2018-10-23 19:39:31 -04:00
|
|
|
#include "test.h"
|
2019-06-04 13:35:51 -04:00
|
|
|
#include <fstream>
|
2019-01-29 21:31:59 -05:00
|
|
|
#include <string>
|
2019-06-04 13:35:51 -04:00
|
|
|
#include "internal.h"
|
2018-10-23 19:39:31 -04:00
|
|
|
|
2019-04-08 10:12:43 -04:00
|
|
|
deno_snapshot snapshot = {nullptr, 0};
|
2018-07-12 13:41:19 -04:00
|
|
|
|
2019-06-04 13:35:51 -04:00
|
|
|
bool ReadFileToString(const char* fn, std::string* contents) {
|
|
|
|
std::ifstream file(fn, std::ios::binary);
|
|
|
|
if (file.fail()) {
|
|
|
|
return false;
|
2018-11-01 08:05:21 -04:00
|
|
|
}
|
2019-06-04 13:35:51 -04:00
|
|
|
contents->assign(std::istreambuf_iterator<char>{file}, {});
|
|
|
|
return !file.fail();
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char** argv) {
|
|
|
|
// All of the JS code in libdeno_test.js is tested after being snapshotted.
|
|
|
|
// We create that snapshot now at runtime, rather than at compile time to
|
|
|
|
// simplify the build process. So we load and execute the libdeno_test.js
|
|
|
|
// file, without running any of the tests and store the result in the global
|
|
|
|
// "snapshot" variable, which will be used later in the tests.
|
|
|
|
std::string js_fn = JS_PATH;
|
|
|
|
std::string js_source;
|
|
|
|
CHECK(ReadFileToString(js_fn.c_str(), &js_source));
|
|
|
|
|
|
|
|
deno_init();
|
|
|
|
deno_config config = {1, deno::empty_snapshot, deno::empty_buf, nullptr,
|
|
|
|
nullptr};
|
|
|
|
Deno* d = deno_new(config);
|
2018-11-01 08:05:21 -04:00
|
|
|
|
2019-06-04 13:35:51 -04:00
|
|
|
deno_execute(d, nullptr, js_fn.c_str(), js_source.c_str());
|
|
|
|
if (deno_last_exception(d) != nullptr) {
|
|
|
|
std::cerr << "Snapshot Exception " << std::endl;
|
|
|
|
std::cerr << deno_last_exception(d) << std::endl;
|
|
|
|
deno_delete(d);
|
2018-10-23 19:39:31 -04:00
|
|
|
return 1;
|
|
|
|
}
|
2019-06-04 13:35:51 -04:00
|
|
|
|
|
|
|
snapshot = deno_snapshot_new(d);
|
2018-10-23 19:39:31 -04:00
|
|
|
|
2018-07-12 13:41:19 -04:00
|
|
|
testing::InitGoogleTest(&argc, argv);
|
|
|
|
deno_init();
|
2018-09-22 08:47:44 -04:00
|
|
|
deno_set_v8_flags(&argc, argv);
|
2018-07-12 13:41:19 -04:00
|
|
|
return RUN_ALL_TESTS();
|
|
|
|
}
|