PolyglotSpecRunner, BehavioralParityChecker, ParityRegressionGuard, PolyglotSuiteOrchestrator — 26/26 tests pass. Integration step 1942: poly-sort Python+Rust+Go parity verified. Metrics: 7 whetstone calls, 8855 tokens. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
95 lines
3.1 KiB
C++
95 lines
3.1 KiB
C++
// Step 1938: PolyglotSpecRunner
|
|
//
|
|
// t1: registerVariant and registeredLanguages/variantCount
|
|
// t2: recordOutput and runAll returns recorded results
|
|
// t3: runAll returns ran=false for variants with no recorded output
|
|
// t4: unknown nodeId returns empty runAll
|
|
// t5: multiple nodeIds are independent
|
|
|
|
#include "PolyglotSpecRunner.h"
|
|
#include <iostream>
|
|
|
|
namespace ws = whetstone;
|
|
static int p=0,f=0;
|
|
#define T(n) { std::cout<<" "<<#n<<"... "; }
|
|
#define P() { std::cout<<"PASS\n"; ++p; }
|
|
#define F(m) { std::cout<<"FAIL: "<<m<<"\n"; ++f; }
|
|
#define C(c,m) if(!(c)){F(m);return;}
|
|
|
|
void t1(){
|
|
T(registerVariant_and_metadata);
|
|
ws::PolyglotSpecRunner r;
|
|
r.registerVariant("sort","Python","sort.py");
|
|
r.registerVariant("sort","Rust", "sort");
|
|
r.registerVariant("sort","Go", "sort_go");
|
|
C(r.variantCount("sort") == 3, "three variants");
|
|
auto langs = r.registeredLanguages("sort");
|
|
C(langs.size() == 3, "three languages");
|
|
C(r.variantCount("unknown") == 0, "unknown zero");
|
|
P();
|
|
}
|
|
|
|
void t2(){
|
|
T(recordOutput_and_runAll);
|
|
ws::PolyglotSpecRunner r;
|
|
r.registerVariant("sort","Python","sort.py");
|
|
r.registerVariant("sort","Rust", "sort");
|
|
r.recordOutput("sort","Python","1 2 3\n",0);
|
|
r.recordOutput("sort","Rust", "1 2 3\n",0);
|
|
auto results = r.runAll("sort","3 1 2");
|
|
C(results.size() == 2, "two results");
|
|
bool pyOk = false, rsOk = false;
|
|
for (auto& rr : results) {
|
|
if (rr.language == "Python") { pyOk = rr.ran && rr.output == "1 2 3\n"; }
|
|
if (rr.language == "Rust") { rsOk = rr.ran && rr.output == "1 2 3\n"; }
|
|
}
|
|
C(pyOk, "Python result ok");
|
|
C(rsOk, "Rust result ok");
|
|
P();
|
|
}
|
|
|
|
void t3(){
|
|
T(missing_recorded_output_gives_ran_false);
|
|
ws::PolyglotSpecRunner r;
|
|
r.registerVariant("sort","Python","sort.py");
|
|
r.registerVariant("sort","Go", "sort_go");
|
|
r.recordOutput("sort","Python","ok\n",0);
|
|
// Go has no recorded output
|
|
auto results = r.runAll("sort","input");
|
|
bool goFound = false;
|
|
for (auto& rr : results)
|
|
if (rr.language == "Go") { goFound = true; C(!rr.ran,"Go ran=false"); }
|
|
C(goFound, "Go result present");
|
|
P();
|
|
}
|
|
|
|
void t4(){
|
|
T(unknown_nodeId_returns_empty);
|
|
ws::PolyglotSpecRunner r;
|
|
r.registerVariant("sort","Python","p");
|
|
auto results = r.runAll("unknown","input");
|
|
C(results.empty(), "empty for unknown node");
|
|
P();
|
|
}
|
|
|
|
void t5(){
|
|
T(multiple_nodeIds_independent);
|
|
ws::PolyglotSpecRunner r;
|
|
r.registerVariant("sort", "Rust","s");
|
|
r.registerVariant("merge", "Go", "m");
|
|
r.recordOutput("sort", "Rust","sorted\n",0);
|
|
r.recordOutput("merge", "Go", "merged\n",0);
|
|
auto sr = r.runAll("sort", "");
|
|
auto mr = r.runAll("merge","");
|
|
C(sr.size() == 1 && sr[0].output == "sorted\n", "sort result");
|
|
C(mr.size() == 1 && mr[0].output == "merged\n", "merge result");
|
|
P();
|
|
}
|
|
|
|
int main(){
|
|
std::cout << "Step 1938: PolyglotSpecRunner\n";
|
|
t1(); t2(); t3(); t4(); t5();
|
|
std::cout << "\n" << p << "/" << (p+f) << " passed\n";
|
|
return f > 0 ? 1 : 0;
|
|
}
|