reworked part of the arg handling...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2020-08-14 15:38:29 +03:00
parent 9b48c797c9
commit a2664b5dd8
3 changed files with 29 additions and 19 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "ig-test", "name": "ig-test",
"version": "1.1.0", "version": "1.2.0",
"description": "experimental test runner....", "description": "experimental test runner....",
"main": "test.js", "main": "test.js",
"scripts": { "scripts": {
@ -23,7 +23,7 @@
"dependencies": { "dependencies": {
"colors": "^1.4.0", "colors": "^1.4.0",
"glob": "^7.1.6", "glob": "^7.1.6",
"ig-argv": "^2.12.0", "ig-argv": "^2.13.0",
"ig-object": "^5.2.2" "ig-object": "^5.2.2"
} }
} }

View File

@ -36,12 +36,6 @@ tests.Test('dummy',
assert(true, 'dummy: assert') assert(true, 'dummy: assert')
}) })
console.log('>>>>', tests.Tests.members)
console.log('>>>>', tests.Tests.keys())
// XXX this does not call the Merged.length for some reason...
console.log('>>>>', tests.Tests.size)
//--------------------------------------------------------------------- //---------------------------------------------------------------------

38
test.js
View File

@ -420,11 +420,21 @@ argv.Parser({
], ],
// options... default_files: undefined,
'-l': '-list', '-l': '-list',
'-list': { '-list': {
doc: 'list available tests.', doc: ['list available tests.',
handler: function(){ 'note that if passing files via -f explicitly they',
'must precede the -list flag.'],
arg: 'PATH',
handler: function(args, key, path){
path = path || this.default_files
// load path or the defaults if nothing loaded...
;(path != this.default_files
|| this.test_modules == null)
&& this.handle('-f', [], key, path)
// get key value...
var keys = function(s){ var keys = function(s){
return object.parentOf(Merged, s) ? return object.parentOf(Merged, s) ?
s.keys() s.keys()
@ -441,11 +451,15 @@ argv.Parser({
') } ') }
Modifiers: Modifiers:
${ keys(this.modifiers).join('\n\ ${ keys(this.modifiers)
.filter(function(e){ return e != '-' })
.join('\n\
') } ') }
Tests: Tests:
${ keys(this.tests).join('\n\ ${ keys(this.tests)
.filter(function(e){ return e != '-' })
.join('\n\
') } ') }
Standalone test cases: Standalone test cases:
@ -455,18 +469,17 @@ argv.Parser({
process.exit() }}, process.exit() }},
default_files: undefined, test_modules: undefined,
// XXX revise error handling...
'-f': '-test-file', '-f': '-test-file',
'-test-file': { '-test-file': {
doc: ['test script or filename patter, supports glob.', doc: ['test script or filename patter, supports glob.',
'this flag can be given multiple times for', 'this flag can be given multiple times for',
'multiple paths/patterns'], 'multiple paths/patterns'],
arg: 'PATH', arg: 'PATH',
default: function(){ default: function(){
return this.default_files }, return this.default_files },
handler: function(args, key, path){ handler: function(args, key, path){
var that = this var that = this
this.test_modules = this.test_modules || {} this.test_modules = this.test_modules || {}
@ -482,9 +495,12 @@ argv.Parser({
// load the modules... // load the modules...
.forEach(function(path){ .forEach(function(path){
// only load .js files... // only load .js files...
/.*\.js$/.test(path) if(!/.*\.js$/.test(path)){
&& (that.test_modules[path] = throw argv.ParserError(
require('./' + path.slice(0, -3))) }) }) }}, `${key}: only support .js modules, got: "${path}"`) }
// XXX should we handle the load error here???
that.test_modules[path] =
require('./' + path.slice(0, -3)) }) }) }},
'-verbose': { '-verbose': {