-
Notifications
You must be signed in to change notification settings - Fork 651
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FIx issues with multiple positional args
Signed-off-by: Ben Sherman <[email protected]>
- Loading branch information
1 parent
e20788b
commit b5eb83b
Showing
4 changed files
with
243 additions
and
45 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
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
162 changes: 162 additions & 0 deletions
162
modules/nextflow/src/test/groovy/nextflow/cli/v2/LauncherTest.groovy
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,162 @@ | ||
/* | ||
* Copyright 2023, Seqera Labs | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package nextflow.cli.v2 | ||
|
||
import java.nio.file.Files | ||
|
||
import picocli.CommandLine | ||
import spock.lang.Specification | ||
|
||
/** | ||
* | ||
* @author Ben Sherman <[email protected]> | ||
*/ | ||
class LauncherTest extends Specification { | ||
|
||
def parseArgs(String... args) { | ||
def launcher = new Launcher() | ||
def cmd = new CommandLine(launcher) | ||
cmd.parseArgs(args) | ||
|
||
return launcher | ||
} | ||
|
||
def getCommand(Launcher launcher) { | ||
launcher.spec.commandLine().getParseResult().subcommand().commandSpec().commandLine().getCommand() | ||
} | ||
|
||
def getArgs(Launcher launcher) { | ||
launcher.spec.commandLine().getParseResult().originalArgs() | ||
} | ||
|
||
|
||
def 'should return `version` option' () { | ||
|
||
when: | ||
def launcher = parseArgs('-v') | ||
then: | ||
assert launcher.options.version | ||
|
||
when: | ||
launcher = parseArgs('--version') | ||
then: | ||
assert launcher.options.fullVersion | ||
|
||
} | ||
|
||
def 'should return `info` command'() { | ||
|
||
when: | ||
def launcher = parseArgs('info') | ||
def command = getCommand(launcher) | ||
then: | ||
command instanceof InfoCmd | ||
command.pipeline == null | ||
|
||
when: | ||
launcher = parseArgs('info', 'xxx') | ||
command = getCommand(launcher) | ||
then: | ||
command instanceof InfoCmd | ||
command.pipeline == 'xxx' | ||
|
||
} | ||
|
||
def 'should return `pull` command'() { | ||
|
||
when: | ||
def launcher = parseArgs('pull', 'alpha') | ||
def command = getCommand(launcher) | ||
then: | ||
command instanceof PullCmd | ||
command.pipeline == 'alpha' | ||
|
||
when: | ||
launcher = parseArgs('pull', 'xxx', '--hub', 'bitbucket', '--user', 'xx:11') | ||
command = getCommand(launcher) | ||
then: | ||
command instanceof PullCmd | ||
command.pipeline == 'xxx' | ||
command.hubProvider == 'bitbucket' | ||
command.hubUser == 'xx' | ||
command.hubPassword == '11' | ||
|
||
} | ||
|
||
def 'should return `clone` command'() { | ||
when: | ||
def launcher = parseArgs('clone', 'xxx', 'yyy') | ||
def command = getCommand(launcher) | ||
then: | ||
command instanceof CloneCmd | ||
command.pipeline == 'xxx' | ||
command.targetName == 'yyy' | ||
|
||
when: | ||
launcher = parseArgs('clone', 'xxx', '--hub', 'bitbucket', '--user', 'xx:yy') | ||
command = getCommand(launcher) | ||
then: | ||
command instanceof CloneCmd | ||
command.pipeline == 'xxx' | ||
command.targetName == null | ||
command.hubProvider == 'bitbucket' | ||
command.hubUser == 'xx' | ||
command.hubPassword == 'yy' | ||
} | ||
|
||
def 'should return `run` command'() { | ||
when: | ||
def launcher = parseArgs('run', 'xxx', '--hub', 'bitbucket', '--user', 'xx:yy') | ||
def command = getCommand(launcher) | ||
then: | ||
command instanceof RunCmd | ||
command.pipeline == 'xxx' | ||
command.hubProvider == 'bitbucket' | ||
command.hubUser == 'xx' | ||
command.hubPassword == 'yy' | ||
|
||
when: | ||
launcher = parseArgs('run', 'alpha', '--hub', 'github') | ||
command = getCommand(launcher) | ||
then: | ||
command instanceof RunCmd | ||
command.pipeline == 'alpha' | ||
command.hubProvider == 'github' | ||
|
||
when: | ||
launcher = parseArgs('run', 'script.nf', 'arg1', 'arg2', '--', '--alpha', '0', '--omega', '9') | ||
command = getCommand(launcher) | ||
then: | ||
command instanceof RunCmd | ||
command.pipeline == 'script.nf' | ||
command.args == ['arg1', 'arg2'] | ||
command.params.'alpha' == '0' | ||
command.params.'omega' == '9' | ||
|
||
} | ||
|
||
def 'should make cli' () { | ||
given: | ||
def launcher = new Launcher() | ||
expect: | ||
launcher.makeCli('nextflow', 'run', 'foo.nf') == 'nextflow run foo.nf' | ||
launcher.makeCli('nextflow', 'run', 'foo.nf', '*.txt') == "nextflow run foo.nf '*.txt'" | ||
launcher.makeCli('/this/that/nextflow run foo.nf', 'run', 'foo.nf', 'a{1,2}.z') == "nextflow run foo.nf 'a{1,2}.z'" | ||
launcher.makeCli('/this/that/launch run bar.nf', 'run', 'bar.nf') == '/this/that/launch run bar.nf' | ||
} | ||
|
||
} |