Skip to content

Commit

Permalink
More tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
danfuzz committed Oct 4, 2023
1 parent 774a0dd commit 488cfa1
Show file tree
Hide file tree
Showing 12 changed files with 448 additions and 0 deletions.
95 changes: 95 additions & 0 deletions tests/03-arg-processor/002-one-required-positional/expect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
## no args or options passed

### stderr
```
the-cmd: Missing required argument <zongo>.
the-cmd -- test command
```

### exit: 1

- - - - - - - - - -

## passed `--`

### stderr
```
the-cmd: Missing required argument <zongo>.
the-cmd -- test command
```

### exit: 1

- - - - - - - - - -

## passed positional arg

### stdout
```
Value: i-am-arguing
```

### exit: 0

- - - - - - - - - -

## passed two positional args

### stderr
```
the-cmd: Too many positional arguments.
the-cmd -- test command
```

### exit: 1

- - - - - - - - - -

## passed `--` then positional arg

### stdout
```
Value: MORE_ARGUING
```

### exit: 0

- - - - - - - - - -

## passed `--` then arg that looks like an option

### stdout
```
Value: --non-option
```

### exit: 0

- - - - - - - - - -

## passed a double-dash option

### stderr
```
the-cmd: Unknown option: --x
the-cmd -- test command
```

### exit: 1

- - - - - - - - - -

## passed a double-dash option then a positional arg

### stderr
```
the-cmd: Unknown option: --x
the-cmd -- test command
```

### exit: 1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Test of a single required positional argument.
31 changes: 31 additions & 0 deletions tests/03-arg-processor/002-one-required-positional/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash
# Copyright 2022-2023 the Bashy-lib Authors (Dan Bornstein et alia).
# SPDX-License-Identifier: Apache-2.0

. "$(dirname "$(readlink -f "$0")")/../../_test-init.sh" || exit "$?"

cmd="$(this-cmd-dir)/the-cmd"

call-and-log-as-test 'no args or options passed' \
"${cmd}"

call-and-log-as-test 'passed `--`' \
"${cmd}" --

call-and-log-as-test 'passed positional arg' \
"${cmd}" i-am-arguing

call-and-log-as-test 'passed two positional args' \
"${cmd}" florp fleep

call-and-log-as-test 'passed `--` then positional arg' \
"${cmd}" -- MORE_ARGUING

call-and-log-as-test 'passed `--` then arg that looks like an option' \
"${cmd}" -- --non-option

call-and-log-as-test 'passed a double-dash option' \
"${cmd}" --x

call-and-log-as-test 'passed a double-dash option then a positional arg' \
"${cmd}" --x bloop
22 changes: 22 additions & 0 deletions tests/03-arg-processor/002-one-required-positional/the-cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash
# Copyright 2022-2023 the Bashy-lib Authors (Dan Bornstein et alia).
# SPDX-License-Identifier: Apache-2.0

. "$(dirname "$(readlink -f "$0")")/../../_init.sh" || exit "$?"


#
# Argument parsing
#

define-usage $'
${name} -- test command
This is a test command.
'

positional-arg --required --var=theName zongo

process-args "$@" || usage --short

printf 'Value: %q\n' "${theName}"
91 changes: 91 additions & 0 deletions tests/03-arg-processor/003-one-optional-positional/expect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
## no args or options passed

### stdout
```
Value: zorch
```

### exit: 0

- - - - - - - - - -

## passed `--`

### stdout
```
Value: zorch
```

### exit: 0

- - - - - - - - - -

## passed positional arg

### stdout
```
Value: i-am-arguing
```

### exit: 0

- - - - - - - - - -

## passed two positional args

### stderr
```
the-cmd: Too many positional arguments.
the-cmd -- test command
```

### exit: 1

- - - - - - - - - -

## passed `--` then positional arg

### stdout
```
Value: MORE_ARGUING
```

### exit: 0

- - - - - - - - - -

## passed `--` then arg that looks like an option

### stdout
```
Value: --non-option
```

### exit: 0

- - - - - - - - - -

## passed a double-dash option

### stderr
```
the-cmd: Unknown option: --x
the-cmd -- test command
```

### exit: 1

- - - - - - - - - -

## passed a double-dash option then a positional arg

### stderr
```
the-cmd: Unknown option: --x
the-cmd -- test command
```

### exit: 1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Test of a single optional positional argument.
31 changes: 31 additions & 0 deletions tests/03-arg-processor/003-one-optional-positional/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash
# Copyright 2022-2023 the Bashy-lib Authors (Dan Bornstein et alia).
# SPDX-License-Identifier: Apache-2.0

. "$(dirname "$(readlink -f "$0")")/../../_test-init.sh" || exit "$?"

cmd="$(this-cmd-dir)/the-cmd"

call-and-log-as-test 'no args or options passed' \
"${cmd}"

call-and-log-as-test 'passed `--`' \
"${cmd}" --

call-and-log-as-test 'passed positional arg' \
"${cmd}" i-am-arguing

call-and-log-as-test 'passed two positional args' \
"${cmd}" florp fleep

call-and-log-as-test 'passed `--` then positional arg' \
"${cmd}" -- MORE_ARGUING

call-and-log-as-test 'passed `--` then arg that looks like an option' \
"${cmd}" -- --non-option

call-and-log-as-test 'passed a double-dash option' \
"${cmd}" --x

call-and-log-as-test 'passed a double-dash option then a positional arg' \
"${cmd}" --x bloop
22 changes: 22 additions & 0 deletions tests/03-arg-processor/003-one-optional-positional/the-cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash
# Copyright 2022-2023 the Bashy-lib Authors (Dan Bornstein et alia).
# SPDX-License-Identifier: Apache-2.0

. "$(dirname "$(readlink -f "$0")")/../../_init.sh" || exit "$?"


#
# Argument parsing
#

define-usage $'
${name} -- test command
This is a test command.
'

positional-arg --var=theName --init=zorch zongo

process-args "$@" || usage --short

printf 'Value: %q\n' "${theName}"
97 changes: 97 additions & 0 deletions tests/03-arg-processor/004-positional-req-opt/expect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
## no args or options passed

### stderr
```
the-cmd: Missing required argument <avec-yes>.
the-cmd -- test command
```

### exit: 1

- - - - - - - - - -

## passed `--`

### stderr
```
the-cmd: Missing required argument <avec-yes>.
the-cmd -- test command
```

### exit: 1

- - - - - - - - - -

## passed one positional arg

### stdout
```
avec-yes: one
some-value: ''
```

### exit: 0

- - - - - - - - - -

## passed two positional args

### stdout
```
avec-yes: florp
some-value: fleep
```

### exit: 0

- - - - - - - - - -

## passed three positional args

### stderr
```
the-cmd: Too many positional arguments.
the-cmd -- test command
```

### exit: 1

- - - - - - - - - -

## passed `--` then one positional arg

### stdout
```
avec-yes: ONE
some-value: ''
```

### exit: 0

- - - - - - - - - -

## passed `--` then two positional args

### stdout
```
avec-yes: YES
some-value: MORE-YES
```

### exit: 0

- - - - - - - - - -

## passed `--` then three positional args

### stderr
```
the-cmd: Too many positional arguments.
the-cmd -- test command
```

### exit: 1
Loading

0 comments on commit 488cfa1

Please sign in to comment.