Skip to content

Commit ec3b3c4

Browse files
authored
Merge pull request #5 from tmr232/fix-demo-build
fix demo build
2 parents c521670 + d23f1a9 commit ec3b3c4

File tree

9 files changed

+361
-253
lines changed

9 files changed

+361
-253
lines changed

.github/workflows/pages.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
name: Github Pages
22
on:
3+
pull_request:
34
push:
45
branches: "main"
56

@@ -20,6 +21,7 @@ jobs:
2021
with:
2122
path: ./dist/demo
2223
deploy:
24+
if: github.ref == 'refs/heads/main'
2325
needs: build
2426
runs-on: ubuntu-latest
2527
# Grant GITHUB_TOKEN the permissions required to make a Pages deployment

src/control-flow/cfg-python.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,9 @@ export class CFGBuilder {
224224
const exceptSyntaxMany = this.getSyntaxMany(match, "except-body");
225225
const elseSyntax = this.getSyntax(match, "else-body");
226226
const finallySyntax = this.getSyntax(match, "finally-body");
227+
228+
const mergeNode = this.addNode("MERGE", "merge try-complex");
229+
227230
return this.withCluster("try-complex", (tryComplexCluster) => {
228231
const bodyBlock = this.withCluster("try", () =>
229232
getBlock(bodySyntax),
@@ -281,29 +284,37 @@ export class CFGBuilder {
281284
return finallyBlock;
282285
});
283286

284-
let complexExit: string | null = bodyBlock.exit;
287+
// This is the exit we get to if we don't have an exception
288+
let happyExit: string | null = bodyBlock.exit;
285289

286290
// Connect the body to the `else` block
287291
if (bodyBlock.exit && elseBlock?.entry) {
288292
this.addEdge(bodyBlock.exit, elseBlock.entry);
289-
complexExit = elseBlock.exit;
293+
happyExit = elseBlock.exit;
290294
}
291295

292296
if (finallyBlock?.entry) {
293297
// Connect `try` to `finally`
294298
const toFinally = elseBlock?.exit ?? bodyBlock.exit;
295299
if (toFinally) this.addEdge(toFinally, finallyBlock.entry);
296-
complexExit = finallyBlock.exit;
300+
happyExit = finallyBlock.exit;
297301
// Connect `except` to `finally`
298302
exceptBlocks.forEach((exceptBlock) => {
299303
if (exceptBlock.exit)
300304
this.addEdge(exceptBlock.exit, finallyBlock.entry as string);
301305
});
306+
} else {
307+
// We need to connect the `except` blocks to the merge node
308+
exceptBlocks.forEach((exceptBlock) => {
309+
if (exceptBlock.exit) this.addEdge(exceptBlock.exit, mergeNode);
310+
});
302311
}
303312

313+
if (happyExit) this.addEdge(happyExit, mergeNode);
314+
304315
return blockHandler.update({
305316
entry: bodyBlock.entry,
306-
exit: complexExit,
317+
exit: mergeNode,
307318
});
308319
});
309320
}

src/demo/src/App.svelte

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22
import Demo from "../../frontend/src/lib/Demo.svelte";
33
import demoCodeGo from "./assets/demo.go?raw";
44
import demoCodeC from "./assets/demo.c?raw";
5+
import demoCodePython from "./assets/demo.py?raw";
56
</script>
67

78
<main>
8-
<Demo codeGo={demoCodeGo} codeC={demoCodeC} />
9+
<Demo codeGo={demoCodeGo} codeC={demoCodeC} codePython={demoCodePython} />
910
</main>
1011

1112
<style>

src/demo/src/assets/demo.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
def f():
2+
try:
3+
linux_interaction()
4+
except RuntimeError as error:
5+
print(error)
6+
else:
7+
try:
8+
with open("file.log") as file:
9+
read_data = file.read()
10+
except FileNotFoundError as fnf_error:
11+
print(fnf_error)
12+
finally:
13+
print("Cleaning up, irrespective of any exceptions.")

