@@ -4,12 +4,20 @@ import { jsPython, Interpreter, PackageLoader } from 'jspython-interpreter';
44import { httpGet , httpPost , httpDelete , httpPut } from './http' ;
55
66const pkg = require ( '../package.json' ) ;
7-
7+ const context : any = {
8+ asserts : [ ]
9+ }
810export const interpreter : Interpreter = jsPython ( ) as Interpreter ;
911interpreter . addFunction ( 'httpGet' , httpGet ) ;
1012interpreter . addFunction ( 'httpPost' , httpPost ) ;
1113interpreter . addFunction ( 'httpDelete' , httpDelete ) ;
1214interpreter . 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+ } ) ;
1321run ( ) ;
1422
1523async 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