fixup test options

This commit is contained in:
2024-01-03 17:49:58 +01:00
parent 6d241b2daf
commit 4d7f0eee03
5 changed files with 57 additions and 5 deletions

View File

@@ -9,8 +9,6 @@
#include "Options.h"
Logger &Logger::get() {
// Ensure proper destruction order for tests
Options::get();
static Logger logger;
return logger;
}

View File

@@ -197,9 +197,6 @@ void MemoryContext::gc_thread_entry() {
}
}
MemoryContext &MemoryContext::get() {
// Ensure proper destruction order for tests
Options::get();
Logger::get();
static MemoryContext mc;
return mc;
}

View File

@@ -5,6 +5,22 @@
#include <gtest/gtest.h>
#include "MemoryContext.h"
class Environment : public ::testing::Environment {
public:
~Environment() override {}
void SetUp() override {
Options::set_int("cell_limit", 60000);
Logger::set_level("MemoryContext", Logger::INFO);
}
void TearDown() override {
Options::reset();
Logger::reset();
}
};
testing::Environment *const env = testing::AddGlobalTestEnvironment(new Environment);
TEST(GCTest, GCTest) {
@@ -19,6 +35,7 @@ TEST(GCTest, GCTest) {
}
MemoryContext::get().request_gc_and_wait();
MemoryContext::get().request_gc_and_wait();
MemoryContext::get().request_gc_and_wait();
EXPECT_EQ(MemoryContext::get().cell_count(), 0);
{
Handle c = Handle::cons(nullptr, nullptr);
@@ -31,6 +48,7 @@ TEST(GCTest, GCTest) {
}
MemoryContext::get().request_gc_and_wait();
MemoryContext::get().request_gc_and_wait();
MemoryContext::get().request_gc_and_wait();
EXPECT_EQ(MemoryContext::get().cell_count(), 0);
}
@@ -45,6 +63,7 @@ TEST(GCTest, GCTestAppend) {
}
MemoryContext::get().request_gc_and_wait();
MemoryContext::get().request_gc_and_wait();
MemoryContext::get().request_gc_and_wait();
EXPECT_EQ(MemoryContext::get().cell_count(), 0);
}
TEST(GCTest, GCTestPop) {
@@ -63,6 +82,7 @@ TEST(GCTest, GCTestPop) {
}
MemoryContext::get().request_gc_and_wait();
MemoryContext::get().request_gc_and_wait();
MemoryContext::get().request_gc_and_wait();
EXPECT_EQ(MemoryContext::get().cell_count(), 0);
}
@@ -80,6 +100,7 @@ TEST(GCTest, GCTestAppend2) {
}
MemoryContext::get().request_gc_and_wait();
MemoryContext::get().request_gc_and_wait();
MemoryContext::get().request_gc_and_wait();
EXPECT_EQ(MemoryContext::get().cell_count(), 0);
}
@@ -98,5 +119,6 @@ TEST(GCTest, GCTestAppend3) {
}
MemoryContext::get().request_gc_and_wait();
MemoryContext::get().request_gc_and_wait();
MemoryContext::get().request_gc_and_wait();
EXPECT_EQ(MemoryContext::get().cell_count(), 0);
}

View File

@@ -2,6 +2,22 @@
#include "Command.h"
#include "VM.h"
class Environment : public ::testing::Environment {
public:
~Environment() override {}
void SetUp() override {
Options::set_int("cell_limit", 1000);
Logger::set_level("MemoryContext", Logger::INFO);
}
void TearDown() override {
Options::reset();
Logger::reset();
}
};
testing::Environment *const env = testing::AddGlobalTestEnvironment(new Environment);
using namespace Command;
TEST(VMTest, BasicHello) {

View File

@@ -3,6 +3,24 @@
#include "Parser.h"
#include "VM.h"
class Environment : public ::testing::Environment {
public:
~Environment() override {}
void SetUp() override {
Options::set_int("cell_limit", 2000);
Logger::set_level("MemoryContext", Logger::INFO);
}
void TearDown() override {
Options::reset();
Logger::reset();
}
};
testing::Environment *const env = testing::AddGlobalTestEnvironment(new Environment);
TEST(VMWithParserTest, BasicHello) {
std::stringstream ssin;
std::stringstream ssout;
@@ -63,6 +81,7 @@ TEST(VMWithParserTest, RecFunction) {
}
MemoryContext::get().request_gc_and_wait();
MemoryContext::get().request_gc_and_wait();
MemoryContext::get().request_gc_and_wait();
EXPECT_EQ(MemoryContext::get().cell_count(), 0);
ssout.flush();
EXPECT_EQ(ssout.str(), "6765");