-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #479 from LaurineDargaud/clap-bookTester-generateT…
…ests Clap pillar generateTests
- Loading branch information
Showing
3 changed files
with
96 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,50 @@ | ||
Class { | ||
#name : #PRCreateTestsDocument, | ||
#superclass : #PRAbstractOutputDocument, | ||
#category : 'Pillar-BookTester-CommandLine' | ||
#category : #'Pillar-BookTester-CommandLine' | ||
} | ||
|
||
{ #category : #writing } | ||
PRCreateTestsDocument >> basicWriter [ | ||
" No basicWriter : do nothing" | ||
] | ||
|
||
{ #category : #accessing } | ||
PRCreateTestsDocument >> buildOn: aPRProject [ | ||
|
||
| parsedDocument transformedDocument testGen | | ||
| parsedDocument transformedDocument | | ||
parsedDocument := self parseInputFile: file. | ||
transformedDocument := self transformDocument: parsedDocument. | ||
^ self writeDocument: transformedDocument. | ||
] | ||
|
||
{ #category : #accessing } | ||
PRCreateTestsDocument >> extension [ | ||
^ 'txt' | ||
] | ||
|
||
{ #category : #accessing } | ||
PRCreateTestsDocument >> writeDocument: aDocument [ | ||
| testGen testReport outputFile | | ||
testGen := PRBookTestGenerator new. | ||
testGen fileName: (testGen prettyRename: file file). | ||
testGen createClassFrom: testGen fileName. | ||
parsedDocument := self parseInputFile: file. | ||
transformedDocument := self transformDocument: parsedDocument. | ||
testGen start: transformedDocument. | ||
Stdio stdout crlf; crlf; | ||
nextPutAll: file fullName;crlf; | ||
nextPutAll: 'Tests created under the package ''Pillar-BookTesterResults'' with the name of the file'; crlf. | ||
|
||
testGen start: aDocument. | ||
|
||
testReport := String streamContents: | ||
[ :s | | ||
s crlf. | ||
s crlf. | ||
s << file fullName; crlf. | ||
s << 'Tests created under the package ''Pillar-BookTesterResults'' with the name of the file'; crlf. | ||
]. | ||
|
||
outputFile := (self outputDirectory resolve: (file file asAbsolute relativeTo: project baseDirectory asAbsolute)) withoutExtension , self extension. | ||
outputFile ensureDelete. | ||
outputFile parent ensureCreateDirectory. | ||
outputFile writeStreamDo: [ :stream | stream nextPutAll: testReport contents]. | ||
|
||
testGen allTestResults do: [:each | testGen finalStatus: (testGen finalStatus and: each status) ]. | ||
^ PRStatus withStatus: testGen finalStatus | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
Class { | ||
#name : #ClapPillarGenerateTestsCommand, | ||
#superclass : #ClapPillarCommand, | ||
#category : #'Pillar-Cli-Clap' | ||
} | ||
|
||
{ #category : #accessing } | ||
ClapPillarGenerateTestsCommand class >> commandName [ | ||
^ 'generateTests' | ||
] | ||
|
||
{ #category : #'command line' } | ||
ClapPillarGenerateTestsCommand class >> commandSpecification [ | ||
<commandline> | ||
| target | | ||
target := PRCreateTestsTarget new. | ||
^ (ClapCommand id: self commandName asSymbol) | ||
description: 'Generate tests from examples in the codeblocks of Pillar file(s)'; | ||
add: ClapFlag forHelp; | ||
add: ((ClapPositional id: #requestedFiles ) | ||
description: 'Pillar document(s) used to generate tests'; | ||
implicitMeaning: [ '' ]); | ||
meaning: | ||
[ :args | | ||
args at: #helpFlag ifPresent: [ :help | help value; exitSuccess ]. | ||
(args at: #requestedFiles ) isExplicit | ||
ifTrue:[ | ||
target buildStrategy: (PRBuildListStrategy list: (args occurrencesOf: #requestedFiles collect: #value) ) | ||
] | ||
ifFalse: [ | ||
target buildStrategy: (PRBuildAllStrategy new) | ||
]. | ||
target buildOn: self new project. | ||
] | ||
] |