David T. Lewis uploaded a new version of Tests to project The Trunk:
http://source.squeak.org/trunk/Tests-dtl.443.mcz ==================== Summary ==================== Name: Tests-dtl.443 Author: dtl Time: 8 December 2020, 4:12:09.524558 pm UUID: 7c308020-16a4-4b76-83c9-5bc4ba13fd98 Ancestors: Tests-mt.442 Add DoItFirstTest to verify command line parsing for DoitFirst and confirm mapping of command line tokens to known options. =============== Diff against Tests-mt.442 =============== Item was added: + TestCase subclass: #DoItFirstTest + instanceVariableNames: '' + classVariableNames: '' + poolDictionaries: '' + category: 'Tests-System-Support'! + + !DoItFirstTest commentStamp: 'dtl 12/6/2020 20:02' prior: 0! + A DoItFirstTest verifies command line parsing for DoitFirst to confirm mapping of command line tokens to known options. + ! Item was added: + ----- Method: DoItFirstTest>>testEvaluateFileContents (in category 'tests') ----- + testEvaluateFileContents + | doItFirst actionBlocks action blockArg | + doItFirst := DoItFirst new. + { + { '--' . 'foo' . 'bar' . '--file' . 'arg1' . 'arg2' . 'arg3' } . + { '--' . 'foo' . 'bar' . '-file' . 'arg1' . 'arg2' . 'arg3' } . + { '--' . 'foo' . 'bar' . '-f' . 'arg1' . 'arg2' . 'arg3' } . + { 'foo' . 'bar' . '--file' . 'arg1' . 'arg2' . 'arg3' } . + { 'foo' . 'bar' . '-file' . 'arg1' . 'arg2' . 'arg3' } . + { 'foo' . 'bar' . '-f' . 'arg1' . 'arg2' . 'arg3' } + } do: [ :args | + actionBlocks := doItFirst parse: args. + self assert: 1 equals: actionBlocks size. + action := actionBlocks first. + self assert: action equals: (doItFirst actions at: #file). + self assert: 0 equals: action numArgs. + self assert: 1 equals: action numTemps. + blockArg := (action at: 1) first. + self assert: 'arg1' equals: blockArg. + ]. + ! Item was added: + ----- Method: DoItFirstTest>>testEvaluateOption (in category 'tests') ----- + testEvaluateOption + | doItFirst actionBlocks action blockArg | + doItFirst := DoItFirst new. + { + { '--' . 'foo' . 'bar' . '--evaluate' . 'arg1' . 'arg2' . 'arg3' } . + { '--' . 'foo' . 'bar' . '-evaluate' . 'arg1' . 'arg2' . 'arg3' } . + { '--' . 'foo' . 'bar' . '-e' . 'arg1' . 'arg2' . 'arg3' } . + { 'foo' . 'bar' . '--evaluate' . 'arg1' . 'arg2' . 'arg3' } . + { 'foo' . 'bar' . '-evaluate' . 'arg1' . 'arg2' . 'arg3' } . + { 'foo' . 'bar' . '-e' . 'arg1' . 'arg2' . 'arg3' } + } do: [ :args | + actionBlocks := doItFirst parse: args. + self assert: 1 equals: actionBlocks size. + action := actionBlocks first. + self assert: action equals: (doItFirst actions at: #evaluate). + self assert: 0 equals: action numArgs. + self assert: 1 equals: action numTemps. + blockArg := (action at: 1) first. + self assert: 'arg1' equals: blockArg. + ]. + ! Item was added: + ----- Method: DoItFirstTest>>testParseCwd (in category 'tests') ----- + testParseCwd + | doItFirst actionBlocks action blockArg | + doItFirst := DoItFirst new. + { + { '--' . 'foo' . 'bar' . '--cwd' . 'arg1' . 'arg2' . 'arg3' } . + { '--' . 'foo' . 'bar' . '-cwd' . 'arg1' . 'arg2' . 'arg3' } . + { '--' . 'foo' . 'bar' . '-c' . 'arg1' . 'arg2' . 'arg3' } . + { 'foo' . 'bar' . '--cwd' . 'arg1' . 'arg2' . 'arg3' } . + { 'foo' . 'bar' . '-cwd' . 'arg1' . 'arg2' . 'arg3' } . + { 'foo' . 'bar' . '-c' . 'arg1' . 'arg2' . 'arg3' } + } do: [ :args | + actionBlocks := doItFirst parse: args. + self assert: 1 equals: actionBlocks size. + action := actionBlocks first. + self assert: action equals: (doItFirst actions at: #cwd). + self assert: 0 equals: action numArgs. + self assert: 1 equals: action numTemps. + blockArg := (action at: 1) first. + self assert: 'arg1' equals: blockArg. + ]. + ! Item was added: + ----- Method: DoItFirstTest>>testParseDebug (in category 'tests') ----- + testParseDebug + "Debug is a deferred action, registered in the actions but not added + to the list of actions to be immediately evaluated" + | doItFirst actionBlocks deferredAction | + doItFirst := DoItFirst new. + { + { '--' . 'foo' . 'bar' . '--debug' . 'arg1' . 'arg2' . 'arg3' } . + { '--' . 'foo' . 'bar' . '-debug' . 'arg1' . 'arg2' . 'arg3' } . + { 'foo' . 'bar' . '--debug' . 'arg1' . 'arg2' . 'arg3' } . + { 'foo' . 'bar' . '-debug' . 'arg1' . 'arg2' . 'arg3' } . + } do: [ :args | + actionBlocks := doItFirst parse: args. + self assert: 0 equals: actionBlocks size. "deferred action" + deferredAction := doItFirst actions at: #debug. + self assert: 0 equals: deferredAction numArgs. + self assert: 0 equals: deferredAction numTemps + ]. + ! Item was added: + ----- Method: DoItFirstTest>>testParseDoit (in category 'tests') ----- + testParseDoit + | doItFirst actionBlocks action blockArg | + doItFirst := DoItFirst new. + { + { '--' . 'foo' . 'bar' . '--doit' . 'arg1' . 'arg2' . 'arg3' } . + { '--' . 'foo' . 'bar' . '-doit' . 'arg1' . 'arg2' . 'arg3' } . + { '--' . 'foo' . 'bar' . '-d' . 'arg1' . 'arg2' . 'arg3' } . + { 'foo' . 'bar' . '--doit' . 'arg1' . 'arg2' . 'arg3' } . + { 'foo' . 'bar' . '-doit' . 'arg1' . 'arg2' . 'arg3' } . + { 'foo' . 'bar' . '-d' . 'arg1' . 'arg2' . 'arg3' } + } do: [ :args | + actionBlocks := doItFirst parse: args. + self assert: 1 equals: actionBlocks size. + action := actionBlocks first. + self assert: action equals: (doItFirst actions at: #doit). + self assert: 0 equals: action numArgs. + self assert: 1 equals: action numTemps. + blockArg := (action at: 1) first. + self assert: 3 equals: blockArg size. + self assert: 'arg1' equals: blockArg first. + self assert: 'arg2' equals: blockArg second. + self assert: 'arg3' equals: blockArg third. + ]. + ! Item was added: + ----- Method: DoItFirstTest>>testParseDoitArgsListWithFileArg (in category 'tests') ----- + testParseDoitArgsListWithFileArg + | doItFirst actionBlocks action blockArg | + doItFirst := DoItFirst new. + { + { '--' . 'foo' . 'bar' . '--doit' . 'arg1' . 'arg2' . 'arg3' . '-f' . 'arg4'} . + { '--' . 'foo' . 'bar' . '-doit' . 'arg1' . 'arg2' . 'arg3' . '-f' . 'arg4'} . + { '--' . 'foo' . 'bar' . '-d' . 'arg1' . 'arg2' . 'arg3' . '-f' . 'arg4'} . + { 'foo' . 'bar' . '--doit' . 'arg1' . 'arg2' . 'arg3' . '-f' . 'arg4'} . + { 'foo' . 'bar' . '-doit' . 'arg1' . 'arg2' . 'arg3' . '-f' . 'arg4'} . + { 'foo' . 'bar' . '-d' . 'arg1' . 'arg2' . 'arg3' . '-f' . 'arg4'} + } do: [ :args | + actionBlocks := doItFirst parse: args. + self assert: 2 equals: actionBlocks size. + action := actionBlocks first. + self assert: action equals: (doItFirst actions at: #doit). + self assert: 0 equals: action numArgs. + self assert: 1 equals: action numTemps. + blockArg := (action at: 1) first. + self assert: 3 equals: blockArg size. + self assert: 'arg1' equals: blockArg first. + self assert: 'arg2' equals: blockArg second. + self assert: 'arg3' equals: blockArg third. + ]. + + ! Item was added: + ----- Method: DoItFirstTest>>testParseDoitArgsListWithHelpArg (in category 'tests') ----- + testParseDoitArgsListWithHelpArg + | doItFirst actionBlocks action blockArg | + doItFirst := DoItFirst new. + { + { '--' . 'foo' . 'bar' . '--doit' . 'arg1' . 'arg2' . 'arg3' . '-help' . 'arg4'} . + { '--' . 'foo' . 'bar' . '-doit' . 'arg1' . 'arg2' . 'arg3' . '-help' . 'arg4'} . + { '--' . 'foo' . 'bar' . '-d' . 'arg1' . 'arg2' . 'arg3' . '-help' . 'arg4'} . + { 'foo' . 'bar' . '--doit' . 'arg1' . 'arg2' . 'arg3' . '-help' . 'arg4'} . + { 'foo' . 'bar' . '-doit' . 'arg1' . 'arg2' . 'arg3' . '-help' . 'arg4'} . + { 'foo' . 'bar' . '-d' . 'arg1' . 'arg2' . 'arg3' . '-help' . 'arg4'} + } do: [ :args | + actionBlocks := doItFirst parse: args. + self assert: 2 equals: actionBlocks size. + action := actionBlocks second. + self assert: action equals: (doItFirst actions at: #doit). + self assert: 0 equals: action numArgs. + self assert: 1 equals: action numTemps. + blockArg := (action at: 1) first. + self assert: 3 equals: blockArg size. + self assert: 'arg1' equals: blockArg first. + self assert: 'arg2' equals: blockArg second. + self assert: 'arg3' equals: blockArg third. + ]. + ! Item was added: + ----- Method: DoItFirstTest>>testParseFIleinArgsListWithHelpArg (in category 'tests') ----- + testParseFIleinArgsListWithHelpArg + | doItFirst actionBlocks action blockArg | + doItFirst := DoItFirst new. + { + { '--' . 'foo' . 'bar' . '--filein' . 'arg1' . 'arg2' . 'arg3' . '-help' . 'arg4'} . + { '--' . 'foo' . 'bar' . '-filein' . 'arg1' . 'arg2' . 'arg3' . '-help' . 'arg4'} . + { 'foo' . 'bar' . '--filein' . 'arg1' . 'arg2' . 'arg3' . '-help' . 'arg4'} . + { 'foo' . 'bar' . '-filein' . 'arg1' . 'arg2' . 'arg3' . '-help' . 'arg4'} . + } do: [ :args | + actionBlocks := doItFirst parse: args. + self assert: 2 equals: actionBlocks size. + action := actionBlocks second. + self assert: action equals: (doItFirst actions at: #filein). + self assert: 0 equals: action numArgs. + self assert: 1 equals: action numTemps. + blockArg := (action at: 1) first. + self assert: 3 equals: blockArg size. + self assert: 'arg1' equals: blockArg first. + self assert: 'arg2' equals: blockArg second. + self assert: 'arg3' equals: blockArg third. + ]. + ! Item was added: + ----- Method: DoItFirstTest>>testParseFilein (in category 'tests') ----- + testParseFilein + | doItFirst actionBlocks action blockArg | + doItFirst := DoItFirst new. + { + { '--' . 'foo' . 'bar' . '--filein' . 'arg1' . 'arg2' . 'arg3' } . + { '--' . 'foo' . 'bar' . '-filein' . 'arg1' . 'arg2' . 'arg3' } . + { 'foo' . 'bar' . '--filein' . 'arg1' . 'arg2' . 'arg3' } . + { 'foo' . 'bar' . '-filein' . 'arg1' . 'arg2' . 'arg3' } . + } do: [ :args | + actionBlocks := doItFirst parse: args. + self assert: 1 equals: actionBlocks size. + action := actionBlocks first. + self assert: action equals: (doItFirst actions at: #filein). + self assert: 0 equals: action numArgs. + self assert: 1 equals: action numTemps. + blockArg := (action at: 1) first. + self assert: 3 equals: blockArg size. + self assert: 'arg1' equals: blockArg first. + self assert: 'arg2' equals: blockArg second. + self assert: 'arg3' equals: blockArg third. + ]. + ! Item was added: + ----- Method: DoItFirstTest>>testParseFileinArgsListWithFileArg (in category 'tests') ----- + testParseFileinArgsListWithFileArg + | doItFirst actionBlocks action blockArg | + doItFirst := DoItFirst new. + { + { '--' . 'foo' . 'bar' . '--filein' . 'arg1' . 'arg2' . 'arg3' . '-f' . 'arg4'} . + { '--' . 'foo' . 'bar' . '-filein' . 'arg1' . 'arg2' . 'arg3' . '-f' . 'arg4'} . + { 'foo' . 'bar' . '--filein' . 'arg1' . 'arg2' . 'arg3' . '-f' . 'arg4'} . + { 'foo' . 'bar' . '-filein' . 'arg1' . 'arg2' . 'arg3' . '-f' . 'arg4'} . + } do: [ :args | + actionBlocks := doItFirst parse: args. + self assert: 2 equals: actionBlocks size. + action := actionBlocks first. + self assert: action equals: (doItFirst actions at: #filein). + self assert: 0 equals: action numArgs. + self assert: 1 equals: action numTemps. + blockArg := (action at: 1) first. + self assert: 3 equals: blockArg size. + self assert: 'arg1' equals: blockArg first. + self assert: 'arg2' equals: blockArg second. + self assert: 'arg3' equals: blockArg third. + ]. + + ! Item was added: + ----- Method: DoItFirstTest>>testParseHelp (in category 'tests') ----- + testParseHelp + | doItFirst actionBlocks action | + doItFirst := DoItFirst new. + { + { '--' . 'foo' . 'bar' . '--help' . 'arg1' . 'arg2' . 'arg3' } . + { '--' . 'foo' . 'bar' . '-help' . 'arg1' . 'arg2' . 'arg3' } . + { '--' . 'foo' . 'bar' . '-h' . 'arg1' . 'arg2' . 'arg3' } . + { 'foo' . 'bar' . '--help' . 'arg1' . 'arg2' . 'arg3' } . + { 'foo' . 'bar' . '-help' . 'arg1' . 'arg2' . 'arg3' } . + { 'foo' . 'bar' . '-h' . 'arg1' . 'arg2' . 'arg3' } + } do: [ :args | + actionBlocks := doItFirst parse: args. + self assert: 1 equals: actionBlocks size. + action := actionBlocks first. + self assert: action equals: (doItFirst actions at: #help). + self assert: 0 equals: action numArgs. + self assert: 0 equals: action numTemps + ]. + ! |
Free forum by Nabble | Edit this page |