Repository: duckdb/duckdb
File: test/sqlite/result_helper.cpp (C++)

Code before:
                                            duckdb::unique_ptr<MaterializedQueryResult> owned_result) {
	auto &result = *owned_result;
	bool error = result.HasError();
	SQLLogicTestLogger logger(context, statement);
	if (runner.output_result_mode || runner.debug_mode) {
		result.Print();
	}

	/* Check to see if we are expecting success or failure */
	auto expected_result = statement.expected_result;
	if (expected_result != ExpectedResult::RESULT_SUCCESS) {
		// even in the case of "statement error", we do not accept ALL errors
		// internal errors are never expected
		// neither are "unoptimized result differs from original result" errors

		if (result.HasError() && TestIsInternalError(runner.always_fail_error_messages, result.GetError())) {
			logger.InternalException(result);
			return false;
		}
		if (expected_result == ExpectedResult::RESULT_UNKNOWN) {
			error = false;
		} else {
			error = !error;
		}
		if (result.HasError() && !statement.expected_error.empty()) {
			// We run both comparions on purpose, we might move to only the second but might require some changes in
			// tests
			if (!StringUtil::Contains(result.GetError(), statement.expected_error) &&
			    !StringUtil::Contains(result.GetError(), runner.ReplaceKeywords(statement.expected_error))) {
				bool success = false;
				if (StringUtil::StartsWith(statement.expected_error, "<REGEX>:") ||
				    StringUtil::StartsWith(statement.expected_error, "<!REGEX>:")) {
					success = MatchesRegex(logger, result.ToString(), statement.expected_error);
				}
				if (!success) {
					// don't log the same test failure many times:
					// e.g. log only the first failure in
					// `./build/debug/test/unittest --on-init "SET max_memory='400kb';"
					// test/fuzzer/pedro/concurrent_catalog_usage.test`
					if (!SkipErrorMessage(result.GetError()) &&
					    !FailureSummary::SkipLoggingSameError(statement.file_name)) {
						logger.ExpectedErrorMismatch(statement.expected_error, result);
						return false;
					}
				}
				string success_log =
				    StringUtil::Format("CheckStatementResult: %s:%d", statement.file_name, statement.query_line);
				REQUIRE(success_log.c_str());
				return true;
			}
		}

Review comment (suggestion):
If I grok, the change is to check both raw error match and kw-subst'd match, and the comment suggests that we may not need both... but unclear why -- I assume it's uncertainty/lack of confidence that all cases are covered? Might be nice clarify for future code/comment GC
(ditto for comment below @ line 313)

Code after:
                                            duckdb::unique_ptr<MaterializedQueryResult> owned_result) {
	auto &result = *owned_result;
	bool error = result.HasError();
	SQLLogicTestLogger logger(context, statement);
	if (runner.output_result_mode || runner.debug_mode) {
		result.Print();
	}

	/* Check to see if we are expecting success or failure */
	auto expected_result = statement.expected_result;
	if (expected_result != ExpectedResult::RESULT_SUCCESS) {
		// even in the case of "statement error", we do not accept ALL errors
		// internal errors are never expected
		// neither are "unoptimized result differs from original result" errors

		if (result.HasError() && TestIsInternalError(runner.always_fail_error_messages, result.GetError())) {
			logger.InternalException(result);
			return false;
		}
		if (expected_result == ExpectedResult::RESULT_UNKNOWN) {
			error = false;
		} else {
			error = !error;
		}
		if (result.HasError() && !statement.expected_error.empty()) {
			// We run both comparions on purpose, we might move to only the second but might require some changes in
			// tests
			// This is due to some errors containing absolute paths, some relatives
			if (!StringUtil::Contains(result.GetError(), statement.expected_error) &&
			    !StringUtil::Contains(result.GetError(), runner.ReplaceKeywords(statement.expected_error))) {
				bool success = false;
				if (StringUtil::StartsWith(statement.expected_error, "<REGEX>:") ||
				    StringUtil::StartsWith(statement.expected_error, "<!REGEX>:")) {
					success = MatchesRegex(logger, result.ToString(), statement.expected_error);
				}
				if (!success) {
					// don't log the same test failure many times:
					// e.g. log only the first failure in
					// `./build/debug/test/unittest --on-init "SET max_memory='400kb';"
					// test/fuzzer/pedro/concurrent_catalog_usage.test`
					if (!SkipErrorMessage(result.GetError()) &&
					    !FailureSummary::SkipLoggingSameError(statement.file_name)) {
						logger.ExpectedErrorMismatch(statement.expected_error, result);
						return false;
					}
				}
				string success_log =
				    StringUtil::Format("CheckStatementResult: %s:%d", statement.file_name, statement.query_line);
				REQUIRE(success_log.c_str());
				return true;
			}