Actually fix which allocator we're using in the tests.

This commit is contained in:
2025-09-13 22:01:29 +02:00
parent b0653b6563
commit 622ce388fa
4 changed files with 83 additions and 69 deletions

133
Ink.jai
View File

@@ -167,9 +167,9 @@ run_codegen_test :: (file_path : string, ctx : *Compiler_Context, output_type :
result : Result;
result.path = file_path;
lex(ctx);
parse(ctx);
check(ctx);
lex(ctx, context.allocator);
parse(ctx, context.allocator);
check(ctx, context.allocator);
if ctx.had_error {
result.type = .Failed;
@@ -185,7 +185,7 @@ run_codegen_test :: (ctx : *Compiler_Context, output_type : Output_Type = 0) ->
result.path = ctx.file.path;
result_text : string;
codegen(ctx);
codegen(ctx, context.allocator);
if ctx.had_error {
result.type = .Failed;
@@ -210,7 +210,7 @@ run_compile_test :: (path : string, output_type : Output_Type = 0) -> Result, Co
ctx : Compiler_Context;
result : Result;
result.path = path;
compile_file(*ctx, path);
compile_file(*ctx, path, context.allocator);
if ctx.had_error {
result.type = .Failed;
@@ -263,7 +263,7 @@ run_lexer_test :: (file_path : string, ctx : *Compiler_Context, output_type : Ou
result.type = .Failed;
result_text = report_messages(ctx.messages);
} else {
result_text = pretty_print_tokens(ctx.tokens, *temp);
result_text = pretty_print_tokens(ctx.tokens, context.allocator);
}
if output_type & .StdOut {
@@ -293,16 +293,16 @@ run_parser_test :: (file_path : string, ctx : *Compiler_Context, output_type : O
}
run_parser_test :: (ctx : *Compiler_Context, output_type : Output_Type = 0) -> Result {
parse(ctx);
parse(ctx, context.allocator);
result : Result;
result.path = ctx.file.path;
result_text : string;
if ctx.had_error {
result.type = .Failed;
result_text = report_messages(ctx.messages,, temp);
result_text = report_messages(ctx.messages);
} else {
result_text = pretty_print_ast(ctx.root, *temp);
result_text = pretty_print_ast(ctx.root, context.allocator);
}
if output_type & .StdOut {
@@ -321,13 +321,13 @@ run_semantic_analysis_test :: (ctx : *Compiler_Context, output_type : Output_Typ
result.path = ctx.file.path;
result_text : string;
check(ctx);
check(ctx, context.allocator);
if ctx.had_error {
result.type = .Failed;
result_text = report_messages(ctx.messages);
} else {
result_text = pretty_print_symbol_table(ctx, temp);
result_text = pretty_print_symbol_table(ctx, context.allocator);
}
if output_type & .StdOut {
@@ -345,8 +345,8 @@ run_semantic_analysis_test :: (file_path : string, ctx : *Compiler_Context, outp
result : Result;
result.path = file_path;
lex(ctx);
parse(ctx);
lex(ctx, context.allocator);
parse(ctx, context.allocator);
if ctx.had_error {
result.type = .Failed;
return result;
@@ -366,51 +366,56 @@ make_test_case :: (path : string, stage_flags : Stage_Flags, allocator := contex
return test_case;
}
run_test_new :: (file_path : string, stage_flags : Stage_Flags, results : *[..]Result, output_type : Output_Type = 0) {
ctx : Compiler_Context;
run_test_new :: (file_path : string, stage_flags : Stage_Flags, results : *[..]Result, output_type : Output_Type = 0, allocator := temp) {
new_context := context;
new_context.allocator = allocator;
push_context new_context {
ctx : Compiler_Context;
ctx.file = make_file(*ctx, file_path);
ctx.file = make_file(*ctx, file_path);
result : Result;
if stage_flags & .Lexer {
result = run_lexer_test(file_path, *ctx, output_type);
record_result(results, result);
}
if stage_flags & .Parser {
if stage_flags & .Lexer && result.type == .Passed || result.type == .Golden_Output {
result = run_parser_test(*ctx, output_type);
} else {
result = run_parser_test(file_path, *ctx, output_type);
result : Result;
if stage_flags & .Lexer {
result = run_lexer_test(file_path, *ctx, output_type);
record_result(results, result);
}
record_result(results, result);
}
if stage_flags & .Semantic_Analysis {
if stage_flags & .Parser && (result.type == .Passed || result.type == .Golden_Output) {
result = run_semantic_analysis_test(*ctx, output_type);
} else {
result = run_semantic_analysis_test(file_path, *ctx, output_type);
if stage_flags & .Parser {
if stage_flags & .Lexer && result.type == .Passed || result.type == .Golden_Output {
result = run_parser_test(*ctx, output_type);
} else {
result = run_parser_test(file_path, *ctx, output_type);
}
record_result(results, result);
}
record_result(results, result);
}
if stage_flags & .Codegen {
if stage_flags & .Semantic_Analysis && (result.type == .Passed || result.type == .Golden_Output) {
result = run_codegen_test(*ctx, output_type);
} else {
result = run_codegen_test(file_path, *ctx, output_type);
if stage_flags & .Semantic_Analysis {
if stage_flags & .Parser && (result.type == .Passed || result.type == .Golden_Output) {
result = run_semantic_analysis_test(*ctx, output_type);
} else {
result = run_semantic_analysis_test(file_path, *ctx, output_type);
}
record_result(results, result);
}
if stage_flags & .Codegen {
if stage_flags & .Semantic_Analysis && (result.type == .Passed || result.type == .Golden_Output) {
result = run_codegen_test(*ctx, output_type);
} else {
result = run_codegen_test(file_path, *ctx, output_type);
}
record_result(results, result);
}
if stage_flags & .Compile {
result = run_compile_test(file_path, output_type);
record_result(results, result);
}
record_result(results, result);
}
if stage_flags & .Compile {
result = run_compile_test(file_path, output_type);
record_result(results, result);
}
}
run_test :: (test_case : Test_Case, results : *[..]Result, output_type : Output_Type = 0) {
run_test :: (test_case : Test_Case, results : *[..]Result, output_type : Output_Type = 0, allocator := temp) {
print("%Running test: %......", cyan(), test_case.path);
// path 30
@@ -428,7 +433,7 @@ run_test :: (test_case : Test_Case, results : *[..]Result, output_type : Output_
print(" ");
}
run_test_new(test_case.path, test_case.stage_flags, results, output_type);
run_test_new(test_case.path, test_case.stage_flags, results, output_type, allocator);
}
record_result :: (results : *[..]Result, result : Result) {
@@ -446,14 +451,16 @@ run_test_suite :: (using suite : *Test_Suite, output_type : Output_Type = 0) {
stage : string;
}
test_arena : Allocator = make_arena(Gigabytes(1));
failed_test_paths : [..]Fail_Data;
failed_test_paths.allocator = temp;
failed_test_paths.allocator = test_arena;
builder : String_Builder;
init_string_builder(*builder,, temp);
init_string_builder(*builder,, test_arena);
for test_case : test_cases {
run_test(test_case, *suite.results, output_type);
run_test(test_case, *suite.results, output_type, allocator = test_arena);
for < suite.results {
result := suite.results[it_index];
@@ -496,10 +503,10 @@ run_test_suite :: (using suite : *Test_Suite, output_type : Output_Type = 0) {
}
}
print("%\n", builder_to_string(*builder,, temp));
print("%\n", builder_to_string(*builder,, test_arena));
}
read_suite :: (file_path : string, suite : *Test_Suite) -> bool {
read_suite :: (file_path : string, suite : *Test_Suite, allocator := temp) -> bool {
sc := get_scratch();
defer scratch_end(sc);
bytes, ok := read_entire_file(file_path,, sc.allocator);
@@ -510,10 +517,18 @@ read_suite :: (file_path : string, suite : *Test_Suite) -> bool {
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);
suite.name = copy_string(file_without_extension[0],, allocator);
split_lines := split(bytes, "\n",, sc.allocator);
for split_line : split_lines {
if split_line.count == 0 {
break;
}
if split_line[0] == #char "#" {
continue;
}
line := split(split_line, " ",, sc.allocator);
if line[0].count == 0 {
continue;
@@ -547,7 +562,7 @@ read_suite :: (file_path : string, suite : *Test_Suite) -> bool {
stage_flags |= .Compile;
}
}
test_case := make_test_case(test_case_path, stage_flags, temp);
test_case := make_test_case(test_case_path, stage_flags, allocator);
array_add(*suite.test_cases, test_case);
}
@@ -612,8 +627,10 @@ main :: () {
init_context_allocators();
local_temp := make_arena(Megabytes(128));
suites : [..]Test_Suite;
suites.allocator = temp;
suites.allocator = local_temp;
output_type : Output_Type = 0;
Argument_Parse_State :: enum {
@@ -626,8 +643,6 @@ 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 {
@@ -715,7 +730,7 @@ main :: () {
suite : Test_Suite;
suite.results.allocator = local_temp;
suite.test_cases.allocator = local_temp;
read_suite(path, *suite);
read_suite(path, *suite, local_temp);
array_add(*suites, suite);
current_suite = *suites[0];
} else {

View File

@@ -486,7 +486,7 @@ new_builtin_struct_node :: (ctx : *Compiler_Context, name : string, members : []
source_location.end = brace_token;
source := builder_to_string(*builder);
source := builder_to_string(*builder,, context.allocator);
source_location.begin.source = *source.data[source_location.begin.column];
source_location.end.source = *source.data[source_location.end.column];
@@ -557,7 +557,7 @@ new_builtin_function_node :: (ctx : *Compiler_Context, name : string, members :
source_location.end = semicolon_tok;
source := builder_to_string(*builder);
source := builder_to_string(*builder,, context.allocator);
source_location.begin.source = *source.data[source_location.begin.column];
source_location.end.source = *source.data[source_location.end.column];

BIN
output.tracy Normal file

Binary file not shown.

View File

@@ -1,4 +1,3 @@
test/assign_arithmetic_expression.ink semant
test/basic_property_and_return_value.ink semant
test/builtin_types.ink semant