Files
RedBear-OS/local/recipes/dev/libclc/source/flang/lib/Testing/testing.cpp
T
vasilito cb424d7448 build: static patch-sanity linter (shift-left the malformed-patch class)
verify-patch-sanity.py validates every active recipe .patch has internally-
consistent hunk line counts — catching the 'malformed patch at line N' failure
at commit/CI/preflight time instead of hours into a cook. This cycle hit that
class three times (qtwaylandscanner, sddm, xwayland), each only discovered when
cookbook tried to apply the patch.

Running it across the repo found 29 latent malformed patches (validated against
GNU patch: e.g. relibc/P3-sysv-ipc reproduces 'malformed patch at line 22').
They were harmless only because they sit in vendored recipes (baked, not re-
applied) — but would fail on any version-bump re-derivation. --fix recounts the
hunk headers (body untouched) and repaired all 29.

Wired into build-preflight.sh (Phase 1.0D) and redbear-ci.yml, with a unit test
(test-patch-sanity.sh). Skips archived/legacy trees and unvalidatable formats
(empty placeholders, bare-@@ git hunks).
2026-08-01 05:13:02 +03:00

136 lines
3.3 KiB
C++

//===-- lib/Testing/testing.cpp ---------------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#include "flang/Testing/testing.h"
#include "llvm/Support/raw_ostream.h"
#include <cstdarg>
#include <cstdio>
#include <cstdlib>
namespace testing {
namespace {
int passes{0};
int failures{0};
} // namespace
static void BitBucket(const char *, ...) {}
static void PrintFailureDetails(const char *format, ...) {
va_list ap;
va_start(ap, format);
fputs("\t", stderr);
vfprintf(stderr, format, ap);
va_end(ap);
fputc('\n', stderr);
}
FailureDetailPrinter Test(
const char *file, int line, const char *predicate, bool pass) {
if (pass) {
++passes;
return BitBucket;
} else {
++failures;
fprintf(stderr, "%s:%d: FAIL: %s\n", file, line, predicate);
return PrintFailureDetails;
}
}
FailureDetailPrinter Match(const char *file, int line, std::uint64_t want,
const char *gots, std::uint64_t got) {
if (want == got) {
++passes;
return BitBucket;
} else {
++failures;
fprintf(stderr, "%s:%d: FAIL: %s == 0x%jx, not 0x%jx\n", file, line, gots,
static_cast<std::uintmax_t>(got), static_cast<std::uintmax_t>(want));
return PrintFailureDetails;
}
}
FailureDetailPrinter Match(const char *file, int line, const char *want,
const char *gots, const std::string &got) {
if (want == got) {
++passes;
return BitBucket;
} else {
++failures;
fprintf(stderr, "%s:%d: FAIL: %s == \"%s\", not \"%s\"\n", file, line, gots,
got.data(), want);
return PrintFailureDetails;
}
}
FailureDetailPrinter Match(const char *file, int line, const std::string &want,
const char *gots, const std::string &got) {
return Match(file, line, want.data(), gots, got);
}
FailureDetailPrinter Compare(const char *file, int line, const char *xs,
const char *rel, const char *ys, std::uint64_t x, std::uint64_t y) {
while (*rel == ' ') {
++rel;
}
bool pass{false};
if (*rel == '<') {
if (rel[1] == '=') {
pass = x <= y;
} else {
pass = x < y;
}
} else if (*rel == '>') {
if (rel[1] == '=') {
pass = x >= y;
} else {
pass = x > y;
}
} else if (*rel == '=') {
pass = x == y;
} else if (*rel == '!') {
pass = x != y;
}
if (pass) {
++passes;
return BitBucket;
} else {
++failures;
fprintf(stderr, "%s:%d: FAIL: %s[0x%jx] %s %s[0x%jx]\n", file, line, xs,
static_cast<std::uintmax_t>(x), rel, ys,
static_cast<std::uintmax_t>(y));
return PrintFailureDetails;
}
}
int Complete() {
if (failures == 0) {
if (passes == 1) {
llvm::outs() << "single test PASSES\n";
} else {
llvm::outs() << "all " << passes << " tests PASS\n";
}
passes = 0;
return EXIT_SUCCESS;
} else {
if (passes == 1) {
llvm::errs() << "1 test passes, ";
} else {
llvm::errs() << passes << " tests pass, ";
}
if (failures == 1) {
llvm::errs() << "1 test FAILS\n";
} else {
llvm::errs() << failures << " tests FAIL\n";
}
passes = failures = 0;
return EXIT_FAILURE;
}
}
} // namespace testing