8000 Assert summary #187 · jspython-dev/jspython-cli@fe06fc3 · GitHub
[go: up one dir, main page]

Skip to content

Commit fe06fc3

Browse files
committed
Assert summary #187
1 parent 6ea4d18 commit fe06fc3

File tree

4 files changed

+14
-5
lines changed

4 files changed

+14
-5
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "jspython-cli",
3-
"version": "0.0.5",
3+
"version": "0.0.6",
44
"description": "CLI for jspython. Allows you to run jspython (*.jspy) files",
55
"main": "src/index.ts",
66
"bin": {

rollup.config.dev.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export default {
1414
plugins: [
1515
typescript()
1616
],
17-
external: ['arg', 'fs', 'JSPython', 'json5'],
17+
external: ['arg', 'fs', 'jspython-interpreter', 'json5', 'http', 'https'],
1818
watch: {
1919
exclude: ['node_modules/**'],
2020
include: 'src/**'

rollup.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ export default {
1616
]
1717
})
1818
],
19-
external: ['arg', 'fs', '@jspython-dev/jspython']
19+
external: ['arg', 'fs', 'jspython-interpreter', 'http', 'https']
2020
};

src/index.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,20 @@ import { jsPython, Interpreter, PackageLoader } from 'jspython-interpreter';
44
import { httpGet, httpPost, httpDelete, httpPut } from './http';
55

66
const pkg = require('../package.json');
7-
7+
const context: any = {
8+
asserts: []
9+
}
810
export const interpreter: Interpreter = jsPython() as Interpreter;
911
interpreter.addFunction('httpGet', httpGet);
1012
interpreter.addFunction('httpPost', httpPost);
1113
interpreter.addFunction('httpDelete', httpDelete);
1214
interpreter.addFunction('httpPut', httpPut);
15+
interpreter.addFunction('assert', (condition: boolean, name?: string, description?: string) => {
16+
context.asserts.push({ condition, name, description });
17+
});
18+
interpreter.addFunction('showAsserts', (condition: boolean, name?: string, description?: string) => {
19+
console.table(context.asserts);
20+
});
1321
run();
1422

1523
async function run() {
@@ -21,7 +29,8 @@ async function run() {
2129
if (options.file) {
2230
interpreter.registerPackagesLoader(packageLoader as PackageLoader);
2331
const scripts = fs.readFileSync(options.file, 'utf8');
24-
const res = await interpreter.evaluate(scripts);
32+
context.asserts.length = 0;
33+
const res = await interpreter.evaluate(scripts, context);
2534
console.log('Execution result:\n', res);
2635
console.log('Finish');
2736
}

0 commit comments

Comments
 (0)
0