Files
zeekay cc0aa16da7 The C++ Q, Z, D and F chains, and the half of a decision Q was missing
Four ports existed on branches nothing built and nothing ran against the
corpus. They are here so the differential has a C++ voice on the four
chains it could not see, and so that whatever they answer is answered in
public rather than in a branch.

  quantumvm  from blue/quantumvm-cpp
  zkvm       from blue/zkvm-cpp-impl
  dexvm      from blue/dexvm-cpp
  fhevm      from blue/fhevm-cpp  (with chains/cpp/zap, which it reads)

quantumvm did not build: the node's VM seam grew `Block::reject()` after
that branch was written, so VmBlock was abstract and every construction
of it was a compile error. It forwards to the block's own reject now,
and — as the seam asks and as Go's pendingBlocks.Decided does — accept
and reject are each inert once either has run.

Nothing else was changed. What these ports say about the corpus is the
next commit's business, and it is not this commit's job to make them say
anything in particular.

Verified: all four configure, build and pass their own suites here —
quantumvm 13/13, zkvm 13/13, dexvm 10/10, fhevm 14/14.
2026-09-05 13:50:41 -07:00

115 lines
6.7 KiB
C++

// Copyright (C) 2026, Lux Industries, Inc. All rights reserved.
// SPDX-License-Identifier: BSD-3-Clause-Eco
//
// harness.hpp — the smallest thing that can run a ported Go test honestly.
//
// The Go suite says `require.Equal(expected, got)` and `require.ErrorIs(err,
// errX)`; the ported test says the same, so the two can be read side by side. A
// test that cannot run PRINTS `skipped` and says why — a skip is never reported
// as a pass, and the binary's exit code is nonzero only for real failures,
// never for a skip that was declared.
#pragma once
#include "lux/quantumvm/error.hpp"
#include <cstdio>
#include <functional>
#include <string>
#include <string_view>
#include <vector>
namespace qvmtest {
struct Case {
std::string name;
std::function<void()> body;
};
std::vector<Case>& registry();
void fail_current(const std::string& msg);
void skip_current(const std::string& why);
int run_all(std::string_view suite);
struct Register {
Register(const char* name, std::function<void()> body) { registry().push_back({name, std::move(body)}); }
};
} // namespace qvmtest
#define QVM_CONCAT_(a, b) a##b
#define QVM_CONCAT(a, b) QVM_CONCAT_(a, b)
// TEST(Name) { ... } — one ported Go test function.
#define TEST(name) \
static void QVM_CONCAT(qvm_case_, name)(); \
static ::qvmtest::Register QVM_CONCAT(qvm_reg_, name)(#name, QVM_CONCAT(qvm_case_, name)); \
static void QVM_CONCAT(qvm_case_, name)()
#define REQUIRE(cond) \
do { \
if (!(cond)) { \
::qvmtest::fail_current(std::string(__FILE__ ":") + std::to_string(__LINE__) + \
" require(" #cond ")"); \
return; \
} \
} while (0)
#define REQUIRE_MSG(cond, msg) \
do { \
if (!(cond)) { \
::qvmtest::fail_current(std::string(__FILE__ ":") + std::to_string(__LINE__) + \
" " + (msg)); \
return; \
} \
} while (0)
#define REQUIRE_EQ(want, got) \
do { \
const auto& _w = (want); \
const auto& _g = (got); \
if (!(_w == _g)) { \
::qvmtest::fail_current(std::string(__FILE__ ":") + std::to_string(__LINE__) + \
" " #want " != " #got); \
return; \
} \
} while (0)
// REQUIRE_ERR(expr, code) — the Go suite's require.ErrorIs: this input is
// refused for THIS reason, not merely refused.
#define REQUIRE_ERR(expr, want_code) \
do { \
auto&& _r = (expr); \
if (_r) { \
::qvmtest::fail_current(std::string(__FILE__ ":") + std::to_string(__LINE__) + \
" " #expr " succeeded, wanted " #want_code); \
return; \
} \
if (_r.error().code != (want_code)) { \
::qvmtest::fail_current(std::string(__FILE__ ":") + std::to_string(__LINE__) + \
" " #expr " failed with " + _r.error().message() + \
", wanted " #want_code); \
return; \
} \
} while (0)
#define REQUIRE_FAILS(expr) \
do { \
auto&& _r = (expr); \
if (_r) { \
::qvmtest::fail_current(std::string(__FILE__ ":") + std::to_string(__LINE__) + \
" " #expr " succeeded, wanted a refusal"); \
return; \
} \
} while (0)
#define REQUIRE_OK(expr) \
do { \
auto&& _r = (expr); \
if (!_r) { \
::qvmtest::fail_current(std::string(__FILE__ ":") + std::to_string(__LINE__) + \
" " #expr ": " + _r.error().message()); \
return; \
} \
} while (0)