mirror of
https://github.com/morluto/rea.git
synced 2026-12-06 17:23:37 +08:00
test(electron): share fallthrough coverage fixtures (#17460)
This commit is contained in:
@@ -306,97 +306,80 @@ cliTest(
|
||||
},
|
||||
);
|
||||
|
||||
const partialFallthrough = (name: string, body: string, condition: string) =>
|
||||
({ name, body, conditions: [condition], coverage: "partial" }) as const;
|
||||
|
||||
const completeFallthrough = (name: string, body: string) =>
|
||||
({ name, body, conditions: [], coverage: "complete" }) as const;
|
||||
|
||||
const fallthroughCases = [
|
||||
{
|
||||
name: "conditional early return",
|
||||
body: 'if(x)return;e.contextBridge.exposeInMainWorld("api",{copy:()=>e.ipcRenderer.send("x")});',
|
||||
conditions: ["!(x)"],
|
||||
coverage: "partial",
|
||||
},
|
||||
{
|
||||
name: "equivalent nested branch",
|
||||
body: 'if(!x){e.contextBridge.exposeInMainWorld("api",{copy:()=>e.ipcRenderer.send("x")});}',
|
||||
conditions: ["!x"],
|
||||
coverage: "partial",
|
||||
},
|
||||
{
|
||||
name: "conditional break to enclosing label",
|
||||
body: 'guard:{if(!x)break guard;e.contextBridge.exposeInMainWorld("api",{copy:()=>e.ipcRenderer.send("x")});}',
|
||||
conditions: ["!(!x)"],
|
||||
coverage: "partial",
|
||||
},
|
||||
{
|
||||
name: "nested label breaking enclosing label",
|
||||
body: 'guard:{if(!x)inner:{break guard;}e.contextBridge.exposeInMainWorld("api",{copy:()=>e.ipcRenderer.send("x")});}',
|
||||
conditions: ["!(!x)"],
|
||||
coverage: "partial",
|
||||
},
|
||||
{
|
||||
name: "nested label breaking itself",
|
||||
body: 'guard:{if(!x)inner:{break inner;}e.contextBridge.exposeInMainWorld("api",{copy:()=>e.ipcRenderer.send("x")});}',
|
||||
conditions: [],
|
||||
coverage: "complete",
|
||||
},
|
||||
{
|
||||
name: "inner break skips unreachable throw",
|
||||
body: 'guard:{if(x)inner:{break inner;throw 0;}e.contextBridge.exposeInMainWorld("api",{copy:()=>e.ipcRenderer.send("x")});}',
|
||||
conditions: [],
|
||||
coverage: "complete",
|
||||
},
|
||||
{
|
||||
name: "loop may break inner label before throw",
|
||||
body: 'guard:{if(x)inner:{while(true){break inner;}throw 0;}e.contextBridge.exposeInMainWorld("api",{copy:()=>e.ipcRenderer.send("x")});}',
|
||||
conditions: [],
|
||||
coverage: "complete",
|
||||
},
|
||||
{
|
||||
name: "try may break inner label before throw",
|
||||
body: 'guard:{if(x)inner:{try{break inner;}finally{}throw 0;}e.contextBridge.exposeInMainWorld("api",{copy:()=>e.ipcRenderer.send("x")});}',
|
||||
conditions: [],
|
||||
coverage: "complete",
|
||||
},
|
||||
{
|
||||
name: "ordinary loop before return retains guard",
|
||||
body: 'if(x){while(false){}return;}e.contextBridge.exposeInMainWorld("api",{copy:()=>e.ipcRenderer.send("x")});',
|
||||
conditions: ["!(x)"],
|
||||
coverage: "partial",
|
||||
},
|
||||
{
|
||||
name: "true guard and ordinary loop before return",
|
||||
body: 'if(true){while(false){}return;}e.contextBridge.exposeInMainWorld("api",{copy:()=>e.ipcRenderer.send("x")});',
|
||||
conditions: [],
|
||||
coverage: "complete",
|
||||
},
|
||||
{
|
||||
name: "ordinary loop before throw retains guard",
|
||||
body: 'if(x){for(const item of [])cleanup(item);throw 0;}e.contextBridge.exposeInMainWorld("api",{copy:()=>e.ipcRenderer.send("x")});',
|
||||
conditions: ["!(x)"],
|
||||
coverage: "partial",
|
||||
},
|
||||
{
|
||||
name: "loop local label cannot skip return",
|
||||
body: 'if(x){while(false){local:{break local;}}return;}e.contextBridge.exposeInMainWorld("api",{copy:()=>e.ipcRenderer.send("x")});',
|
||||
conditions: ["!(x)"],
|
||||
coverage: "partial",
|
||||
},
|
||||
{
|
||||
name: "break to inner label does not guard outer continuation",
|
||||
body: 'outer:{inner:{if(x)break inner;}e.contextBridge.exposeInMainWorld("api",{copy:()=>e.ipcRenderer.send("x")});}',
|
||||
conditions: [],
|
||||
coverage: "complete",
|
||||
},
|
||||
{
|
||||
name: "definite early return",
|
||||
body: 'return;e.contextBridge.exposeInMainWorld("api",{copy:()=>e.ipcRenderer.send("x")});',
|
||||
conditions: [],
|
||||
coverage: "complete",
|
||||
},
|
||||
{
|
||||
name: "unguarded exposure",
|
||||
body: 'e.contextBridge.exposeInMainWorld("api",{copy:()=>e.ipcRenderer.send("x")});',
|
||||
conditions: [],
|
||||
coverage: "complete",
|
||||
},
|
||||
partialFallthrough(
|
||||
"conditional early return",
|
||||
'if(x)return;e.contextBridge.exposeInMainWorld("api",{copy:()=>e.ipcRenderer.send("x")});',
|
||||
"!(x)",
|
||||
),
|
||||
partialFallthrough(
|
||||
"equivalent nested branch",
|
||||
'if(!x){e.contextBridge.exposeInMainWorld("api",{copy:()=>e.ipcRenderer.send("x")});}',
|
||||
"!x",
|
||||
),
|
||||
partialFallthrough(
|
||||
"conditional break to enclosing label",
|
||||
'guard:{if(!x)break guard;e.contextBridge.exposeInMainWorld("api",{copy:()=>e.ipcRenderer.send("x")});}',
|
||||
"!(!x)",
|
||||
),
|
||||
partialFallthrough(
|
||||
"nested label breaking enclosing label",
|
||||
'guard:{if(!x)inner:{break guard;}e.contextBridge.exposeInMainWorld("api",{copy:()=>e.ipcRenderer.send("x")});}',
|
||||
"!(!x)",
|
||||
),
|
||||
completeFallthrough(
|
||||
"nested label breaking itself",
|
||||
'guard:{if(!x)inner:{break inner;}e.contextBridge.exposeInMainWorld("api",{copy:()=>e.ipcRenderer.send("x")});}',
|
||||
),
|
||||
completeFallthrough(
|
||||
"inner break skips unreachable throw",
|
||||
'guard:{if(x)inner:{break inner;throw 0;}e.contextBridge.exposeInMainWorld("api",{copy:()=>e.ipcRenderer.send("x")});}',
|
||||
),
|
||||
completeFallthrough(
|
||||
"loop may break inner label before throw",
|
||||
'guard:{if(x)inner:{while(true){break inner;}throw 0;}e.contextBridge.exposeInMainWorld("api",{copy:()=>e.ipcRenderer.send("x")});}',
|
||||
),
|
||||
completeFallthrough(
|
||||
"try may break inner label before throw",
|
||||
'guard:{if(x)inner:{try{break inner;}finally{}throw 0;}e.contextBridge.exposeInMainWorld("api",{copy:()=>e.ipcRenderer.send("x")});}',
|
||||
),
|
||||
partialFallthrough(
|
||||
"ordinary loop before return retains guard",
|
||||
'if(x){while(false){}return;}e.contextBridge.exposeInMainWorld("api",{copy:()=>e.ipcRenderer.send("x")});',
|
||||
"!(x)",
|
||||
),
|
||||
completeFallthrough(
|
||||
"true guard and ordinary loop before return",
|
||||
'if(true){while(false){}return;}e.contextBridge.exposeInMainWorld("api",{copy:()=>e.ipcRenderer.send("x")});',
|
||||
),
|
||||
partialFallthrough(
|
||||
"ordinary loop before throw retains guard",
|
||||
'if(x){for(const item of [])cleanup(item);throw 0;}e.contextBridge.exposeInMainWorld("api",{copy:()=>e.ipcRenderer.send("x")});',
|
||||
"!(x)",
|
||||
),
|
||||
partialFallthrough(
|
||||
"loop local label cannot skip return",
|
||||
'if(x){while(false){local:{break local;}}return;}e.contextBridge.exposeInMainWorld("api",{copy:()=>e.ipcRenderer.send("x")});',
|
||||
"!(x)",
|
||||
),
|
||||
completeFallthrough(
|
||||
"break to inner label does not guard outer continuation",
|
||||
'outer:{inner:{if(x)break inner;}e.contextBridge.exposeInMainWorld("api",{copy:()=>e.ipcRenderer.send("x")});}',
|
||||
),
|
||||
completeFallthrough(
|
||||
"definite early return",
|
||||
'return;e.contextBridge.exposeInMainWorld("api",{copy:()=>e.ipcRenderer.send("x")});',
|
||||
),
|
||||
completeFallthrough(
|
||||
"unguarded exposure",
|
||||
'e.contextBridge.exposeInMainWorld("api",{copy:()=>e.ipcRenderer.send("x")});',
|
||||
),
|
||||
] as const;
|
||||
|
||||
cliTest(
|
||||
|
||||
Reference in New Issue
Block a user