src/frontend/src/lib/Graph.svelte

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@
55
import { graphToDot } from "../../../control-flow/render";
66
import { simplifyCFG, trimFor } from "../../../control-flow/graph-ops";
77
import { Graphviz } from "@hpcc-js/wasm-graphviz";
8-
import { getFirstFunction, initializeParsers, type Parsers } from "./utils";
8+
import {
9+
getFirstFunction,
10+
initialize as initializeUtils,
11+
type Parsers,
12+
} from "./utils";
913
1014
let parsers: Parsers;
1115
let graphviz: Graphviz;
@@ -17,8 +21,9 @@
1721
export let flatSwitch: boolean = false;
1822
1923
async function initialize() {
20-
parsers = await initializeParsers();
21-
graphviz = await Graphviz.load();
24+
const utils = await initializeUtils();
25+
parsers = utils.parsers;
26+
graphviz = utils.graphviz;
2227
}
2328
2429
interface RenderOptions {

src/frontend/src/lib/TestViewer.svelte

Lines changed: 65 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,45 @@
22
import testRecordsJson from "../../../../dist/tests/commentTests.json?json";
33
import type { TestFuncRecord } from "../../../test/commentTestUtils";
44
import TestGraph from "./TestGraph.svelte";
5-
import { runTest, type TestResults } from "./utils";
5+
import {
6+
runTest,
7+
type TestResults,
8+
initialize as initializeUtils,
9+
} from "./utils";
10+
611
const testRecords = testRecordsJson as TestFuncRecord[];
712
8-
const testResults = testRecords.map((record) => {
9-
let results: TestResults[];
10-
try {
11-
results = runTest(record);
12-
} catch (error) {
13-
console.trace(
14-
`\nFailed running tests for ${record.language}: ${record.name}\n`,
15-
error,
16-
);
17-
results = [
18-
{
19-
reqName: "Tests",
20-
reqValue: "Failed to complete",
21-
failure: `${error}`,
22-
},
23-
];
24-
}
25-
return {
26-
record,
27-
failed: !results.every((result) => result.failure === null),
28-
results,
29-
};
30-
});
13+
async function runAllTests() {
14+
await initializeUtils();
15+
16+
const testResults = testRecords.map((record) => {
17+
let results: TestResults[];
18+
try {
19+
results = runTest(record);
20+
} catch (error) {
21+
console.trace(
22+
`\nFailed running tests for ${record.language}: ${record.name}\n`,
23+
error,
24+
);
25+
results = [
26+
{
27+
reqName: "Tests",
28+
reqValue: "Failed to complete",
29+
failure: `${error}`,
30+
},
31+
];
32+
}
33+
return {
34+
record,
35+
failed: !results.every((result) => result.failure === null),
36+
results,
37+
};
38+
});
3139
32-
const failCount = testResults.filter(({ failed }) => failed).length;
40+
const failCount = testResults.filter(({ failed }) => failed).length;
41+
42+
return { testResults, failCount };
43+
}
3344
3445
let simplify: boolean = true;
3546
let verbose: boolean = false;
@@ -54,35 +65,37 @@
5465
<input type="checkbox" id="showAll" bind:checked={showAll} />
5566
<label for="showAll">Show All</label>
5667
</div>
57-
<div class="content">
58-
<div class="summary" class:green={failCount === 0} class:red={failCount}>
59-
{#if failCount === 0}
60-
All tests pass.
61-
{:else}
62-
{failCount} failing test{failCount > 1 ? "s" : ""}.
63-
{/if}
64-
</div>
65-
<div class="container">
66-
{#each testResults as { record, failed, results } (record)}
67-
{#if failed || showAll}
68-
<div class="code-side" data-failed={failed}>
69-
<div class="test-name">{record.language}: {record.name}</div>
70-
<div class="code"><pre>{record.code}</pre></div>
71-
<div class="results">
72-
{#each results as { reqName, reqValue, failure } (reqName)}
73-
{#if failure !== null}
74-
<div class="result">
75-
{reqName}: {reqValue}; {failure}
76-
</div>
77-
{/if}
78-
{/each}
79-
</div>
80-
</div>
81-
<TestGraph {record} {simplify} {verbose} {trim} {flatSwitch} />
68+
{#await runAllTests() then { failCount, testResults }}
69+
<div class="content">
70+
<div class="summary" class:green={failCount === 0} class:red={failCount}>
71+
{#if failCount === 0}
72+
All tests pass.
73+
{:else}
74+
{failCount} failing test{failCount > 1 ? "s" : ""}.
8275
{/if}
83-
{/each}
76+
</div>
77+
<div class="container">
78+
{#each testResults as { record, failed, results } (record)}
79+
{#if failed || showAll}
80+
<div class="code-side" data-failed={failed}>
81+
<div class="test-name">{record.language}: {record.name}</div>
82+
<div class="code"><pre>{record.code}</pre></div>
83+
<div class="results">
84+
{#each results as { reqName, reqValue, failure } (reqName)}
85+
{#if failure !== null}
86+
<div class="result">
87+
{reqName}: {reqValue}; {failure}
88+
</div>
89+
{/if}
90+
{/each}
91+
</div>
92+
</div>
93+
<TestGraph {record} {simplify} {verbose} {trim} {flatSwitch} />
94+
{/if}
95+
{/each}
96+
</div>
8497
</div>
85-
</div>
98+
{/await}
8699

87100
<style>
88101
.content {

src/frontend/src/lib/utils.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,19 @@ export function getFirstFunction(tree: Parser.Tree): Parser.SyntaxNode | null {
7777
return functionNode;
7878
}
7979

80-
const parsers: Parsers = await initializeParsers();
81-
const graphviz: Graphviz = await Graphviz.load();
80+
let parsers: Parsers;
81+
let graphviz: Graphviz;
82+
export async function initialize() {
83+
parsers = await initializeParsers();
84+
graphviz = await Graphviz.load();
85+
return { parsers, graphviz };
86+
}
8287
export interface TestResults {
8388
reqName: string;
8489
reqValue: any;
8590
failure: string | null;
8691
}
92+
8793
export function runTest(record: TestFuncRecord): TestResults[] {
8894
const tree = parsers[record.language].parse(record.code);
8995
const testFunc: TestFunction = {

0 commit comments

Comments
 (0)