Skip to content

Commit

Permalink
More tests
Browse files Browse the repository at this point in the history
Signed-off-by: Martin Zeithaml <[email protected]>
  • Loading branch information
Martin-Zeithaml committed Sep 27, 2024
1 parent f09be06 commit 1fa6dd2
Show file tree
Hide file tree
Showing 7 changed files with 140 additions and 77 deletions.
16 changes: 0 additions & 16 deletions tests/quickJS/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,3 @@ Keep in mind, test the simple cases like:
* No parameters when exepecting some
* Incorrect data types
* Empty, null, undefined values...

```javascript
export function test_someFunction() {
const TEST = [ -1, 0, 1, 42 ]
let errs = 0;
for (let t in TEST) {
const result = someFunction(TEST[t]);
print.clog(result == TEST[t], `someFunction(${TEST[i]})=${result}`);
if (result != TEST[t]) {
errs++;
}
}
return { errors: errs, total: TEST.lenght }
}

```
16 changes: 14 additions & 2 deletions tests/quickJS/lib/print.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,20 @@ export function cyan(msg) {
color(CYAN, msg);
}

export function conditionally(condition, ...msg) {
console.log(`${condition ? GREEN : RED}` + msg + RESET);
export function conditionally(condition, functionTested, parm, result, additionalInfo) {
if (typeof parm == 'object') {
parm = JSON.stringify(parm);
}
if (typeof result == 'object') {
result = JSON.stringify(result);
}
if (!additionalInfo) {
additionalInfo = '';
} else {
additionalInfo = `[${additionalInfo}]`;
}
console.log(`${condition ? GREEN : RED}` + `${functionTested}("${parm}")=${result} ${additionalInfo}` + RESET);
return + !condition;
}

export function lines(clr, msg) {
Expand Down
37 changes: 37 additions & 0 deletions tests/quickJS/lib/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
// This program and the accompanying materials are made available
// under the terms of the Eclipse Public License v2.0 which
// accompanies this distribution, and is available at
// https://www.eclipse.org/legal/epl-v20.html
//
// SPDX-License-Identifier: EPL-2.0
//
// Copyright Contributors to the Zowe Project.
*/

import * as print from './print';

export const CLASSIC_FAILS = [ '', null, undefined, true, false, -16, 0, 256, 3.141592, 999999999,
['banana', 'apple', 'kiwi'],
{ success: "guaranteed" }
];

export function process(testFunction, testSet, compare, msg) {
let errors = 0;
let result;
if (typeof compare == 'object') {
compare = JSON.stringify(compare);
}
for (let t in testSet) {
if (Array.isArray(testSet[t])) {
result = testFunction(...testSet[t]);
} else {
result = testFunction(testSet[t]);
}
if (typeof result == 'object') {
result = JSON.stringify(result);
}
errors += print.conditionally(result == compare, msg, testSet[t], result);
}
return errors;
}
27 changes: 8 additions & 19 deletions tests/quickJS/quickJS.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,33 +11,22 @@

import * as std from 'cm_std';
import * as print from './lib/print';
import * as testZos from './testLib/testZos';

const TEST_ZOS = [
testZos.test_changeTag,
testZos.test_changeExtAttr,
testZos.test_changeStreamCCSID,
testZos.test_zstat,
testZos.test_getZosVersion,
testZos.test_getEsm,
testZos.test_dslist,
testZos.test_resolveSymbol,
testZos.test_getStatvfs,
]

const TESTS = [
...TEST_ZOS
]
import * as testSet from './testSet';

let result = {};
let errors = 0;
let total = 0;

for (let testFunction in TESTS) {
result = TESTS[testFunction]();
const loopStart = Date.now();
for (let testFunction in testSet.TESTS) {
result = testSet.TESTS[testFunction]();
errors += result.errors;
total += result.total;
}
const loopEnd = Date.now();

const timeDiff = loopEnd-loopStart;
print.cyan(`\nTime elapsed ${timeDiff} ms.`);

if (errors) {
print.lines(print.RED, `${errors} error${errors == 1 ? '' : 's'} detected in ${total} tests, review the test output.`);
Expand Down
1 change: 1 addition & 0 deletions tests/quickJS/testLib/hello.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
çÁ%%?Œ€Ï?Ê%ÀŽ
92 changes: 52 additions & 40 deletions tests/quickJS/testLib/testZos.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,30 @@
// Copyright Contributors to the Zowe Project.
*/

// ========================
// zowe-common-c/c/qjszos.c
// ========================

import * as zos from 'zos';
import * as print from '../lib/print';
import * as test from '../lib/test';


// int status = tagFile(pathname, ccsid);
export function test_changeTag() {
const result = zos.changeTag('./');
print.purple(`DUMMY TEST: zos.changeTag(./)=${result}`);
return { errors: 0, total: 0 }
let errs;
const FAILS = [ ...test.CLASSIC_FAILS,
'./file, which does not exit', ['./file, which does not exit', 250000 ],
]
const FINES = [
[ './testLib/hello.txt', 0 ],
[ './testLib/hello.txt', 859 ],
[ './testLib/hello.txt', 1047 ],
];

errs = test.process(zos.changeTag, FAILS, -1, 'zos.changeTag');
errs += test.process(zos.changeTag, FINES, 0, 'zos.changeTag');

return { errors: errs, total: FAILS.length + FINES.length }
}


Expand All @@ -37,17 +52,25 @@ export function test_changeStreamCCSID() {
}


// res = stat(pathNative, &st);
export function test_zstat() {
const result = zos.zstat('./testLib/testZos.js');
print.purple(`DUMMY TEST: zos.zstat(./testLib/testZos.js)=${JSON.stringify(result)}`);
return { errors: 0, total: 0 }
const FAILS = [ ...test.CLASSIC_FAILS ];
const FINES = [ './testLib/hello.txt', './', './run_test.sh' ];
let errs = 0;
for (let f in FAILS) {
const result = zos.zstat(FAILS[f]);
errs += print.conditionally(result[1] == 129, 'zos.zstat', FAILS[f], result);
}
for (let f in FINES) {
const result = zos.zstat(FINES[f]);
errs += print.conditionally(result[1] == 0, 'zos.zstat', FINES[f], result);
}
return { errors: errs, total: FAILS.length }
}


export function test_getZosVersion() {
const result = zos.getZosVersion();
print.conditionally(true, `zos.getZosVersion()=${result}${result > 0 ? `=hex(0x${result.toString(16)}` : ``})`);
print.conditionally(true, 'zos.getZosVersion', 'no parameter', result, `${result > 0 ? `in hex 0x${result.toString(16)}` : ``}`);
return { errors: result ? 0 : 1, total : 1 };
}

Expand All @@ -57,19 +80,24 @@ export function test_getEsm() {
const result = zos.getEsm();

if (result == null || !EXPECTED.includes(result)) {
print.conditionally(false, `zos.getEsms()=${result}`);
print.conditionally(false, 'zos.getEsms', 'no parameter', result);
return { errors: 1, total: 1 };
}
print.conditionally(true, `zos.getEsms()=${result}`);
print.conditionally(true, 'zos.getEsms', 'no parameter', result);
return { errors: 0, total: 1 };
}



export function test_dslist() {
const result = zos.dslist('SYS1.MACLIB');
print.purple(`DUMMY TEST: zos.zstat(SYS1.MACLIB)=${JSON.stringify(result)}`);
return { errors: 0, total: 0 }
const FAILS = [ ...test.CLASSIC_FAILS, 'sys1.maclib' ];
const FINES = [ 'SYS1.PARMLIB', 'SYS1.MACLIB' ];

let errs = test.process(zos.dslist, FAILS, null, 'zos.dslist');
for (let f in FINES) {
const result = zos.dslist(FINES[f]);
errs += print.conditionally(result.datasets[0].dsn == FINES[f], 'zos.dslist', FINES[f], result);
}
return { errors: errs, total: FAILS.length + FINES.length }
}


Expand All @@ -79,45 +107,29 @@ export function test_resolveSymbol() {
const yymmdd = (date.getFullYear() - 2000) * 10000 + (date.getMonth() + 1) * 100 + date.getDate() + '';
let errs = 0;

print.conditionally(result == yymmdd, `zos.resolveSymbol('&YYMMDD')=${result} -> ${yymmdd}`);
if (result != yymmdd) {
errs ++
}
errs += print.conditionally(result == yymmdd, 'zos.resolveSymbol', '&YYMMDD', result, `javascript date -> ${yymmdd}`);

const SYMBOLS_ERR = [ undefined, null, '', 'YYMMDD', ' &', ['a', 'b'], '& UNDEFINED SYMBOL !@#$%^&*()' ];
for (let s in SYMBOLS_ERR) {
const result = zos.resolveSymbol(SYMBOLS_ERR[s]);
print.conditionally(result.length == 0, `zos.resolveSymbol(${SYMBOLS_ERR[s]})=${result}`);
if (result.length) {
errs++
}
}
return { errors: errs, total : SYMBOLS_ERR.length + 1 };;
const ERR_SYMBOLS = [ ...test.CLASSIC_FAILS, 'YYMMDD', ' &', ['a', 'b'], '& UNDEFINED SYMBOL !@#$%^&*()' ];
errs += test.process(zos.resolveSymbol, ERR_SYMBOLS, '', 'zos.resolveSymbol');

return { errors: errs, total : ERR_SYMBOLS.length + 1 };;
}


export function test_getStatvfs() {
const PATHS_OK = [ './', '/', '/bin/' ];
const PATHS_ERR = [ '', '/aaaaaaaaaaaaaaaaaaaaaaaaaaaaa', [ 'a', 3.14 ], { path: '/dev/null' }, null, true, false, undefined, 0, -1, 800 ];
const PATHS_ERR = [ ...test.CLASSIC_FAILS, '/aaaaaaaaaaaaaaaaaaaaaaaaaaaaa/bbbbbbbbbbbbbbbbbbbbbb/ccccccccccccccccccccccc' ];
let errs = 0;

for (let p in PATHS_OK) {
const result = zos.getStatvfs(PATHS_OK[p]);
print.conditionally(result[1] == 0, `zos.getStatvfs(${PATHS_OK[p]})=${result[1]}`);
if (result[1] != 0) {
errs++;
}
if (result[0]) {
console.log(`Stats=${JSON.stringify(result[0])}`);
}
errs += print.conditionally(result[1] == 0, 'zos.getStatvfs', PATHS_OK[p], result);
}

for (let p in PATHS_ERR) {
const result = zos.getStatvfs(PATHS_ERR[p]);
print.conditionally(result[1] != 0, `zos.getStatvfs(${PATHS_ERR[p]})=${result[1]}`);
if (result[1] == 0) {
errs++;
}
errs += print.conditionally(result[1] != 0, 'zos.getStatvfs', PATHS_ERR[p], result[1]);
}

return { errors: errs, total: PATHS_ERR.length + PATHS_OK.length };
}
28 changes: 28 additions & 0 deletions tests/quickJS/testSet.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
// This program and the accompanying materials are made available
// under the terms of the Eclipse Public License v2.0 which
// accompanies this distribution, and is available at
// https://www.eclipse.org/legal/epl-v20.html
//
// SPDX-License-Identifier: EPL-2.0
//
// Copyright Contributors to the Zowe Project.
*/

import * as testZos from './testLib/testZos'

export const TEST_ZOS = [
testZos.test_changeTag,
testZos.test_changeExtAttr,
testZos.test_changeStreamCCSID,
testZos.test_zstat,
testZos.test_getZosVersion,
testZos.test_getEsm,
testZos.test_dslist,
testZos.test_resolveSymbol,
testZos.test_getStatvfs,
];

export const TESTS = [
...TEST_ZOS
];

0 comments on commit 1fa6dd2

Please sign in to comment.