82 lines
2.7 KiB
C++
82 lines
2.7 KiB
C++
|
|
// Step 1956: PolyglotOrchestrator
|
||
|
|
//
|
||
|
|
// t1: addFunction delegates to functionMap
|
||
|
|
// t2: recordResult and runSummary pass/fail
|
||
|
|
// t3: runSummary allPassed when no failures
|
||
|
|
// t4: functionMap lookup via orchestrator
|
||
|
|
// t5: setContext and contextHas via executionContext
|
||
|
|
|
||
|
|
#include "PolyglotOrchestrator.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(addFunction_delegates_to_functionMap);
|
||
|
|
ws::PolyglotOrchestrator o;
|
||
|
|
o.addFunction("Python", "compute", "py::compute");
|
||
|
|
o.addFunction("Rust", "compute", "rs::compute");
|
||
|
|
C(o.functionMap().hasFunction("Python","compute"), "Python compute present");
|
||
|
|
C(o.functionMap().hasFunction("Rust", "compute"), "Rust compute present");
|
||
|
|
C(o.functionMap().functionCountForLanguage("Python") == 1, "one Python fn");
|
||
|
|
P();
|
||
|
|
}
|
||
|
|
|
||
|
|
void t2(){
|
||
|
|
T(recordResult_and_runSummary_pass_fail);
|
||
|
|
ws::PolyglotOrchestrator o;
|
||
|
|
o.recordResult({"Python","compute","42\n", true, 100});
|
||
|
|
o.recordResult({"Rust", "compute","42\n", true, 80});
|
||
|
|
o.recordResult({"Go", "compute","err\n",false, 50});
|
||
|
|
auto s = o.runSummary();
|
||
|
|
C(s.passCount == 2, "passCount 2");
|
||
|
|
C(s.failCount == 1, "failCount 1");
|
||
|
|
C(!s.allPassed, "not allPassed");
|
||
|
|
P();
|
||
|
|
}
|
||
|
|
|
||
|
|
void t3(){
|
||
|
|
T(runSummary_allPassed_when_no_failures);
|
||
|
|
ws::PolyglotOrchestrator o;
|
||
|
|
o.recordResult({"Python","fn","ok\n",true,100});
|
||
|
|
o.recordResult({"Rust", "fn","ok\n",true,90});
|
||
|
|
auto s = o.runSummary();
|
||
|
|
C(s.passCount == 2, "passCount 2");
|
||
|
|
C(s.failCount == 0, "failCount 0");
|
||
|
|
C(s.allPassed, "allPassed true");
|
||
|
|
P();
|
||
|
|
}
|
||
|
|
|
||
|
|
void t4(){
|
||
|
|
T(functionMap_lookup_via_orchestrator);
|
||
|
|
ws::PolyglotOrchestrator o;
|
||
|
|
o.addFunction("Haskell", "transform", "hs::transform_v2");
|
||
|
|
C(o.functionMap().lookupTag("Haskell","transform") == "hs::transform_v2", "tag correct");
|
||
|
|
P();
|
||
|
|
}
|
||
|
|
|
||
|
|
void t5(){
|
||
|
|
T(setContext_and_executionContext_hasConfig);
|
||
|
|
ws::PolyglotOrchestrator o;
|
||
|
|
ws::LanguageConfig cfg;
|
||
|
|
cfg.timeout_ms = 3000;
|
||
|
|
cfg.working_dir = "/work";
|
||
|
|
o.setContext("TypeScript", cfg);
|
||
|
|
C( o.executionContext().hasConfig("TypeScript"), "TypeScript configured");
|
||
|
|
C(!o.executionContext().hasConfig("Lisp"), "Lisp not configured");
|
||
|
|
C(o.executionContext().getConfig("TypeScript").timeout_ms == 3000, "timeout_ms correct");
|
||
|
|
P();
|
||
|
|
}
|
||
|
|
|
||
|
|
int main(){
|
||
|
|
std::cout << "Step 1956: PolyglotOrchestrator\n";
|
||
|
|
t1(); t2(); t3(); t4(); t5();
|
||
|
|
std::cout << "\n" << p << "/" << (p+f) << " passed\n";
|
||
|
|
return f > 0 ? 1 : 0;
|
||
|
|
}
|