102 lines
3.5 KiB
C++
102 lines
3.5 KiB
C++
|
|
// Step 1936: DAPBreakpointHitDispatcher
|
||
|
|
//
|
||
|
|
// t1: dispatch finds active breakpoint by source+line, sets router
|
||
|
|
// t2: dispatch returns dispatched=false when no breakpoint matches
|
||
|
|
// t3: dispatchAll returns all matches across different nodes/languages
|
||
|
|
// t4: dispatch skips inactive breakpoints
|
||
|
|
// t5: dispatchAll with no matches returns empty vector
|
||
|
|
|
||
|
|
#include "DAPBreakpointHitDispatcher.h"
|
||
|
|
#include "ASTNodeBreakpointMapper.h"
|
||
|
|
#include "DebugAdapterRouter.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;}
|
||
|
|
|
||
|
|
static ws::DebugAdapterRouter makeRouter() {
|
||
|
|
ws::DebugAdapterRouter r;
|
||
|
|
r.registerAdapter("Python", {"stackTrace","stepIn"});
|
||
|
|
r.registerAdapter("Rust", {"stackTrace"});
|
||
|
|
r.setActiveLanguage("Python");
|
||
|
|
return r;
|
||
|
|
}
|
||
|
|
|
||
|
|
void t1(){
|
||
|
|
T(dispatch_finds_breakpoint_sets_router);
|
||
|
|
ws::ASTNodeBreakpointMapper mapper;
|
||
|
|
mapper.setBreakpoint("HandleRequest","Rust","server.rs",42);
|
||
|
|
mapper.setBreakpoint("HandleRequest","Python","server.py",10);
|
||
|
|
auto router = makeRouter();
|
||
|
|
ws::DAPBreakpointHitDispatcher d;
|
||
|
|
auto r = d.dispatch("server.rs", 42, mapper, router);
|
||
|
|
C(r.dispatched, "dispatched");
|
||
|
|
C(r.language == "Rust", "language Rust");
|
||
|
|
C(r.astNodeId == "HandleRequest", "astNodeId");
|
||
|
|
C(r.line == 42, "line 42");
|
||
|
|
C(router.getActiveLanguage() == "Rust","router set to Rust");
|
||
|
|
P();
|
||
|
|
}
|
||
|
|
|
||
|
|
void t2(){
|
||
|
|
T(dispatch_no_match_returns_false);
|
||
|
|
ws::ASTNodeBreakpointMapper mapper;
|
||
|
|
mapper.setBreakpoint("HandleRequest","Rust","server.rs",42);
|
||
|
|
auto router = makeRouter();
|
||
|
|
ws::DAPBreakpointHitDispatcher d;
|
||
|
|
auto r = d.dispatch("server.rs", 99, mapper, router);
|
||
|
|
C(!r.dispatched, "not dispatched");
|
||
|
|
C(router.getActiveLanguage() == "Python", "router unchanged");
|
||
|
|
P();
|
||
|
|
}
|
||
|
|
|
||
|
|
void t3(){
|
||
|
|
T(dispatchAll_returns_all_matches);
|
||
|
|
ws::ASTNodeBreakpointMapper mapper;
|
||
|
|
// Two different nodes with a breakpoint at same source:line
|
||
|
|
mapper.setBreakpoint("NodeA","Python","shared.py",5);
|
||
|
|
mapper.setBreakpoint("NodeB","Python","shared.py",5);
|
||
|
|
mapper.setBreakpoint("NodeC","Rust", "other.rs", 10);
|
||
|
|
auto router = makeRouter();
|
||
|
|
ws::DAPBreakpointHitDispatcher d;
|
||
|
|
auto results = d.dispatchAll("shared.py", 5, mapper, router);
|
||
|
|
C(results.size() == 2, "two matches");
|
||
|
|
C(results[0].dispatched,"first dispatched");
|
||
|
|
C(results[1].dispatched,"second dispatched");
|
||
|
|
P();
|
||
|
|
}
|
||
|
|
|
||
|
|
void t4(){
|
||
|
|
T(dispatch_skips_inactive_breakpoints);
|
||
|
|
ws::ASTNodeBreakpointMapper mapper;
|
||
|
|
mapper.setBreakpoint("HandleRequest","Rust","server.rs",42);
|
||
|
|
mapper.deactivateAll("HandleRequest");
|
||
|
|
auto router = makeRouter();
|
||
|
|
ws::DAPBreakpointHitDispatcher d;
|
||
|
|
auto r = d.dispatch("server.rs", 42, mapper, router);
|
||
|
|
C(!r.dispatched, "inactive bp not dispatched");
|
||
|
|
P();
|
||
|
|
}
|
||
|
|
|
||
|
|
void t5(){
|
||
|
|
T(dispatchAll_no_match_returns_empty);
|
||
|
|
ws::ASTNodeBreakpointMapper mapper;
|
||
|
|
mapper.setBreakpoint("HandleRequest","Rust","server.rs",42);
|
||
|
|
auto router = makeRouter();
|
||
|
|
ws::DAPBreakpointHitDispatcher d;
|
||
|
|
auto results = d.dispatchAll("server.rs", 99, mapper, router);
|
||
|
|
C(results.empty(), "empty on no match");
|
||
|
|
P();
|
||
|
|
}
|
||
|
|
|
||
|
|
int main(){
|
||
|
|
std::cout << "Step 1936: DAPBreakpointHitDispatcher\n";
|
||
|
|
t1(); t2(); t3(); t4(); t5();
|
||
|
|
std::cout << "\n" << p << "/" << (p+f) << " passed\n";
|
||
|
|
return f > 0 ? 1 : 0;
|
||
|
|
}
|