Refactor code for invoke_lua_source and world.init. Also, add compile_commands.json to luprex
This commit is contained in:
@@ -22,21 +22,12 @@ static void dump_lines(StreamBuffer *in, StreamBuffer *out, int chid) {
|
||||
}
|
||||
}
|
||||
|
||||
// This test is the minimal possible DrivenEngine.
|
||||
class DriverStubTest : public DrivenEngine {
|
||||
virtual void event_init(std::string_view srcpk, int argc, char *argv[]) override {
|
||||
stop_driver();
|
||||
}
|
||||
virtual void event_update() override {
|
||||
}
|
||||
};
|
||||
|
||||
// This test connects to a public webserver and prints
|
||||
// the output from the server.
|
||||
class DriverWebServerTest : public DrivenEngine {
|
||||
public:
|
||||
eng::vector<SharedChannel> channels_;
|
||||
virtual void event_init(std::string_view srcpk, int argc, char *argv[]) override {
|
||||
DriverWebServerTest() {
|
||||
SharedChannel ch = new_outgoing_channel("cert:stanford.edu:443");
|
||||
ch->out()->write_bytes("GET https://stanford.edu/xbanankjdsh.html HTTP/1.1\n\n");
|
||||
channels_.emplace_back(std::move(ch));
|
||||
@@ -62,7 +53,7 @@ public:
|
||||
class DriverDNSFailTest : public DrivenEngine {
|
||||
public:
|
||||
eng::vector<SharedChannel> channels_;
|
||||
virtual void event_init(std::string_view srcpk, int argc, char *argv[]) override {
|
||||
DriverDNSFailTest() {
|
||||
SharedChannel ch = new_outgoing_channel("akjsdkajshdakjshd.alk:80");
|
||||
ch->out()->write_bytes("GET http://stanford.edu/index.html HTTP/1.1\n\n");
|
||||
channels_.emplace_back(std::move(ch));
|
||||
@@ -89,7 +80,7 @@ class DriverPrintClockTest : public DrivenEngine {
|
||||
public:
|
||||
int count_;
|
||||
double last_clock_;
|
||||
virtual void event_init(std::string_view srcpk, int argc, char *argv[]) override {
|
||||
DriverPrintClockTest() {
|
||||
count_ = 0;
|
||||
last_clock_ = 0.0;
|
||||
}
|
||||
@@ -111,21 +102,29 @@ public:
|
||||
|
||||
|
||||
class RunUnitTests : public DrivenEngine {
|
||||
private:
|
||||
public:
|
||||
UniqueWorld world_;
|
||||
|
||||
void event_init(std::string_view srcpk, int argc, char *argv[]) override
|
||||
{
|
||||
RunUnitTests() {
|
||||
world_.reset(new World(WORLD_TYPE_MASTER));
|
||||
world_->update_source(srcpk);
|
||||
world_->run_unittests();
|
||||
stop_driver();
|
||||
rescan_lua_source();
|
||||
}
|
||||
|
||||
virtual void event_access(AccessKind kind, int64_t place_id, std::string_view datapk, StreamBuffer *retpk) override {
|
||||
switch (kind) {
|
||||
case AccessKind::INVOKE_LUA_SOURCE: {
|
||||
world_->update_source(datapk);
|
||||
world_->run_unittests();
|
||||
break;
|
||||
}
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
void event_update() override {}
|
||||
};
|
||||
|
||||
DrivenEngineDefine("driverstubtest", DriverStubTest);
|
||||
DrivenEngineDefine("driverwebservertest", DriverWebServerTest);
|
||||
DrivenEngineDefine("driverdnsfailtest", DriverDNSFailTest);
|
||||
DrivenEngineDefine("driverprintclocktest", DriverPrintClockTest);
|
||||
|
||||
Reference in New Issue
Block a user