moving to new argv parser in test.js (not done yet)...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2020-06-29 01:14:21 +03:00
parent e6014f3c98
commit 2b4f6a6514
2 changed files with 88 additions and 101 deletions

View File

@ -26,8 +26,8 @@
}, },
"homepage": "https://github.com/flynx/object.js#readme", "homepage": "https://github.com/flynx/object.js#readme",
"devDependencies": { "devDependencies": {
"colors": "^1.4.0",
"c8": "*", "c8": "*",
"ig-argv": "*" "colors": "^1.4.0",
"ig-argv": "^2.0.0"
} }
} }

63
test.js
View File

@ -67,11 +67,6 @@ module.VERBOSE = process ?
//--------------------------------------------------------------------- //---------------------------------------------------------------------
// helpers... // helpers...
Object.defineProperty(String.prototype, 'raw', {
get: function(){
return this.replace(/\x1b\[..?m/g, '') }, })
// compare two arrays by items... // compare two arrays by items...
var arrayCmp = function(a, b){ var arrayCmp = function(a, b){
var ka = Object.keys(a) var ka = Object.keys(a)
@ -178,6 +173,9 @@ module.setups = {
assert(object.parentProperty(C.prototype, 'prop').get() == 'A.prop', assert(object.parentProperty(C.prototype, 'prop').get() == 'A.prop',
'get parent property') 'get parent property')
assert(object.parentProperty(C.prototype, 'does-not-exist') === undefined,
'get non-existent property')
return 'C' return 'C'
}, },
}), `inherit (gen3)`), }), `inherit (gen3)`),
@ -894,15 +892,16 @@ function(chain, stats){
if(typeof(__filename) != 'undefined' if(typeof(__filename) != 'undefined'
&& __filename == (require.main || {}).filename){ && __filename == (require.main || {}).filename){
var stats = {}
// parse args... // parse args...
var chains = argv.Parser({
argv.ArgvParser({
// doc... // doc...
__usage__: `$scriptname [OPTIONS] [CHAIN] ...`, usage: `$SCRIPTNAME [OPTIONS] [CHAIN] ...`,
__doc__: object.normalizeTextIndent( doc: object.normalizeTextIndent(
`Run tests on object.js module. `Run tests on object.js module.
Tests run by $scriptname can be specified in one of the Tests run by $SCRIPTNAME can be specified in one of the
following formats: following formats:
<case> <case>
@ -912,28 +911,29 @@ if(typeof(__filename) != 'undefined'
Each of the items in the test spec can be a "*" indicating Each of the items in the test spec can be a "*" indicating
that all relevant items should be used, for example: that all relevant items should be used, for example:
${ '$ ./$scriptname basic:*:*' } ${ '$ ./$SCRIPTNAME basic:*:*' }
Here $scriptname is instructed to run all tests and modifiers Here $SCRIPTNAME is instructed to run all tests and modifiers
only on the basic setup. only on the basic setup.
Zero or more sets of tests can be specified. Zero or more sets of tests can be specified.
When no tests specified $scriptname will run all tests. When no tests specified $SCRIPTNAME will run all tests.
`), `),
__examples__: [ examples: [
['$ ./$scriptname', ['$ ./$SCRIPTNAME',
'run all tests.'.gray], 'run all tests.'.gray],
['$ ./$scriptname basic:*:*', ['$ ./$SCRIPTNAME basic:*:*',
'run all tests and modifiers on "basic" setup.'.gray, 'run all tests and modifiers on "basic" setup.'.gray,
'(see $scriptname -l for more info)'.gray], '(see $SCRIPTNAME -l for more info)'.gray],
['$ ./$scriptname -v example', ['$ ./$SCRIPTNAME -v example',
'run "example" test in verbose mode.'.gray], 'run "example" test in verbose mode.'.gray],
['$ ./$scriptname native:gen3:methods init:gen3:methods', ['$ ./$SCRIPTNAME native:gen3:methods init:gen3:methods',
'run two tests/patterns.'.gray], 'run two tests/patterns.'.gray],
['$ export VERBOSE=1 && ./$scriptname', ['$ export VERBOSE=1 && ./$SCRIPTNAME',
'set verbose mode globally and run tests.'.gray], 'set verbose mode globally and run tests.'.gray],
], ],
// options... // options...
'-l': '-list', '-l': '-list',
'-list': { '-list': {
@ -961,30 +961,15 @@ if(typeof(__filename) != 'undefined'
Standalone test cases: Standalone test cases:
${ Object.keys(cases).join('\n\ ${ Object.keys(cases).join('\n\
') } ') }
`), this.scriptname) `), this.scriptName)
process.exit() }}, process.exit() }},
'-v': '-verbose',
'-verbose': { '-verbose': {
doc: 'verbose mode (defaults to: $VERBOSE).', doc: 'verbose mode (defaults to: $VERBOSE).',
handler: function(){ handler: function(){
module.VERBOSE = true }}, module.VERBOSE = true }},
})
// XXX commands... .then(function(chains){
'-foo': 'moo',
'moo': 'moue',
'moue': Object.assign(
function(){
console.log('MOO!!!!!!')
process.exit() },
{
doc: 'test command...'
}),
// XXX need to make this nestable...
'nested': argv.ArgvParser({ }),
})(process.argv)
// run the tests... // run the tests...
var stats = {}
chains.length > 0 ? chains.length > 0 ?
chains chains
.forEach(function(chain){ .forEach(function(chain){
@ -999,6 +984,8 @@ if(typeof(__filename) != 'undefined'
// report error status to the OS... // report error status to the OS...
process.exit(stats.failures) process.exit(stats.failures)
})
(process.argv)
} }