Skip to content

Commit

Permalink
Merge pull request #479 from LaurineDargaud/clap-bookTester-generateT…
Browse files Browse the repository at this point in the history
…ests

Clap pillar generateTests
  • Loading branch information
Ducasse authored May 26, 2020
2 parents 9f6ae72 + d554d98 commit 35667f2
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 11 deletions.
44 changes: 36 additions & 8 deletions src/Pillar-BookTester/PRCreateTestsDocument.class.st
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
]
28 changes: 25 additions & 3 deletions src/Pillar-BookTester/PRCreateTestsTarget.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Looks like a little hack to be able to pass extra parameters during the document
Class {
#name : #PRCreateTestsTarget,
#superclass : #PRTarget,
#category : 'Pillar-BookTester-CommandLine'
#category : #'Pillar-BookTester-CommandLine'
}

{ #category : #accessing }
Expand All @@ -14,16 +14,38 @@ PRCreateTestsTarget class >> builderName [
]

{ #category : #building }
PRCreateTestsTarget >> documentFor: aFile [
PRCreateTestsTarget >> buildOn: aProject [
| status |
status := PRSuccess new.

"We chech each file"
(self filesToBuildOn: aProject) do: [ :each |
status := status and: ((self documentFor: each) buildOn: aProject) ].

^ status
]

{ #category : #building }
PRCreateTestsTarget >> documentFor: aFile [
^ PRCreateTestsDocument new
project: aFile project;
file: aFile;
target: self;
outputDirectory: (aFile project baseDirectory / self outputDirectoryName ) ensureCreateDirectory;
yourself
]

{ #category : #building }
{ #category : #accessing }
PRCreateTestsTarget >> extension [
^ 'txt'
]

{ #category : #accessing }
PRCreateTestsTarget >> outputDirectoryName [
^ '_tests-generation'
]

{ #category : #accessing }
PRCreateTestsTarget >> prepareForExecutionOn: aPRProject [

"Do nothing"
Expand Down
35 changes: 35 additions & 0 deletions src/Pillar-Cli/ClapPillarGenerateTestsCommand.class.st
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.
]
]

0 comments on commit 35667f2

Please sign in to comment.