Skip to content

Commit f38fd57

Browse files
author
Alan Christie
committed
- Adjusted template comments
- And minor typos and tweaks
1 parent 0be3cae commit f38fd57

File tree

2 files changed

+31
-26
lines changed

2 files changed

+31
-26
lines changed

src/groovy/PipelineTester.groovy

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ class Tester {
8787
/**
8888
* The run method.
8989
* Locates all the test files, loads them and executes them.
90-
* This is the main/public entrypoint for the class.
90+
* This is the main/public entry-point for the class.
9191
*
9292
* @return boolean, false if any test has failed.
9393
*/
@@ -203,7 +203,8 @@ class Tester {
203203
}
204204

205205
/**
206-
* cleanup the generated output.
206+
* Cleanup the generated output.
207+
*
207208
* Pipelines that create files have their files placed in the project's
208209
* `tmp` directory. This method, called at the start of testing and when
209210
* all tests have passed successfully, removed the collected files.
@@ -317,9 +318,10 @@ class Tester {
317318
if (option.defaultValue != null) {
318319
if (option.defaultValue in java.util.List) {
319320
// Assume something like '[java.lang.Float, 0.7]'
320-
// So the defau;t's the 2nd entry?
321+
// So the default's the 2nd entry?
321322
optionDefaults[arglessOption] = option.defaultValue[1]
322323
} else {
324+
// Just a string?
323325
optionDefaults[arglessOption] = option.defaultValue
324326
}
325327
}
@@ -440,7 +442,7 @@ class Tester {
440442

441443
info('Processing setup_collection section')
442444

443-
// Extract key setup values, suppling defaults
445+
// Extract key setup values, supplying defaults
444446
int timeoutSeconds = setupSection.value.get('timeout')
445447
if (timeoutSeconds != null) {
446448
info("Setup timeout=$timeoutSeconds")
@@ -517,7 +519,7 @@ class Tester {
517519
// Unless a test-specific command has been defined
518520
// check the parameters against the service descriptor
519521
// to ensure that all the options are recognised.
520-
String the_command = null
522+
String pipelineCommand
521523
if (command == null) {
522524

523525
if (!checkAllOptionsHaveBeenUsed(params_block)) {
@@ -526,7 +528,12 @@ class Tester {
526528
}
527529
// No raw command defined in the test block,
528530
// so use the command defined in the service descriptor...
529-
the_command = currentServiceDescriptor.command
531+
String the_command = currentServiceDescriptor.command
532+
533+
// Replace the respective values in the command string...
534+
pipelineCommand = expandTemplate(the_command, params_block)
535+
// Replace newlines with '\n'
536+
pipelineCommand = pipelineCommand.replace(System.lineSeparator(), '\n')
530537

531538
} else {
532539
// The user-supplied command might be a multi-line string.
@@ -535,18 +542,13 @@ class Tester {
535542
command.eachLine {
536543
the_command += it.trim() + ' '
537544
}
538-
the_command = the_command.trim()
545+
pipelineCommand = the_command.trim()
539546
}
540547

541-
// Here ... `the_command` is either the SD-defined command or the
548+
// Here ... `pipelineCommand` is either the SD-defined command or the
542549
// command defined in this test's command block.
543550

544-
// replace the respective values in the command string...
545-
String pipelineCommand = expandTemplate(the_command, params_block)
546-
// Replace newlines with '\n'
547-
pipelineCommand = pipelineCommand.replace(System.lineSeparator(), '\n')
548-
549-
// Redirect the '-o' option, if defined
551+
// Redirect the '-o' option, if there is a '-o' in the command
550552
def oOption = pipelineCommand =~ /$outputRegex/
551553
File testOutputFile = null
552554
if (oOption.count > 0) {
@@ -596,9 +598,9 @@ class Tester {
596598

597599
// If command execution was successful (exit value of 0)
598600
// then:
599-
// - check that th eoutput file was created (if expected)
601+
// - check that the output file was created (if expected)
600602
// - iterate through any optional _see_ values,
601-
// checking that the piupeline log contains the defined text.
603+
// checking that the pipeline log contains the defined text.
602604
boolean validated = true
603605
if (exitValue == 0) {
604606

src/groovy/pipeline.test.template

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,21 +60,23 @@
6060
// An optional test-specific 'raw' command.
6161
//
6262
// As an alternative to exercising the service-descriptor-supplied
63-
// command you can specify your own raw command. If you provide
64-
// a command you cannot provide parameters (see below).
63+
// command you can specify your own raw command.
64+
//
65+
// If you provide a command you **cannot** provide parameters
66+
// (see the params section below).
6567

6668
command: ```python my_own_command
6769
--my-own-param-1 32
6870
--my-own-param-2 18.5```
6971

7072
// Test parameters.
7173
//
72-
// If you are testing the service-descriptor command rather than
73-
// applying your own raw command (see above) you need to provide the
74-
// service-descriptor command wih parameters.
74+
// Unless you are testing a raw command (see above) you need to
75+
// provide the built-in service descriptor command wih parameters
76+
// and values.
7577
//
76-
// A parameter value must be defined for each service descriptor
77-
// option that does not have a default value.
78+
// A parameter value must be defined for each option that does not
79+
// have a default.
7880

7981
params: [ doses: 55,
8082
volumes: 0.42,
@@ -83,9 +85,10 @@
8385
// Log validation.
8486
//
8587
// Optional checks against the pipeline's log.
86-
// Spaces are automatically interpreted
87-
// as the regular expression '[ \s]+',
88-
// but you can also use regular expressions.
88+
// To simplify strign checks against output that contains variable
89+
// whitespace (like tabs etc.) spaces are automatically interpreted
90+
// as the regular expression '[ \t]+', absorbing any non-line-breaking
91+
// gaps. You can also use regular expressions.
8992

9093
see: [ 'Computation = 4.5673' ]
9194

0 commit comments

Comments
 (0)