A bunch of new allocation related stuff.
This commit is contained in:
78
Ink.jai
78
Ink.jai
@@ -72,9 +72,11 @@ Test_Suite :: struct {
|
||||
results : [..]Result;
|
||||
}
|
||||
|
||||
get_golden_path :: (file_path : string, stage : Stage_Flags, allocator := context.allocator) -> string {
|
||||
path := parse_path(file_path);
|
||||
file_without_extension := split(path.words[path.words.count - 1], ".");
|
||||
get_golden_path :: (file_path : string, stage : Stage_Flags) -> string {
|
||||
sc := get_scratch();
|
||||
defer scratch_end(sc);
|
||||
path := parse_path(file_path,, sc.allocator);
|
||||
file_without_extension := split(path.words[path.words.count - 1], ".",, sc.allocator);
|
||||
|
||||
builder : String_Builder;
|
||||
builder.allocator = temp;
|
||||
@@ -82,6 +84,7 @@ get_golden_path :: (file_path : string, stage : Stage_Flags, allocator := contex
|
||||
final_path_length := file_path.count - SHADER_EXTENSION.count + GOLDEN_EXTENSION.count + 1; // +1 for dot
|
||||
|
||||
path.words.count -= 1;
|
||||
path.words.allocator = sc.allocator;
|
||||
|
||||
if stage == {
|
||||
case .Lexer; {
|
||||
@@ -112,10 +115,11 @@ get_golden_path :: (file_path : string, stage : Stage_Flags, allocator := contex
|
||||
}
|
||||
|
||||
init_string_builder(*builder, file_without_extension.count + GOLDEN_EXTENSION.count + 1);
|
||||
builder.allocator = sc.allocator;
|
||||
append(*builder, file_without_extension[0]);
|
||||
append(*builder, ".");
|
||||
append(*builder, GOLDEN_EXTENSION);
|
||||
golden_path := builder_to_string(*builder);
|
||||
golden_path := builder_to_string(*builder,, sc.allocator);
|
||||
array_add(*path.words, golden_path);
|
||||
|
||||
final_path := path_to_string(path);
|
||||
@@ -124,6 +128,8 @@ get_golden_path :: (file_path : string, stage : Stage_Flags, allocator := contex
|
||||
}
|
||||
|
||||
do_golden_comparison :: (golden_path : string, comparison_text : string, result_data : *Result, output_type : Output_Type) {
|
||||
sc := get_scratch();
|
||||
defer scratch_end(sc);
|
||||
if output_type & .Golden {
|
||||
// Output the comparison file
|
||||
write_entire_file(golden_path, comparison_text);
|
||||
@@ -138,15 +144,15 @@ do_golden_comparison :: (golden_path : string, comparison_text : string, result_
|
||||
return;
|
||||
}
|
||||
|
||||
golden_text, ok := read_entire_file(golden_path);
|
||||
golden_text, ok := read_entire_file(golden_path,, sc.allocator);
|
||||
if !ok {
|
||||
result_data.info_text = tprint("Unable to open golden file %\n", golden_path);
|
||||
result_data.type = .Golden_File_Not_Found;
|
||||
return;
|
||||
}
|
||||
|
||||
comp := replace(comparison_text, "\r\n", "\n");
|
||||
gold := replace(golden_text, "\r\n", "\n");
|
||||
comp := replace(comparison_text, "\r\n", "\n",, sc.allocator);
|
||||
gold := replace(golden_text, "\r\n", "\n",, sc.allocator);
|
||||
result := compare(comp, gold) == 0;
|
||||
if !result {
|
||||
result_data.type = .Failed;
|
||||
@@ -314,7 +320,7 @@ run_semantic_analysis_test :: (result : *Compile_Result, output_type : Output_Ty
|
||||
}
|
||||
|
||||
run_semantic_analysis_test :: (file_path : string, result : *Compile_Result, output_type : Output_Type = 0) -> Result {
|
||||
result.file = make_file(result, file_path);
|
||||
result.file = make_file(result, file_path,, result.allocator);
|
||||
result.allocator = make_arena(Megabytes(128));
|
||||
|
||||
result_data : Result;
|
||||
@@ -343,9 +349,9 @@ make_test_case :: (path : string, stage_flags : Stage_Flags, allocator := contex
|
||||
|
||||
run_test_new :: (file_path : string, stage_flags : Stage_Flags, results : *[..]Result, output_type : Output_Type = 0) {
|
||||
compile_result : Compile_Result;
|
||||
|
||||
compile_result.file = make_file(*compile_result, file_path);
|
||||
|
||||
compile_result.allocator = make_arena(Megabytes(128));
|
||||
compile_result.file = make_file(*compile_result, file_path,, compile_result.allocator);
|
||||
|
||||
result : Result;
|
||||
if stage_flags & .Lexer {
|
||||
@@ -404,7 +410,6 @@ run_test :: (test_case : Test_Case, results : *[..]Result, output_type : Output_
|
||||
}
|
||||
|
||||
run_test_new(test_case.path, test_case.stage_flags, results, output_type);
|
||||
// run_test(test_case.path, test_case.stage_flags, results, output_type);
|
||||
}
|
||||
|
||||
record_result :: (results : *[..]Result, result : Result) {
|
||||
@@ -472,23 +477,25 @@ run_test_suite :: (using suite : *Test_Suite, output_type : Output_Type = 0) {
|
||||
}
|
||||
}
|
||||
|
||||
print("%\n", builder_to_string(*builder));
|
||||
print("%\n", builder_to_string(*builder,, temp));
|
||||
}
|
||||
|
||||
read_suite :: (file_path : string, suite : *Test_Suite) -> bool {
|
||||
bytes, ok := read_entire_file(file_path);
|
||||
sc := get_scratch();
|
||||
defer scratch_end(sc);
|
||||
bytes, ok := read_entire_file(file_path,, sc.allocator);
|
||||
if !ok {
|
||||
log_error("Unable to read suite file %\n", file_path);
|
||||
return false;
|
||||
}
|
||||
|
||||
path := parse_path(file_path);
|
||||
file_without_extension := split(path.words[path.words.count - 1], ".");
|
||||
suite.name = copy_string(file_without_extension[0]);
|
||||
split_lines := split(bytes, "\n");
|
||||
path := parse_path(file_path,, sc.allocator);
|
||||
file_without_extension := split(path.words[path.words.count - 1], ".",, sc.allocator);
|
||||
suite.name = copy_string(file_without_extension[0],, temp);
|
||||
split_lines := split(bytes, "\n",, sc.allocator);
|
||||
|
||||
for split_line : split_lines {
|
||||
line := split(split_line, " ");
|
||||
line := split(split_line, " ",, sc.allocator);
|
||||
if line[0].count == 0 {
|
||||
continue;
|
||||
}
|
||||
@@ -498,7 +505,7 @@ read_suite :: (file_path : string, suite : *Test_Suite) -> bool {
|
||||
}
|
||||
|
||||
if line.count == 1 {
|
||||
line = split(split_line, "\t");
|
||||
line = split(split_line, "\t",, sc.allocator);
|
||||
if line.count == 1 {
|
||||
log_error("Invalid line - % - \n", it_index + 1);
|
||||
continue;
|
||||
@@ -521,7 +528,7 @@ read_suite :: (file_path : string, suite : *Test_Suite) -> bool {
|
||||
stage_flags |= .Compile;
|
||||
}
|
||||
}
|
||||
test_case := make_test_case(test_case_path, stage_flags);
|
||||
test_case := make_test_case(test_case_path, stage_flags, temp);
|
||||
array_add(*suite.test_cases, test_case);
|
||||
}
|
||||
|
||||
@@ -584,7 +591,10 @@ evaluate_result :: (result : Result) {
|
||||
main :: () {
|
||||
args := get_command_line_arguments();
|
||||
|
||||
init_context_allocators();
|
||||
|
||||
suites : [..]Test_Suite;
|
||||
suites.allocator = temp;
|
||||
output_type : Output_Type = 0;
|
||||
|
||||
Argument_Parse_State :: enum {
|
||||
@@ -597,6 +607,8 @@ main :: () {
|
||||
arg_parse_state : Argument_Parse_State;
|
||||
current_suite : *Test_Suite;
|
||||
|
||||
local_temp := make_arena(Megabytes(128));
|
||||
|
||||
path : string;
|
||||
|
||||
for i: 1..args.count - 1 {
|
||||
@@ -632,12 +644,14 @@ main :: () {
|
||||
} else if arg == "-compile" {
|
||||
current_suite.test_cases[cases - 1].stage_flags |= .Compile;
|
||||
} else if contains(arg, ".") {
|
||||
path_split := split(arg, "\\");
|
||||
split_path := split(path_split[path_split.count - 1], ".");
|
||||
sc := get_scratch();
|
||||
defer scratch_end(sc);
|
||||
path_split := split(arg, "\\",, sc.allocator);
|
||||
split_path := split(path_split[path_split.count - 1], ".",, sc.allocator);
|
||||
extension := split_path[1];
|
||||
if extension == SHADER_EXTENSION {
|
||||
path := copy_string(arg);
|
||||
test_case := make_test_case(path, 0);
|
||||
path := copy_string(arg,, local_temp);
|
||||
test_case := make_test_case(path, 0, local_temp);
|
||||
array_add(*current_suite.test_cases, test_case);
|
||||
} else {
|
||||
print("%Invalid file as argument % %\n", red(), arg, reset_color());
|
||||
@@ -648,8 +662,10 @@ main :: () {
|
||||
}
|
||||
case .None; {
|
||||
if contains(arg, ".") {
|
||||
path_split := split(arg, "\\");
|
||||
split_path := split(path_split[path_split.count - 1], ".");
|
||||
sc := get_scratch();
|
||||
defer scratch_end(sc);
|
||||
path_split := split(arg, "\\",, sc.allocator);
|
||||
split_path := split(path_split[path_split.count - 1], ".",, sc.allocator);
|
||||
extension := split_path[1];
|
||||
|
||||
if extension == SHADER_EXTENSION {
|
||||
@@ -660,12 +676,14 @@ main :: () {
|
||||
|
||||
if !current_suite {
|
||||
suite : Test_Suite;
|
||||
suite.results.allocator = local_temp;
|
||||
suite.test_cases.allocator = local_temp;
|
||||
array_add(*suites, suite);
|
||||
current_suite = *suites[0];
|
||||
}
|
||||
arg_parse_state = .Run_Test;
|
||||
path := copy_string(arg);
|
||||
test_case := make_test_case(path, 0);
|
||||
path := copy_string(arg,, local_temp);
|
||||
test_case := make_test_case(path, 0, local_temp);
|
||||
array_add(*current_suite.test_cases, test_case);
|
||||
} else if extension == SUITE_EXTENSION {
|
||||
if arg_parse_state == .Run_Test {
|
||||
@@ -676,6 +694,8 @@ main :: () {
|
||||
path := copy_string(arg);
|
||||
|
||||
suite : Test_Suite;
|
||||
suite.results.allocator = local_temp;
|
||||
suite.test_cases.allocator = local_temp;
|
||||
read_suite(path, *suite);
|
||||
array_add(*suites, suite);
|
||||
current_suite = *suites[0];
|
||||
@@ -690,4 +710,6 @@ main :: () {
|
||||
for suite : suites {
|
||||
run_test_suite(*suite, output_type);
|
||||
}
|
||||
|
||||
clear(local_temp);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user