Fix error propagation error in parsing. Semantic checker fix for compile result struct. Test cleanup
This commit is contained in:
134
Test.jai
134
Test.jai
@@ -119,40 +119,40 @@ get_golden_path :: (file_path : string, stage : Stage_Flags, allocator := contex
|
||||
return final_path;
|
||||
}
|
||||
|
||||
run_lexer_test :: (file_path : string, lexer : *Lexer, output_type : Output_Type = 0) -> Result {
|
||||
ok := read_input_from_file(lexer, file_path);
|
||||
// run_lexer_test :: (file_path : string, lexer : *Lexer, output_type : Output_Type = 0) -> Result {
|
||||
// ok := read_input_from_file(lexer, file_path);
|
||||
|
||||
result_data : Result;
|
||||
result_data.path = file_path;
|
||||
result_data.stage = .Lexer;
|
||||
// result_data : Result;
|
||||
// result_data.path = file_path;
|
||||
// result_data.stage = .Lexer;
|
||||
|
||||
if !ok {
|
||||
result_data.type = .File_Read_Failed;
|
||||
result_data.info_text = tprint("Unable to read file: %\n", file_path);
|
||||
// if !ok {
|
||||
// result_data.type = .File_Read_Failed;
|
||||
// result_data.info_text = tprint("Unable to read file: %\n", file_path);
|
||||
|
||||
return result_data;
|
||||
} else {
|
||||
result_text : string;
|
||||
result := lex(lexer, *temp);
|
||||
// return result_data;
|
||||
// } else {
|
||||
// result_text : string;
|
||||
// result := lex(lexer, *temp);
|
||||
|
||||
if result.had_error {
|
||||
result_data.type = .Failed;
|
||||
result_text = report_messages(result.messages);
|
||||
} else {
|
||||
result_text = pretty_print_tokens(result.tokens, *temp);
|
||||
}
|
||||
// if result.had_error {
|
||||
// result_data.type = .Failed;
|
||||
// result_text = report_messages(result.messages);
|
||||
// } else {
|
||||
// result_text = pretty_print_tokens(result.tokens, *temp);
|
||||
// }
|
||||
|
||||
if output_type & .StdOut {
|
||||
result_data.info_text = result_text;
|
||||
result_data.type = .StdOut;
|
||||
return result_data;
|
||||
}
|
||||
// if output_type & .StdOut {
|
||||
// result_data.info_text = result_text;
|
||||
// result_data.type = .StdOut;
|
||||
// return result_data;
|
||||
// }
|
||||
|
||||
golden_path := get_golden_path(file_path, .Lexer);
|
||||
do_golden_comparison(golden_path, result_text, *result_data, output_type);
|
||||
return result_data;
|
||||
}
|
||||
}
|
||||
// golden_path := get_golden_path(file_path, .Lexer);
|
||||
// do_golden_comparison(golden_path, result_text, *result_data, output_type);
|
||||
// return result_data;
|
||||
// }
|
||||
// }
|
||||
|
||||
run_parser_test :: (file_path : string, output_type : Output_Type = 0) -> Result, *AST_Node {
|
||||
lexer : Lexer;
|
||||
@@ -490,14 +490,11 @@ run_parser_test :: (result : *Compile_Result, output_type : Output_Type = 0) ->
|
||||
return result_data;
|
||||
}
|
||||
|
||||
run_semantic_analysis_test :: (file_path : string, result : *Compile_Result, output_type : Output_Type = 0) -> Result {
|
||||
add_file(result, file_path);
|
||||
|
||||
run_semantic_analysis_test :: (result : *Compile_Result, output_type : Output_Type = 0) -> Result {
|
||||
result_data : Result;
|
||||
|
||||
result_data.path = file_path;
|
||||
result_data.stage = .Semantic_Analysis;
|
||||
result_data.path = result.files[0].file.path;
|
||||
result_text : string;
|
||||
|
||||
check(result);
|
||||
|
||||
if result.had_error {
|
||||
@@ -513,11 +510,29 @@ run_semantic_analysis_test :: (file_path : string, result : *Compile_Result, out
|
||||
return result_data;
|
||||
}
|
||||
|
||||
golden_path := get_golden_path(file_path, .Semantic_Analysis);
|
||||
golden_path := get_golden_path(result.files[0].file.path, .Semantic_Analysis);
|
||||
do_golden_comparison(golden_path, result_text, *result_data, output_type);
|
||||
return result_data;
|
||||
}
|
||||
|
||||
run_semantic_analysis_test :: (file_path : string, result : *Compile_Result, output_type : Output_Type = 0) -> Result {
|
||||
add_file(result, file_path);
|
||||
|
||||
result_data : Result;
|
||||
result_data.path = file_path;
|
||||
|
||||
lex(result);
|
||||
parse(result);
|
||||
if result.had_error {
|
||||
result_data.type = .Passed;
|
||||
return result_data;
|
||||
}
|
||||
|
||||
result_data = run_semantic_analysis_test(result, output_type);;
|
||||
|
||||
return result_data;
|
||||
}
|
||||
|
||||
make_test_case :: (path : string, stage_flags : Stage_Flags, allocator := context.allocator) -> Test_Case {
|
||||
test_case : Test_Case;
|
||||
test_case.path = copy_string(path,, allocator);
|
||||
@@ -569,50 +584,6 @@ run_test_new :: (file_path : string, stage_flags : Stage_Flags, results : *[..]R
|
||||
// }
|
||||
}
|
||||
|
||||
run_test :: (file_path : string, stage_flags : Stage_Flags, results : *[..]Result, output_type : Output_Type = 0) {
|
||||
lexer : Lexer;
|
||||
result : Result;
|
||||
if stage_flags & .Lexer {
|
||||
result = run_lexer_test(file_path, *lexer, output_type);
|
||||
record_result(results, result);
|
||||
}
|
||||
|
||||
root_node : *AST_Node;
|
||||
if stage_flags & .Parser {
|
||||
if stage_flags & .Lexer && result.type == .Passed || result.type == .Golden_Output {
|
||||
result, root_node = run_parser_test(*lexer, output_type);
|
||||
} else {
|
||||
result, root_node = run_parser_test(file_path, output_type);
|
||||
}
|
||||
record_result(results, result);
|
||||
}
|
||||
|
||||
check_result : Semantic_Check_Result;
|
||||
if stage_flags & .Semantic_Analysis {
|
||||
if stage_flags & .Parser && (result.type == .Passed || result.type == .Golden_Output) {
|
||||
result, check_result = run_semantic_analysis_test(file_path, root_node, output_type);
|
||||
} else {
|
||||
result, check_result = run_semantic_analysis_test(file_path, 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(file_path, root_node, check_result, output_type);
|
||||
} else if root_node {
|
||||
result = run_codegen_test(file_path, root_node, output_type);
|
||||
} else {
|
||||
result = run_codegen_test(file_path, output_type);
|
||||
}
|
||||
record_result(results, result);
|
||||
}
|
||||
|
||||
if stage_flags & .Compile {
|
||||
result = run_compile_test(file_path, output_type);
|
||||
}
|
||||
}
|
||||
|
||||
run_test :: (test_case : Test_Case, results : *[..]Result, output_type : Output_Type = 0) {
|
||||
print("%Running test: %......", cyan(), test_case.path);
|
||||
|
||||
@@ -630,8 +601,9 @@ run_test :: (test_case : Test_Case, results : *[..]Result, output_type : Output_
|
||||
for i: 0..rest {
|
||||
print(" ");
|
||||
}
|
||||
|
||||
run_test(test_case.path, test_case.stage_flags, results, output_type);
|
||||
|
||||
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) {
|
||||
|
||||
Reference in New Issue
Block a user