From a2664b5dd8681504b4b7b740920069c042ee1dab Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Fri, 14 Aug 2020 15:38:29 +0300 Subject: [PATCH] reworked part of the arg handling... Signed-off-by: Alex A. Naanou --- package.json | 4 ++-- test-test.js | 6 ------ test.js | 38 +++++++++++++++++++++++++++----------- 3 files changed, 29 insertions(+), 19 deletions(-) diff --git a/package.json b/package.json index eba505d..29993bb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ig-test", - "version": "1.1.0", + "version": "1.2.0", "description": "experimental test runner....", "main": "test.js", "scripts": { @@ -23,7 +23,7 @@ "dependencies": { "colors": "^1.4.0", "glob": "^7.1.6", - "ig-argv": "^2.12.0", + "ig-argv": "^2.13.0", "ig-object": "^5.2.2" } } diff --git a/test-test.js b/test-test.js index a94bea6..c068f86 100644 --- a/test-test.js +++ b/test-test.js @@ -36,12 +36,6 @@ tests.Test('dummy', 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) - - //--------------------------------------------------------------------- diff --git a/test.js b/test.js index 109e47e..1d32efe 100644 --- a/test.js +++ b/test.js @@ -420,11 +420,21 @@ argv.Parser({ ], - // options... + default_files: undefined, + '-l': '-list', '-list': { - doc: 'list available tests.', - handler: function(){ + doc: ['list available tests.', + '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){ return object.parentOf(Merged, s) ? s.keys() @@ -441,11 +451,15 @@ argv.Parser({ ') } Modifiers: - ${ keys(this.modifiers).join('\n\ + ${ keys(this.modifiers) + .filter(function(e){ return e != '-' }) + .join('\n\ ') } Tests: - ${ keys(this.tests).join('\n\ + ${ keys(this.tests) + .filter(function(e){ return e != '-' }) + .join('\n\ ') } Standalone test cases: @@ -455,18 +469,17 @@ argv.Parser({ process.exit() }}, - default_files: undefined, + test_modules: undefined, + // XXX revise error handling... '-f': '-test-file', '-test-file': { doc: ['test script or filename patter, supports glob.', 'this flag can be given multiple times for', 'multiple paths/patterns'], arg: 'PATH', - default: function(){ return this.default_files }, - handler: function(args, key, path){ var that = this this.test_modules = this.test_modules || {} @@ -482,9 +495,12 @@ argv.Parser({ // load the modules... .forEach(function(path){ // only load .js files... - /.*\.js$/.test(path) - && (that.test_modules[path] = - require('./' + path.slice(0, -3))) }) }) }}, + if(!/.*\.js$/.test(path)){ + throw argv.ParserError( + `${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': {