Files
whetstone_DSL/editor/tests/step1954_test.cpp

96 lines
2.9 KiB
C++
Raw Normal View History

// Step 1954: PolyglotExecutionContext
//
// t1: setConfig and languageCount
// t2: getConfig returns correct fields
// t3: hasConfig correct; getConfig throws on missing
// t4: config env vars and working_dir
// t5: configuredLanguages list
#include "PolyglotExecutionContext.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(setConfig_and_languageCount);
ws::PolyglotExecutionContext ctx;
C(ctx.languageCount() == 0, "empty initially");
ctx.setConfig("Python", {5000, {}, "/tmp/py"});
ctx.setConfig("Rust", {3000, {}, "/tmp/rs"});
C(ctx.languageCount() == 2, "two languages");
P();
}
void t2(){
T(getConfig_returns_correct_fields);
ws::PolyglotExecutionContext ctx;
ws::LanguageConfig cfg;
cfg.timeout_ms = 2500;
cfg.working_dir = "/workspace/go";
ctx.setConfig("Go", cfg);
const auto& got = ctx.getConfig("Go");
C(got.timeout_ms == 2500, "timeout_ms");
C(got.working_dir == "/workspace/go","working_dir");
P();
}
void t3(){
T(hasConfig_and_throws_on_missing);
ws::PolyglotExecutionContext ctx;
ctx.setConfig("Haskell", {1000, {}, ""});
C( ctx.hasConfig("Haskell"), "Haskell present");
C(!ctx.hasConfig("Lisp"), "Lisp absent");
bool threw = false;
try { ctx.getConfig("Lisp"); }
catch (const std::out_of_range&) { threw = true; }
C(threw, "throws on missing language");
P();
}
void t4(){
T(env_vars_stored_correctly);
ws::PolyglotExecutionContext ctx;
ws::LanguageConfig cfg;
cfg.timeout_ms = 8000;
cfg.env["PATH"] = "/usr/bin";
cfg.env["HOME"] = "/root";
cfg.working_dir = "/work";
ctx.setConfig("Java", cfg);
const auto& got = ctx.getConfig("Java");
C(got.env.size() == 2, "two env vars");
C(got.env.at("PATH") == "/usr/bin","PATH correct");
C(got.env.at("HOME") == "/root", "HOME correct");
P();
}
void t5(){
T(configuredLanguages_list);
ws::PolyglotExecutionContext ctx;
ctx.setConfig("TypeScript", {1000, {}, ""});
ctx.setConfig("Lisp", {2000, {}, ""});
ctx.setConfig("C++", {3000, {}, ""});
auto langs = ctx.configuredLanguages();
C(langs.size() == 3, "three languages");
// Just check all three present (map order is alphabetical)
bool hasTs = false, hasLisp = false, hasCpp = false;
for (const auto& l : langs) {
if (l == "TypeScript") hasTs = true;
if (l == "Lisp") hasLisp = true;
if (l == "C++") hasCpp = true;
}
C(hasTs && hasLisp && hasCpp, "all three present");
P();
}
int main(){
std::cout << "Step 1954: PolyglotExecutionContext\n";
t1(); t2(); t3(); t4(); t5();
std::cout << "\n" << p << "/" << (p+f) << " passed\n";
return f > 0 ? 1 : 0;
}