Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change default inline marker from #→ to #=> #15

Merged
merged 2 commits into from
Mar 11, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 25 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -198,12 +198,12 @@ Examples of testable documentation handled by clitest:
## Alternative Syntax: Inline Output

Now a nice extension to the original idea. Using the special marker
`#` you can embed the expected command output at the end of the
`#=>` you can embed the expected command output at the end of the
command line.

```console
$ echo "foo" # foo
$ echo $((10 + 2)) # 12
$ echo "foo" #=> foo
$ echo $((10 + 2)) #=> 12
```

This is the same as doing:
Expand All @@ -220,55 +220,53 @@ Inline outputs are very readable when testing series of commands that
result in short texts.

```console
$ echo "abcdef" | cut -c 1 # a
$ echo "abcdef" | cut -c 4 # d
$ echo "abcdef" | cut -c 1,4 # ad
$ echo "abcdef" | cut -c 1-4 # abcd
$ echo "abcdef" | cut -c 1 #=> a
$ echo "abcdef" | cut -c 4 #=> d
$ echo "abcdef" | cut -c 1,4 #=> ad
$ echo "abcdef" | cut -c 1-4 #=> abcd
```

> Note: The Unicode character `→` (U+2192) was chosen because it's
> meaningful and less likely to appear on a real command. If needed,
> you can change this marker (i.e., to `#->`) at the top of the script
> or using the `--inline-prefix` option.
> Note: If needed, you can change this marker (i.e., to `#→` or `###`)
> at the top of the script or using the `--inline-prefix` option.


## Advanced Tests

When using the `#` marker, you can take advantage of special options
When using the `#=>` marker, you can take advantage of special options
to change the default output matching method.

```console
$ head /etc/passwd # --lines 10
$ tac /etc/passwd | tac # --file /etc/passwd
$ cat /etc/passwd # --egrep ^root:
$ echo $((2 + 10)) # --regex ^\d+$
$ make test # --exit 0
$ pwd # --eval echo $PWD
$ head /etc/passwd #=> --lines 10
$ tac /etc/passwd | tac #=> --file /etc/passwd
$ cat /etc/passwd #=> --egrep ^root:
$ echo $((2 + 10)) #=> --regex ^\d+$
$ make test #=> --exit 0
$ pwd #=> --eval echo $PWD
```

* Using `# --lines` the test will pass if the command output has
* Using `#=> --lines` the test will pass if the command output has
exactly `N` lines. Handy when the output text is variable
(unpredictable), but the number of resulting lines is constant.

* Using `# --file` the test will pass if the command output matches
* Using `#=> --file` the test will pass if the command output matches
the contents of an external file. Useful to organize long/complex
outputs into files.

* Using `# --egrep` the test will pass if `egrep` matches at least
* Using `#=> --egrep` the test will pass if `egrep` matches at least
one line of the command output.

* Using `# --regex` the test will pass if the command output is
* Using `#=> --regex` the test will pass if the command output is
matched by a [Perl regular expression][9]. A multiline output is
matched as a single string, with inner `\n`'s. Use the `(?ims)`
modifiers when needed.

* Using `# --exit` the test will pass if the exit code of the command
* Using `#=> --exit` the test will pass if the exit code of the command
is equal to the code specified. Useful when testing commands that
generate variable output (or no output at all), and the exit code is
the best indication of success. Both STDIN and STDOUT are ignored
when using this option.

* Using `# --eval` the test will pass if both commands result in the
* Using `#=> --eval` the test will pass if both commands result in the
same output. Useful to expand variables which store the full or
partial output.

Expand All @@ -293,7 +291,7 @@ Customization options:
-P, --progress TYPE Set progress indicator: test, number, dot, none
--color WHEN Set when to use colors: auto, always, never
--diff-options OPTIONS Set diff command options (default: '-u')
--inline-prefix PREFIX Set inline output prefix (default: '# ')
--inline-prefix PREFIX Set inline output prefix (default: '#=> ')
--prefix PREFIX Set command line prefix (default: '')
--prompt STRING Set prompt string (default: '$ ')
$
Expand Down Expand Up @@ -405,7 +403,7 @@ clitest --prefix 4 --prompt '[john@localhost ~]$ ' README.md
* Unlike doctest's `<BLANKLINE>`, in clitest blank lines in the
command output aren't a problem. Just insert them normally.

