Add core.cpp, testing changes
This commit is contained in:
@@ -1,38 +1,26 @@
|
|||||||
#include "build_tool/library.cpp"
|
#include "build_tool/library.cpp"
|
||||||
|
|
||||||
void CompileFiles(Strs cc, Strs files);
|
void Compile(Strs cc, Str files);
|
||||||
int ReturnValue = 0;
|
int ReturnValue = 0;
|
||||||
|
|
||||||
int Main() {
|
int Main() {
|
||||||
Strs cc = CMDLine.get("cc"_s, ON_WINDOWS("cl"_s) ON_MAC("clang"_s) ON_LINUX("gcc"_s));
|
Strs cc = CMDLine.get("cc"_s, ON_WINDOWS("cl"_s) ON_MAC("clang"_s) ON_LINUX("gcc"_s));
|
||||||
Strs files = ListDir("../tests");
|
Compile(cc, "../tests/test_main.cpp");
|
||||||
For(files) {
|
Compile(cc, "../tests/test_filesystem.c");
|
||||||
if (S8_Seek(it, "test_"_s)) {
|
|
||||||
CompileFiles(cc, it);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return ReturnValue;
|
return ReturnValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CompileFiles(Strs cc, Strs files) {
|
void Compile(Strs cc, Str file) {
|
||||||
int result = 0;
|
int result = 0;
|
||||||
Str exe = FilenameWithoutExt(files[0]);
|
Str exe = FilenameWithoutExt(file);
|
||||||
Str filestr = Merge(files);
|
bool is_cpp = S8_EndsWith(file, ".cpp");
|
||||||
if (cc == "gcc") {
|
if (cc == "gcc" && is_cpp) result = OS_SystemF("g++ -o %.*s.exe %.*s -g -Wno-write-strings -fsanitize=address", S8_Expand(exe), S8_Expand(file));
|
||||||
result = OS_SystemF("g++ -o %.*s.exe %.*s -g -Wno-write-strings -fsanitize=address", S8_Expand(exe), S8_Expand(filestr));
|
else if (cc == "gcc" && !is_cpp) result = OS_SystemF("g -o %.*s.exe %.*s -g -Wno-write-strings -fsanitize=address", S8_Expand(exe), S8_Expand(file));
|
||||||
}
|
else if (cc == "clang" && is_cpp) result = OS_SystemF("clang++ -std=c++11 -o %.*s.exe %.*s -fdiagnostics-absolute-paths -g -Wno-writable-strings -fsanitize=address", S8_Expand(exe), S8_Expand(file));
|
||||||
else if (cc == "clang") {
|
else if (cc == "clang" && !is_cpp) result = OS_SystemF("clang -o %.*s.exe %.*s -fdiagnostics-absolute-paths -g -Wno-writable-strings -fsanitize=address", S8_Expand(exe), S8_Expand(file));
|
||||||
result = OS_SystemF("clang++ -std=c++11 -o %.*s.exe %.*s -fdiagnostics-absolute-paths -g -Wno-writable-strings -fsanitize=address", S8_Expand(exe), S8_Expand(filestr));
|
else result = OS_SystemF("cl -Fe:%.*s.exe %.*s -FC -Zi -WX -W3 -wd4200 -diagnostics:column -nologo -D_CRT_SECURE_NO_WARNINGS -fsanitize=address -RTC1", S8_Expand(exe), S8_Expand(file));
|
||||||
}
|
|
||||||
else {
|
|
||||||
result = OS_SystemF("cl -Fe:%.*s.exe %.*s -FC -Zi -WX -W3 -wd4200 -diagnostics:column -nologo -D_CRT_SECURE_NO_WARNINGS -fsanitize=address -RTC1", S8_Expand(exe), S8_Expand(filestr));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (result == 0) {
|
if (result == 0) result = OS_SystemF(IF_WINDOWS_ELSE("", "./") "%.*s.exe", S8_Expand(exe));
|
||||||
result = OS_SystemF(IF_WINDOWS_ELSE("", "./") "%.*s.exe", S8_Expand(exe));
|
else ReturnValue = result;
|
||||||
}
|
|
||||||
else {
|
|
||||||
ReturnValue = result;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
1
core_library/core.cpp
Normal file
1
core_library/core.cpp
Normal file
@@ -0,0 +1 @@
|
|||||||
|
#include "core.c"
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
#include "../core_library/core.c"
|
|
||||||
|
|
||||||
#define CL_Allocator MA_Arena *
|
|
||||||
#define CL_Allocate(a, s) MA_PushSizeNonZeroed(a, s)
|
|
||||||
#define CL_ASSERT IO_Assert
|
|
||||||
#define CL_VSNPRINTF stbsp_vsnprintf
|
|
||||||
#define CL_SNPRINTF stbsp_snprintf
|
|
||||||
#include "../standalone_libraries/clexer.c"
|
|
||||||
|
|
||||||
int main() {
|
|
||||||
// Unicode iteration over codepoints
|
|
||||||
{
|
|
||||||
S8_String s = "mrówka";
|
|
||||||
|
|
||||||
bool found_two_byte = false;
|
|
||||||
For(s) {
|
|
||||||
if (it.utf8_codepoint_byte_size == 2) {
|
|
||||||
found_two_byte = true;
|
|
||||||
IO_Assert(it.i == 2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
IO_Assert(found_two_byte);
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
MA_Scratch scratch;
|
|
||||||
|
|
||||||
S8_String filename = "../standalone_libraries/clexer.c";
|
|
||||||
S8_String file = OS_ReadFile(scratch, filename);
|
|
||||||
CL_Lexer lexer = CL_Begin(scratch, file.str, filename.str);
|
|
||||||
|
|
||||||
char buff[1024];
|
|
||||||
for (;;) {
|
|
||||||
CL_Token token = CL_Next(&lexer);
|
|
||||||
if (token.kind == CL_EOF) break;
|
|
||||||
if (token.kind != CL_PREPROC_INCLUDE) continue;
|
|
||||||
|
|
||||||
CL_Stringify(buff, sizeof(buff), &token);
|
|
||||||
IO_Printf("%s\n", buff);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,5 +1,3 @@
|
|||||||
#include "../core_library/core.c"
|
|
||||||
|
|
||||||
void TestBootstrapArenaClear() {
|
void TestBootstrapArenaClear() {
|
||||||
MA_Arena *arena = MA_Bootstrap();
|
MA_Arena *arena = MA_Bootstrap();
|
||||||
IO_Assert(arena->base_len != 0);
|
IO_Assert(arena->base_len != 0);
|
||||||
@@ -29,36 +27,6 @@ void TestBootstrapArenaClear() {
|
|||||||
((char *)arena->memory.data)[arena->len - 1] = 0;
|
((char *)arena->memory.data)[arena->len - 1] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TestScratch() {
|
|
||||||
MA_Arena *scratch_arena_test = NULL;
|
|
||||||
{
|
|
||||||
MA_Scratch scratch;
|
|
||||||
IO_Assert(scratch.checkpoint.arena->len == 0);
|
|
||||||
IO_Assert(scratch.checkpoint.arena->memory.data == NULL);
|
|
||||||
int *a = MA_PushStruct(scratch, int);
|
|
||||||
IO_Assert(scratch.checkpoint.arena->memory.data);
|
|
||||||
IO_Assert(scratch.checkpoint.arena->len == sizeof(int));
|
|
||||||
IO_Assert(scratch.checkpoint.arena);
|
|
||||||
scratch_arena_test = scratch.checkpoint.arena;
|
|
||||||
|
|
||||||
int b = 10;
|
|
||||||
IO_Assert(MA_IsPointerInside(scratch, a));
|
|
||||||
IO_Assert(!MA_IsPointerInside(scratch, &b));
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
MA_Scratch scratch;
|
|
||||||
IO_Assert(scratch_arena_test == scratch.checkpoint.arena);
|
|
||||||
IO_Assert(scratch.checkpoint.arena->len == 0);
|
|
||||||
|
|
||||||
MA_Scratch scratch2(scratch.checkpoint);
|
|
||||||
IO_Assert(scratch.checkpoint.arena != scratch2.checkpoint.arena);
|
|
||||||
|
|
||||||
MA_Scratch scratch3(scratch.checkpoint, scratch2.checkpoint);
|
|
||||||
IO_Assert(scratch3.checkpoint.arena != scratch2.checkpoint.arena);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void TestBuffer() {
|
void TestBuffer() {
|
||||||
char buffer[1024];
|
char buffer[1024];
|
||||||
MA_Arena buffer_arena = MA_MakeFromBuffer(buffer, 1024);
|
MA_Arena buffer_arena = MA_MakeFromBuffer(buffer, 1024);
|
||||||
@@ -98,12 +66,3 @@ void TestBootstrapExclusive() {
|
|||||||
For(v) IO_Assert(it == i++);
|
For(v) IO_Assert(it == i++);
|
||||||
v.dealloc();
|
v.dealloc();
|
||||||
}
|
}
|
||||||
|
|
||||||
int main() {
|
|
||||||
TestScratch();
|
|
||||||
TestBuffer();
|
|
||||||
TestCreateAllocate();
|
|
||||||
TestBootstrap();
|
|
||||||
TestBootstrapExclusive();
|
|
||||||
TestBootstrapArenaClear();
|
|
||||||
}
|
|
||||||
@@ -1,4 +1,3 @@
|
|||||||
#include "../core_library/core.c"
|
|
||||||
void TestExclusiveArenaBackedArray() {
|
void TestExclusiveArenaBackedArray() {
|
||||||
MA_Scratch scratch;
|
MA_Scratch scratch;
|
||||||
MA_Arena ex = MA_Create();
|
MA_Arena ex = MA_Create();
|
||||||
@@ -118,12 +117,3 @@ void TestCopy() {
|
|||||||
|
|
||||||
a.dealloc();
|
a.dealloc();
|
||||||
}
|
}
|
||||||
|
|
||||||
int main() {
|
|
||||||
TestExclusiveArenaBackedArray();
|
|
||||||
TestRemoveForLoop();
|
|
||||||
TestBasic();
|
|
||||||
TestReverseLoop();
|
|
||||||
TestCopy();
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
63
tests/test_main.cpp
Normal file
63
tests/test_main.cpp
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
#include "../core_library/core.cpp"
|
||||||
|
#include "test_table.cpp"
|
||||||
|
#include "test_array.cpp"
|
||||||
|
#include "test_arena.cpp"
|
||||||
|
|
||||||
|
void TestClexer();
|
||||||
|
int main() {
|
||||||
|
TestSimpleInsertAndIntegrity();
|
||||||
|
TestStrings();
|
||||||
|
|
||||||
|
TestExclusiveArenaBackedArray();
|
||||||
|
TestRemoveForLoop();
|
||||||
|
TestBasic();
|
||||||
|
TestReverseLoop();
|
||||||
|
TestCopy();
|
||||||
|
|
||||||
|
TestBuffer();
|
||||||
|
TestCreateAllocate();
|
||||||
|
TestBootstrap();
|
||||||
|
TestBootstrapExclusive();
|
||||||
|
TestBootstrapArenaClear();
|
||||||
|
|
||||||
|
TestClexer();
|
||||||
|
|
||||||
|
// Unicode iteration over codepoints
|
||||||
|
{
|
||||||
|
S8_String s = "mrówka";
|
||||||
|
|
||||||
|
bool found_two_byte = false;
|
||||||
|
For(s) {
|
||||||
|
if (it.utf8_codepoint_byte_size == 2) {
|
||||||
|
found_two_byte = true;
|
||||||
|
IO_Assert(it.i == 2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
IO_Assert(found_two_byte);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#define CL_Allocator MA_Arena *
|
||||||
|
#define CL_Allocate(a, s) MA_PushSizeNonZeroed(a, s)
|
||||||
|
#define CL_ASSERT IO_Assert
|
||||||
|
#define CL_VSNPRINTF stbsp_vsnprintf
|
||||||
|
#define CL_SNPRINTF stbsp_snprintf
|
||||||
|
#include "../standalone_libraries/clexer.c"
|
||||||
|
|
||||||
|
void TestClexer() {
|
||||||
|
MA_Scratch scratch;
|
||||||
|
|
||||||
|
S8_String filename = "../standalone_libraries/clexer.c";
|
||||||
|
S8_String file = OS_ReadFile(scratch, filename);
|
||||||
|
CL_Lexer lexer = CL_Begin(scratch, file.str, filename.str);
|
||||||
|
|
||||||
|
char buff[1024];
|
||||||
|
for (;;) {
|
||||||
|
CL_Token token = CL_Next(&lexer);
|
||||||
|
if (token.kind == CL_EOF) break;
|
||||||
|
if (token.kind != CL_PREPROC_INCLUDE) continue;
|
||||||
|
|
||||||
|
CL_Stringify(buff, sizeof(buff), &token);
|
||||||
|
// IO_Printf("%s\n", buff);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,3 @@
|
|||||||
#include "../core_library/core.c"
|
|
||||||
|
|
||||||
void TestSimpleInsertAndIntegrity() {
|
void TestSimpleInsertAndIntegrity() {
|
||||||
MA_Scratch scratch;
|
MA_Scratch scratch;
|
||||||
Table<uint64_t> table = {scratch};
|
Table<uint64_t> table = {scratch};
|
||||||
@@ -36,9 +34,3 @@ void TestStrings() {
|
|||||||
IO_Assert(table.gets("3")->i == 3);
|
IO_Assert(table.gets("3")->i == 3);
|
||||||
table.dealloc();
|
table.dealloc();
|
||||||
}
|
}
|
||||||
|
|
||||||
int main() {
|
|
||||||
TestSimpleInsertAndIntegrity();
|
|
||||||
TestStrings();
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user