Skip to content

Commit

Permalink
Add new test module: test/errors
Browse files Browse the repository at this point in the history
To make sure an invalid command is detected as such, and an error
message is shown to the user.

Covers the problems found in issues #3 and #48.
  • Loading branch information
aureliojargas committed Nov 17, 2019
1 parent a47b085 commit dc04d78
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@
- Bugfix: Add support for escaped chars in `y` command.
[#11](https://github.com/aureliojargas/sedsed/issues/11)

- Bugfix: Raise syntax error for unknown `s///` flags.
[#3](https://github.com/aureliojargas/sedsed/issues/3)

- Bugfix: Detect and show error on incomplete `s` and `y` commands.
[#48](https://github.com/aureliojargas/sedsed/issues/48)


## [Version 1.1][] released in 2019-05-25

Expand Down
19 changes: 19 additions & 0 deletions test/errors/invalid-commands.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
u
s
s/
s//
s/foo
s/foo\/foo
s/foo/bar
s/foo/bar\/bar
s/foo/bar/@
s/foo/bar/@g
s/foo/bar/g@
s/foo/bar//
s/foo/bar/w
y
y/
y//
y/a
y/a/b
y/a/b/g
25 changes: 25 additions & 0 deletions test/errors/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash

# Always run the tests from this script's folder
cd "$(dirname "$0")" || exit 1

# Read default configuration
# shellcheck source=test/_include.sh
source ../_include.sh

# Run sedsed for each invalid command.
# Each test is ok if sedsed raises an error message.
while read -r line
do
test_message "Testing $line"
output=$($sedsed -e "$line" || true)
if ! echo "$output" | grep -q '^ERROR:'
then
failed=1
echo 'TEST FAILED'
echo "$output"
fi
done < invalid-commands.txt

tests_clean_up
tests_exit

0 comments on commit dc04d78

Please sign in to comment.