* To test outputs with no final `\n`, such as `printf foo`, use `#
* To test outputs with no final `\n`, such as `printf foo`, use `#=>
--regex ^foo$`.

* In multifile mode, the current folder (`$PWD`) is reset when
Expand All @@ -414,7 +412,7 @@ clitest --prefix 4 --prompt '[john@localhost ~]$ ' README.md

* Multiline prompts (`$PS2`) are not yet supported.

* Ellipsis (as in doctest) are not supported. Use `# --regex`
* Ellipsis (as in doctest) are not supported. Use `#=> --regex`
instead.

* Simple examples in [examples/][10]. Hardcore examples in
Expand Down
6 changes: 3 additions & 3 deletions clitest
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ tt_my_version_url="https://github.com/aureliojargas/clitest/tree/$tt_my_version"
# Customization (if needed, edit here or use the command line options)
tt_prefix=''
tt_prompt='$ '
tt_inline_prefix='#→ ' # Problem with Unicode? Use '#=> ' or '### '
tt_inline_prefix='#=> '
tt_diff_options='-u'
tt_color_mode='auto' # auto, always, never
tt_progress='test' # test, number, dot, none
Expand Down Expand Up @@ -602,10 +602,10 @@ tt_make_temp_dir ()
{
# Create private temporary dir and sets global $tt_temp_dir.
# http://mywiki.wooledge.org/BashFAQ/062

# Prefer mktemp when available
tt_temp_dir=$(mktemp -d "${TMPDIR:-/tmp}/clitest.XXXXXX" 2> /dev/null) && return 0

# No mktemp, let's create the dir manually
tt_temp_dir="${TMPDIR:-/tmp}/clitest.$(awk 'BEGIN { srand(); print rand() }').$$" &&
mkdir -m 700 "$tt_temp_dir" || tt_error "cannot create temporary dir: $tt_temp_dir"
Expand Down
42 changes: 21 additions & 21 deletions test.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ $ echo $COLUMNS
$ not_exported=1
$ echo $not_exported
1
$ echo $not_exported # 1
$ echo $not_exported # --regex ^1$
$ echo $not_exported #=> 1
$ echo $not_exported #=> --regex ^1$
```

## Check the temporary dir creation
Expand Down Expand Up @@ -143,7 +143,7 @@ Customization options:
-P, --progress TYPE Set progress indicator: test, number, dot, none
--color WHEN Set when to use colors: auto, always, never
--diff-options OPTIONS Set diff command options (default: '-u')
--inline-prefix PREFIX Set inline output prefix (default: '# ')
--inline-prefix PREFIX Set inline output prefix (default: '#=> ')
--prefix PREFIX Set command line prefix (default: '')
--prompt STRING Set prompt string (default: '$ ')
0
Expand Down Expand Up @@ -196,8 +196,8 @@ $
# [INPUT_LINE: ok]
# [ LINE_*: ok]
# [ OK_TEXT: ok]
# [INPUT_LINE: $ echo ok # ok]
# [ LINE_CMD: $ echo ok # ok]
# [INPUT_LINE: $ echo ok #=> ok]
# [ LINE_CMD: $ echo ok #=> ok]
# [ EVAL: echo ok]
# [ OUTPUT: ok]
# [ NEW_CMD: echo ok ]
Expand Down Expand Up @@ -947,7 +947,7 @@ $
## Fail messages

```
$ ./clitest --prefix tab -P none test/fail-messages.md # --file test/fail-messages.out.txt
$ ./clitest --prefix tab -P none test/fail-messages.md #=> --file test/fail-messages.out.txt
$
```

Expand Down Expand Up @@ -1027,7 +1027,7 @@ FAIL: 2 of 2 tests failed
$
```

## Inline output with #
## Inline output with #=>

```
$ ./clitest test/inline.sh
Expand Down Expand Up @@ -1056,7 +1056,7 @@ $

## Inline match modes

Mode # --text
Mode #=> --text

* This is the default mode.
* The --text part can be omitted.
Expand All @@ -1077,7 +1077,7 @@ $ ./clitest --list-run test/inline-match-text.sh
#12 OK echo '['
#13 OK echo '('
#14 OK echo
#15 OK echo "not inline output" #
#15 OK echo "not inline output" #=>
#16 OK echo '123456789'
#17 OK echo '1 3 7 9'
#18 OK echo ' 5 '
Expand Down Expand Up @@ -1106,7 +1106,7 @@ $ ./clitest --list-run test/inline-match-text.sh
$
```

Mode # --eval
Mode #=> --eval

```
$ ./clitest --list-run test/inline-match-eval.sh
Expand Down Expand Up @@ -1139,7 +1139,7 @@ $ ./clitest --list-run test/inline-match-eval.sh
$
```

Mode # --egrep
Mode #=> --egrep

```
$ ./clitest --list-run test/inline-match-egrep.sh | sed 's/^\(#1[56].\)[A-Z]*/\1?/'
Expand Down Expand Up @@ -1174,7 +1174,7 @@ $ ./clitest --list-run test/inline-match-egrep.sh | sed 's/^\(#1[56].\)[A-Z]*/\1
$
```

Mode # --perl
Mode #=> --perl

* --regex is an alias to --perl

Expand Down Expand Up @@ -1218,7 +1218,7 @@ $ ./clitest --list-run test/inline-match-perl.sh
$
```

Mode # --file
Mode #=> --file

```
$ ./clitest --list-run test/inline-match-file.sh
Expand All @@ -1233,7 +1233,7 @@ $ ./clitest --list-run test/inline-match-file.sh
$
```

Mode # --lines
Mode #=> --lines

```
$ ./clitest --list-run test/inline-match-lines.sh
Expand Down Expand Up @@ -1263,7 +1263,7 @@ Expected 99 lines, got 1.
$
```

Mode # --exit
Mode #=> --exit

```
$ ./clitest --list-run test/inline-match-exit.sh
Expand Down Expand Up @@ -1298,7 +1298,7 @@ Expected exit code 99, got 0
$
```

Errors for # --egrep
Errors for #=> --egrep

```
$ ./clitest test/inline-match-egrep-error-1.sh; echo $?
Expand All @@ -1311,7 +1311,7 @@ clitest: Error: check your inline egrep regex at line 1 of test/inline-match-egr
$
```

Errors for # --perl (and --regex)
Errors for #=> --perl (and --regex)

```
$ ./clitest test/inline-match-perl-error-1.sh; echo $?
Expand All @@ -1324,7 +1324,7 @@ clitest: Error: check your inline Perl regex at line 1 of test/inline-match-perl
$
```

Errors for # --file
Errors for #=> --file

```
$ ./clitest test/inline-match-file-error-1.sh; echo $?
Expand All @@ -1341,7 +1341,7 @@ clitest: Error: cannot read inline output file '/etc/', from line 1 of test/inli
$
```

Errors for # --lines
Errors for #=> --lines

```
$ ./clitest test/inline-match-lines-error-1.sh
Expand All @@ -1356,7 +1356,7 @@ clitest: Error: --lines requires a number. See line 1 of test/inline-match-lines
$
```

Errors for # --exit
Errors for #=> --exit

```
$ ./clitest test/inline-match-exit-error-1.sh
Expand All @@ -1371,7 +1371,7 @@ clitest: Error: --exit requires a number. See line 1 of test/inline-match-exit-e
$
```

Errors for # --eval
Errors for #=> --eval

```
$ ./clitest test/inline-match-eval-error-1.sh; echo $?
Expand Down
2 changes: 1 addition & 1 deletion test/fail-2.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
$ echo ok
fail
$ echo ok # fail
$ echo ok #=> fail
Loading