Minor fixes identified through shellcheck and other tools (#350)

* fix whitespace

* fix spelling

* fix whitespace

* unify headers of tests

* fix some issues in tests, identified by shellcheck

* fix bash completions

bash completion files are not supposed to be executable

* fix some issues identified by shellcheck

Co-authored-by: Ali Karbassi <ali@karbassi.com>
This commit is contained in:
a1346054
2021-08-09 20:03:49 +00:00
committed by GitHub
parent ee94a3fac5
commit 2d70a0aadf
40 changed files with 88 additions and 119 deletions

View File

@@ -147,7 +147,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
### Changed
- Changed odd tabs to spaces.
- Faster help/useage document outputs.
- Faster help/usage document outputs.
- Consolidated `TODOTXT_VERBOSE` tests.
- Refactored various add functionality to one function.
- Updated `_list()` output to match updated `addto`.
@@ -436,7 +436,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
### Added
- `list` is case insenstive. ie, `todo list Mac` will match lines with "mac" and "Mac"
- `list` is case insensitive. ie, `todo list Mac` will match lines with "mac" and "Mac"
### Changed

View File

@@ -34,5 +34,3 @@ test "$VN" = "$VC" || {
echo >&2 "VERSION=$VN"
echo "VERSION=$VN" >$VF
}

View File

@@ -671,4 +671,4 @@ into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
<https://www.gnu.org/licenses/why-not-lgpl.html>.
<https://www.gnu.org/licenses/why-not-lgpl.html>.

View File

@@ -98,7 +98,7 @@ $(TESTS): test-pre-clean
test: aggregate-results
tests/aggregate-results.sh tests/test-results/t*-*
rm -rf tests/test-results
# Force tests to get run every time
.PHONY: test test-pre-clean aggregate-results $(TESTS)

View File

@@ -85,7 +85,7 @@ See [CHANGELOG.md][CHANGELOG]
## Contributing
We welcome all contributations. First read our [Contributor Code of Conduct][CODE_OF_CONDUCT] and then get started [contributing][CONTRIBUTING].
We welcome all contributions. First read our [Contributor Code of Conduct][CODE_OF_CONDUCT] and then get started [contributing][CONTRIBUTING].
## License
@@ -94,7 +94,7 @@ GNU General Public License v3.0 © [todo.txt org][github]
[release]: https://github.com/todotxt/todo.txt-cli/releases
[website]: http://todotxt.org
[website]: http://todotxt.org/
[github]: https://github.com/todotxt
[USAGE]: ./USAGE.md
[CHANGELOG]: ./CHANGELOG.md

View File

@@ -7,9 +7,9 @@ todo.sh [-fhpantvV] [-d todo_config] action [task_number] [task_description]
## Actions
### `add`
Adds THING I NEED TO DO to your todo.txt file on its own line.
Adds THING I NEED TO DO to your todo.txt file on its own line.
Project and context notation optional.
Project and context notation optional.
Quotes optional.
@@ -28,7 +28,7 @@ todo.sh addm "FIRST THING I NEED TO DO +project1 @context
SECOND THING I NEED TO DO +project2 @context"
```
### `addto`
### `addto`
Adds a line of text to any file located in the todo.txt directory.
For example, `addto inbox.txt "decide about vacation"`
@@ -101,10 +101,10 @@ todo.sh help [ACTION...]
```
### `list`
Displays all tasks that contain TERM(s) sorted by priority with line numbers. Each task must match all TERM(s) (logical AND); to display tasks that contain any TERM (logical OR), use `"TERM1\|TERM2\|..."` (with quotes), or `TERM1\\|TERM2` (unquoted). Hides all tasks that contain TERM(s) preceded by a minus sign (i.e. `-TERM`).
Displays all tasks that contain TERM(s) sorted by priority with line numbers. Each task must match all TERM(s) (logical AND); to display tasks that contain any TERM (logical OR), use `"TERM1\|TERM2\|..."` (with quotes), or `TERM1\\|TERM2` (unquoted). Hides all tasks that contain TERM(s) preceded by a minus sign (i.e. `-TERM`).
If no TERM specified, lists entire todo.txt.
```shell
todo.sh list [TERM...]
todo.sh ls [TERM...]

View File

@@ -18,14 +18,14 @@ The easiest way to run tests is to say "make test" from the top-level.
This runs all the tests.
rm -rf tests/test-results "tests/trash directory"*
cd tests && sh t0000-config.sh
cd tests && sh t0000-config.sh
* ok 1: no config file
* ok 2: config file (default location 1)
* ok 3: config file (default location 2)
* ok 4: config file (command line)
* ok 5: config file (env variable)
* passed all 5 test(s)
cd tests && sh t0001-null.sh
cd tests && sh t0001-null.sh
* ok 1: null ls
* passed all 1 test(s)
rm -rf tests/test-results
@@ -33,7 +33,7 @@ This runs all the tests.
Or you can run each test individually from command line, like
this:
$ ./t0001-null.sh
$ ./t0001-null.sh
* ok 1: null ls
* passed all 1 test(s)
@@ -42,27 +42,27 @@ You can pass --verbose (or -v), --debug (or -d), and --immediate
appropriately before running "make".
--verbose::
This makes the test more verbose. Specifically, the
command being run and their output if any are also
output.
This makes the test more verbose. Specifically, the
command being run and their output if any are also
output.
--debug::
This may help the person who is developing a new test.
It causes the command defined with test_debug to run.
This may help the person who is developing a new test.
It causes the command defined with test_debug to run.
--immediate::
This causes the test to immediately exit upon the first
failed test.
This causes the test to immediately exit upon the first
failed test.
--long-tests::
This causes additional long-running tests to be run (where
available), for more exhaustive testing.
This causes additional long-running tests to be run (where
available), for more exhaustive testing.
--tee::
In addition to printing the test output to the terminal,
write it to files named 't/test-results/$TEST_NAME.out'.
As the names depend on the tests' file names, it is safe to
run the tests with this option in parallel.
In addition to printing the test output to the terminal,
write it to files named 't/test-results/$TEST_NAME.out'.
As the names depend on the tests' file names, it is safe to
run the tests with this option in parallel.
Skipping Tests
--------------
@@ -97,15 +97,15 @@ Naming Tests
The test files are named as:
tNNNN-commandname-details.sh
tNNNN-commandname-details.sh
where N is a decimal digit.
First digit tells the family:
0 - the absolute basics and global stuff
1 - basic every-day usage
2 - add ins
0 - the absolute basics and global stuff
1 - basic every-day usage
2 - add ins
Second digit tells the particular command we are testing.
@@ -128,15 +128,15 @@ The test script is written as a shell script. It should start
with the standard "#!/bin/bash" with copyright notices, and an
assignment to variable 'test_description', like this:
#!/bin/bash
#
# Copyright (c) 2005 Junio C Hamano
#
#!/bin/bash
#
# Copyright (c) 2005 Junio C Hamano
#
test_description='xxx test (option --frotz)
test_description='xxx test (option --frotz)
This test registers the following structure in the cache
and tries to run git-ls-files with option --frotz.'
This test registers the following structure in the cache
and tries to run git-ls-files with option --frotz.'
Source 'test-lib.sh'
@@ -145,7 +145,7 @@ Source 'test-lib.sh'
After assigning test_description, the test script should source
test-lib.sh like this:
. ./test-lib.sh
. ./test-lib.sh
This test harness library does the following things:
@@ -219,9 +219,9 @@ library for your script to use.
Example:
test_expect_success \
'git-write-tree should be able to write an empty tree.' \
'tree=$(git-write-tree)'
test_expect_success \
'git-write-tree should be able to write an empty tree.' \
'tree=$(git-write-tree)'
- test_expect_code <code> <message> <script>
@@ -266,7 +266,7 @@ and the dates and timestamps will be artificially fixed.
Then the session can be used to make a unit test thanks to
test_todo_session, see the existing tests as examples.
Be careful to replace all occurences of the full path to the test
Be careful to replace all occurrences of the full path to the test
directory by $HOME as testshell.sh will explain you when you execute it
otherwise the tests will work properly only on your own computer.

View File

@@ -21,7 +21,7 @@ make_action_in_folder()
{
unset TODO_ACTIONS_DIR
[ -d .todo.actions.d ] || mkdir .todo.actions.d
mkdir .todo.actions.d/$1
mkdir ".todo.actions.d/$1"
cat > ".todo.actions.d/$1/$1" <<EOF
#!/bin/bash
[ "\$1" = "usage" ] && {

View File

@@ -15,7 +15,7 @@ case "$1" in
esac
if test -n "$color"; then
say_color () {
say_color() {
(
export TERM
case "$1" in
@@ -67,15 +67,15 @@ do
'')
continue ;;
fixed)
fixed=$(($fixed + $value)) ;;
fixed=$((fixed + $value)) ;;
success)
success=$(($success + $value)) ;;
success=$((success + $value)) ;;
failed)
failed=$(($failed + $value)) ;;
failed=$((failed + $value)) ;;
broken)
broken=$(($broken + $value)) ;;
broken=$((broken + $value)) ;;
total)
total=$(($total + $value)) ;;
total=$((total + $value)) ;;
esac
done <"$file"
done

View File

@@ -20,12 +20,12 @@ test_expect_success 'no config file' '
'
# All the below tests will output the usage message.
cat > expect << EOF
cat > expect <<EOF
Usage: todo.sh [-fhpantvV] [-d todo_config] action [task_number] [task_description]
Try 'todo.sh -h' for more information.
EOF
cat > test.cfg << EOF
cat > test.cfg <<EOF
export TODO_DIR=.
export TODO_FILE="\$TODO_DIR/todo.txt"
export DONE_FILE="\$TODO_DIR/done.txt"
@@ -79,7 +79,7 @@ test_expect_success 'config file (env variable)' '
test_cmp expect output && test -f used_config
'
cat > minimal.cfg << EOF
cat > minimal.cfg <<EOF
export TODO_DIR=.
touch used_config
EOF

View File

@@ -59,7 +59,6 @@ test_expect_success 'null list filter' '
todo.sh listall filter > output && test_cmp expect output
'
#
# lsc|listcon
#

View File

@@ -7,11 +7,11 @@ This test just makes sure that todo.sh can locate custom actions.
. ./test-lib.sh
# All the below tests will output the custom action message
cat > expect << EOF
cat > expect <<EOF
TODO: foo
EOF
cat > foo << EOF
cat > foo <<EOF
echo "TODO: foo"
EOF
chmod +x foo

View File

@@ -66,7 +66,7 @@ test_todo_session 'basic listfile filtering' <<EOF
--
GARDEN: 1 of 2 tasks shown
>>> todo.sh listfile garden.txt smell
>>> todo.sh listfile garden.txt smell
2 smell the roses
--
GARDEN: 1 of 2 tasks shown
@@ -89,7 +89,7 @@ test_todo_session 'addto with &' <<EOF
4 dig the garden & water the flowers
GARDEN: 4 added.
>>> todo.sh listfile garden.txt
>>> todo.sh listfile garden.txt
4 dig the garden & water the flowers
1 notice the daisies
2 smell the roses

View File

@@ -45,7 +45,7 @@ grow some corn
thrash some hay
chase the chickens
EOF
test_todo_session 'replace error' << EOF
test_todo_session 'replace error' <<EOF
>>> todo.sh replace 10 "hej!"
=== 1
TODO: No task 10.
@@ -82,7 +82,7 @@ TODO: Replaced task with:
EOF
echo 'jump on hay' > todo.txt
test_todo_session 'replace with &' << EOF
test_todo_session 'replace with &' <<EOF
>>> todo.sh replace 1 "thrash the hay & thrash the wheat"
1 jump on hay
TODO: Replaced task with:

View File

@@ -1,5 +1,4 @@
#!/bin/bash
#
test_description='list functionality
@@ -162,7 +161,6 @@ TODO: 1 of 5 tasks shown
TODO: 1 of 5 tasks shown
EOF
#
# check the x command line option
#

View File

@@ -1,5 +1,4 @@
#!/bin/bash
#
test_description='listcon functionality

View File

@@ -1,5 +1,4 @@
#!/bin/bash
#
test_description='listproj functionality
@@ -117,7 +116,6 @@ test_todo_session 'listproj with context special cases' <<EOF
+sunflowers
EOF
cat > todo.txt <<EOF
+prj01 -- Some project 1 task
EOF

View File

@@ -1,5 +1,4 @@
#!/bin/bash
#
test_description='list highlighting

View File

@@ -1,5 +1,4 @@
#!/bin/bash
#
test_description='list with escape sequences

View File

@@ -1,5 +1,4 @@
#!/bin/bash
#
test_description='highlighting projects and contexts

View File

@@ -1,5 +1,4 @@
#!/bin/bash
#
test_description='highlighting date, item numbers and metadata
@@ -32,7 +31,6 @@ test_todo_session 'highlighting for date, item numbers and metadata' <<'EOF'
TODO: 3 of 3 tasks shown
EOF
test_todo_session 'suppressing highlighting for date, item numbers and metadata' <<'EOF'
>>> todo.sh -p -d "$TEST_TODO_LABEL_COLORS" ls
1 2018-11-11 task with date

View File

@@ -83,4 +83,5 @@ TODO: 3 marked as done.
>>> todo.sh -a do 3
TODO: 3 is already marked done.
EOF
test_done

View File

@@ -17,7 +17,7 @@ test_todo_session 'append usage' <<EOF
usage: todo.sh append ITEM# "TEXT TO APPEND"
EOF
test_todo_session 'append error' << EOF
test_todo_session 'append error' <<EOF
>>> todo.sh append 10 "hej!"
=== 1
TODO: No task 10.

View File

@@ -1,5 +1,4 @@
#!/bin/bash
#
test_description='basic move functionality
'

View File

@@ -1,5 +1,4 @@
#!/bin/bash
#
test_description='help functionality

View File

@@ -1,5 +1,4 @@
#!/bin/bash
#
test_description='shorthelp functionality
@@ -36,7 +35,6 @@ test_todo_session 'shorthelp output with custom action' <<EOF
See "help" for more details.
EOF
# Verify that custom configuration is actually processed (when the -d option
# precedes the -h option) by specifying a different actions directory and moving
# our custom action there. The help output should mention the "Add-On Actions".

View File

@@ -1,5 +1,4 @@
#!/bin/bash
#
test_description='todo.sh configuration with a sole todo.txt data file.
@@ -8,7 +7,7 @@ checks that no such empty files are created.
'
. ./test-lib.sh
cat > test.cfg << EOF
cat > test.cfg <<EOF
export TODO_DIR=.
export TODO_FILE="\$TODO_DIR/todo.txt"
export DONE_FILE=/dev/null

View File

@@ -1,5 +1,4 @@
#!/bin/bash
#
test_description='Bash completion functionality

View File

@@ -1,5 +1,4 @@
#!/bin/bash
#
test_description='Bash context completion functionality

View File

@@ -1,5 +1,4 @@
#!/bin/bash
#
test_description='Bash project completion functionality

View File

@@ -1,5 +1,4 @@
#!/bin/bash
#
test_description='Bash task number completion functionality

View File

@@ -1,5 +1,4 @@
#!/bin/bash
#
test_description='Bash todo file completion functionality

View File

@@ -1,5 +1,4 @@
#!/bin/bash
#
test_description='Bash add-on action completion functionality
@@ -74,7 +73,7 @@ removeCustomActions "$HOME/.todo.actions.d"
#
# Test resolution of an alternative TODO_ACTIONS_DIR.
#
mkdir "$HOME/.todo"
mkdir "$HOME/.todo"
makeCustomActions "$HOME/.todo/actions"
test_todo_completion 'all arguments with actions from .todo/actions/' 'todo.sh ' "$ACTIONS $ADDONS $CONTAINED $OPTIONS"
removeCustomActions "$HOME/.todo/actions"

View File

@@ -1,5 +1,4 @@
#!/bin/bash
#
test_description='Bash add-on action file completion functionality

View File

@@ -1,5 +1,4 @@
#!/bin/bash
#
test_description='Bash completion with different path functionality
@@ -28,8 +27,6 @@ _todo2()
test_todo_custom_completion _todo2 'all todo2 contexts' 'todo2 list @' '@garden @outdoor @outside'
# Remove the test environment's bin directory from the PATH, so that our test
# executable must be launched with an explicit path.
PATH=${PATH##"${PWD}/bin:"}

View File

@@ -1,5 +1,4 @@
#!/bin/bash
#
test_description='Bash completion with different aliases functionality
@@ -46,7 +45,6 @@ test_todo_session 'todo 1 and 2 contexts' <<EOF
@oriental
EOF
# Define a second completion function that injects the different configuration
# file. In real use, this would be installed via
# complete -F _todo2 todo2

View File

@@ -1,5 +1,4 @@
#!/bin/bash
#
test_description='Bash help completion functionality

View File

@@ -172,12 +172,12 @@ test_set_editor () {
# the text_expect_* functions instead.
test_ok_ () {
test_success=$(($test_success + 1))
test_success=$((test_success + 1))
say_color "" " ok $test_count: $@"
}
test_failure_ () {
test_failure=$(($test_failure + 1))
test_failure=$((test_failure + 1))
say_color error "FAIL $test_count: $1"
shift
echo "$@"
@@ -185,12 +185,12 @@ test_failure_ () {
}
test_known_broken_ok_ () {
test_fixed=$(($test_fixed+1))
test_fixed=$((test_fixed + 1))
say_color "" " FIXED $test_count: $@"
}
test_known_broken_failure_ () {
test_broken=$(($test_broken+1))
test_broken=$((test_broken + 1))
say_color skip " still broken $test_count: $@"
}
@@ -206,7 +206,7 @@ test_run_ () {
}
test_skip () {
test_count=$(($test_count+1))
test_count=$((test_count + 1))
to_skip=
for skp in $SKIP_TESTS
do
@@ -364,7 +364,7 @@ test_external_without_stderr () {
test_ok_ "$descr"
else
if [ "$verbose" = t ]; then
output=`echo; echo Stderr is:; cat "$stderr"`
output=$(echo; echo Stderr is:; cat "$stderr")
else
output=
fi
@@ -428,7 +428,7 @@ test_done () {
if test "$test_broken" != 0
then
say_color error "still have $test_broken known breakage(s)"
msg="remaining $(($test_count-$test_broken)) test(s)"
msg="remaining $((test_count - test_broken)) test(s)"
else
msg="$test_count test(s)"
fi
@@ -471,7 +471,7 @@ rm -fr "$test" || {
test_init_todo () {
test "$#" = 1 ||
error "bug in the test script: not 1 parameter to test_init_todo"
owd=`pwd`
owd=$(pwd)
root="$1"
mkdir -p "$root"
cd "$root" || error "Cannot setup todo dir in $root"
@@ -548,7 +548,7 @@ test_init_todo () {
# Usage: test_tick [increment]
test_tick () {
TODO_TEST_TIME=$(($TODO_TEST_TIME + ${1:-86400}))
TODO_TEST_TIME=$((TODO_TEST_TIME + ${1:-86400}))
}
# Generate and run a series of tests based on a transcript.
@@ -581,14 +581,14 @@ test_todo_session () {
status=${line#=== }
;;
"")
if [ ! -z "$cmd" ]; then
if [ $status = 0 ]; then
if [ -n "$cmd" ]; then
if [ "$status" = 0 ]; then
test_expect_output "$1 $subnum" "$cmd"
else
test_expect_code_and_output "$status" "$1 $subnum" "$cmd"
fi
subnum=$(($subnum + 1))
subnum=$((subnum + 1))
cmd=""
status=0
> expect
@@ -602,8 +602,8 @@ test_todo_session () {
;;
esac
done
if [ ! -z "$cmd" ]; then
if [ $status = 0 ]; then
if [ -n "$cmd" ]; then
if [ "$status" = 0 ]; then
test_expect_output "$1 $subnum" "$cmd"
else
test_expect_code_and_output "$status" "$1 $subnum" "$cmd"
@@ -645,7 +645,7 @@ test_todo_custom_completion () {
SAVEIFS=$IFS
IFS=' ' set -- $2
COMP_WORDS=("$@")
COMP_CWORD=$(($# - $offset))
COMP_CWORD=$(($# - offset))
IFS=' ' eval "set -- $expected"
EXPECT=("$@")

13
todo.sh
View File

@@ -134,7 +134,6 @@ $indentedJoinedConfigFileLocations
-x
Disables TODOTXT_FINAL_FILTER
EndOptionsHelp
[ "$TODOTXT_VERBOSE" -gt 1 ] && cat <<-'EndVerboseHelp'
@@ -156,7 +155,6 @@ $indentedJoinedConfigFileLocations
TODOTXT_SIGIL_VALID_PATTERN=.* tweak the allowed chars for +p and @c
TODOTXT_SIGIL_AFTER_PATTERN="" optionally allow chars after +p / @c
EndVerboseHelp
actionsHelp
addonHelp
@@ -710,7 +708,6 @@ do
fi
done
if [ -z "$TODO_ACTIONS_DIR" ] || [ ! -d "$TODO_ACTIONS_DIR" ]
then
TODO_ACTIONS_DIR="$HOME/.todo/actions"
@@ -788,7 +785,7 @@ ACTION=${1:-$TODOTXT_DEFAULT_ACTION}
if [ $TODOTXT_PLAIN = 1 ]; then
for clr in ${!PRI_@}; do
export "$clr"=$NONE
export "$clr"="$NONE"
done
PRI_X=$NONE
DEFAULT=$NONE
@@ -1093,7 +1090,7 @@ case $action in
SAVEIFS=$IFS
IFS=$'\n'
# Treat each line seperately
# Treat each line separately
for line in $input ; do
_addto "$TODO_FILE" "$line"
done
@@ -1136,7 +1133,7 @@ case $action in
if [ "$TODOTXT_VERBOSE" -gt 0 ]; then
getNewtodo "$item"
echo "$item $newtodo"
fi
fi
else
die "TODO: Error appending task $item."
fi
@@ -1149,7 +1146,7 @@ case $action in
grep "^x " "$TODO_FILE" >> "$DONE_FILE"
sed -i.bak '/^x /d' "$TODO_FILE"
if [ "$TODOTXT_VERBOSE" -gt 0 ]; then
echo "TODO: $TODO_FILE archived."
echo "TODO: $TODO_FILE archived."
fi
;;
@@ -1240,7 +1237,7 @@ case $action in
getNewtodo "$item"
echo "$item $newtodo"
echo "TODO: $item marked as done."
fi
fi
else
echo "TODO: $item is already marked done."
fi

View File

@@ -1,5 +1,7 @@
#!/bin/bash source-this-script
[ "$BASH_VERSION" ] || return
# bash completion for todo.txt-cli
# Check for bash
[ -z "$BASH_VERSION" ] && return
_todo()
{
@@ -18,7 +20,7 @@ _todo()
local _todo_sh=${_todo_sh:-todo.sh}
local completions
if [ $COMP_CWORD -eq 1 ]; then
if [ "$COMP_CWORD" -eq 1 ]; then
completions="$COMMANDS $(eval TODOTXT_VERBOSE=0 $_todo_sh command listaddons 2>/dev/null) $OPTS"
elif [[ $COMP_CWORD -gt 2 && ( \
"${COMP_WORDS[COMP_CWORD-2]}" =~ ^($MOVE_COMMAND_PATTERN${_todo_file2_actions:+|${_todo_file2_actions}})$ || \