From 2ea7d45f6e309608a47d39bee8096324e1f632fd Mon Sep 17 00:00:00 2001 From: Mattias Fredriksson Date: Fri, 18 Jul 2025 09:54:20 +0200 Subject: [PATCH] Cleanup: Improve output from OBJ export tests Improves output from tests comparing export results to the golden example file: - Prints which of the files that are empty and/or has no newline. - Prints a message when there is a mismatch in file length. - Clarifies that the inner compare loop only compares up to shortest string. - Prints the name of the failing golden file, indicating if it was the obj or mtl file that failed. Pull Request: https://projects.blender.org/blender/blender/pulls/141958 --- .../wavefront_obj/tests/obj_exporter_tests.cc | 33 ++++++++++++++----- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/source/blender/io/wavefront_obj/tests/obj_exporter_tests.cc b/source/blender/io/wavefront_obj/tests/obj_exporter_tests.cc index 0056d43a20a..caf980b6526 100644 --- a/source/blender/io/wavefront_obj/tests/obj_exporter_tests.cc +++ b/source/blender/io/wavefront_obj/tests/obj_exporter_tests.cc @@ -243,12 +243,23 @@ static bool strings_equal_after_first_lines(const std::string &a, const std::str const size_t b_len = b.size(); const size_t a_next = a.find_first_of('\n'); const size_t b_next = b.find_first_of('\n'); - if (a_next == std::string::npos || b_next == std::string::npos) { - printf("Couldn't find newline in one of args\n"); + if (a_next == std::string::npos) { + printf("No newline found in evaluated string\n"); return false; } - if (a.compare(a_next, a_len - a_next, b, b_next, b_len - b_next) != 0) { - for (int i = 0; i < a_len - a_next && i < b_len - b_next; ++i) { + if (b_next == std::string::npos) { + printf("No newline found in the golden string\n"); + return false; + } + const size_t a_sublen = a_len - a_next; + const size_t b_sublen = b_len - b_next; + if (a_sublen != b_sublen) { + printf("Mismatching string length, evaluated contains %zu chars, while golden has %zu\n", + a_sublen, + b_sublen); + } + if (a.compare(a_next, a_sublen, b, b_next, b_sublen) != 0) { + for (int i = 0; i < std::min(a_sublen, b_sublen); ++i) { if (a[a_next + i] != b[b_next + i]) { printf("Difference found at pos %zu of a\n", a_next + i); printf("a: %s ...\n", a.substr(a_next + i, 100).c_str()); @@ -293,8 +304,11 @@ class OBJExportRegressionTest : public OBJExportTest { std::string golden_str = read_temp_file_in_string(golden_file_path); bool are_equal = strings_equal_after_first_lines(output_str, golden_str); - if (save_failing_test_output && !are_equal) { - printf("failing test output in %s\n", out_file_path.c_str()); + if (!are_equal) { + printf("failed test for file: %s\n", golden_file_path.c_str()); + if (save_failing_test_output) { + printf("failing test output in %s\n", out_file_path.c_str()); + } } ASSERT_TRUE(are_equal); if (!save_failing_test_output || are_equal) { @@ -307,8 +321,11 @@ class OBJExportRegressionTest : public OBJExportTest { golden_mtl; std::string golden_mtl_str = read_temp_file_in_string(golden_mtl_file_path); are_equal = strings_equal_after_first_lines(output_mtl_str, golden_mtl_str); - if (save_failing_test_output && !are_equal) { - printf("failing test output in %s\n", out_mtl_file_path.c_str()); + if (!are_equal) { + printf("failed test for mtl file: %s\n", golden_mtl_file_path.c_str()); + if (save_failing_test_output) { + printf("failing test output in %s\n", out_mtl_file_path.c_str()); + } } ASSERT_TRUE(are_equal); if (!save_failing_test_output || are_equal) {