Merge branch 'inkarkat/master'
* inkarkat/master: Cosmetics: Corrected inconsistent indentation. Skipping 'nonexecutable action' test on Cygwin. Factored out generation of custom action scripts. Fixed test environment for escaped test output. MINOR: Removed unnecessary empty & reference in sed substitution. Avoiding todo.sh help error when .todo.actions.d contains subdirs. BUG: interpretation of \033 escape sequences in task BUG: task listing aborted on embedded \c escape sequence BUG: tr: extra operand `d' error caused by missing quoting
This commit is contained in:
2
Makefile
2
Makefile
@@ -42,7 +42,7 @@ test-pre-clean:
|
|||||||
aggregate-results: $(TESTS)
|
aggregate-results: $(TESTS)
|
||||||
|
|
||||||
$(TESTS): test-pre-clean
|
$(TESTS): test-pre-clean
|
||||||
-cd tests && sh $(notdir $@) $(TEST_OPTIONS)
|
-cd tests && ./$(notdir $@) $(TEST_OPTIONS)
|
||||||
|
|
||||||
test: aggregate-results
|
test: aggregate-results
|
||||||
tests/aggregate-results.sh tests/test-results/t*-*
|
tests/aggregate-results.sh tests/test-results/t*-*
|
||||||
|
|||||||
65
tests/t1340-listescapes.sh
Executable file
65
tests/t1340-listescapes.sh
Executable file
@@ -0,0 +1,65 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
#
|
||||||
|
|
||||||
|
test_description='list with escape sequences
|
||||||
|
|
||||||
|
This test checks listing of tasks that have embedded escape sequences in them.
|
||||||
|
'
|
||||||
|
. ./test-lib.sh
|
||||||
|
|
||||||
|
#
|
||||||
|
# check aborted list output on \c escape sequence
|
||||||
|
#
|
||||||
|
cat > todo.txt <<'EOF'
|
||||||
|
first todo
|
||||||
|
second todo run C:\WINDOWS\sysnative\cscript.exe
|
||||||
|
third todo
|
||||||
|
EOF
|
||||||
|
|
||||||
|
test_todo_session 'aborted list output on backslash-c' <<'EOF'
|
||||||
|
>>> todo.sh ls
|
||||||
|
1 first todo
|
||||||
|
2 second todo run C:\WINDOWS\sysnative\cscript.exe
|
||||||
|
3 third todo
|
||||||
|
--
|
||||||
|
TODO: 3 of 3 tasks shown
|
||||||
|
|
||||||
|
>>> todo.sh ls 2
|
||||||
|
2 second todo run C:\WINDOWS\sysnative\cscript.exe
|
||||||
|
--
|
||||||
|
TODO: 1 of 3 tasks shown
|
||||||
|
EOF
|
||||||
|
|
||||||
|
#
|
||||||
|
# check various escape sequences
|
||||||
|
#
|
||||||
|
cat > todo.txt <<'EOF'
|
||||||
|
first todo with \\, \a and \t
|
||||||
|
second todo with \r\n line break
|
||||||
|
third todo with \x42\x55\x47 and \033[0;31m color codes \033[0;30m
|
||||||
|
EOF
|
||||||
|
|
||||||
|
test_todo_session 'various escape sequences' <<'EOF'
|
||||||
|
>>> todo.sh ls
|
||||||
|
1 first todo with \\, \a and \t
|
||||||
|
2 second todo with \r\n line break
|
||||||
|
3 third todo with \x42\x55\x47 and \033[0;31m color codes \033[0;30m
|
||||||
|
--
|
||||||
|
TODO: 3 of 3 tasks shown
|
||||||
|
EOF
|
||||||
|
|
||||||
|
#
|
||||||
|
# check embedding of actual color sequence
|
||||||
|
#
|
||||||
|
cat > todo.txt <<'EOF'
|
||||||
|
A task with [0;31m actual color [0;30m
|
||||||
|
EOF
|
||||||
|
|
||||||
|
test_todo_session 'embedding of actual color sequence' <<'EOF'
|
||||||
|
>>> todo.sh ls
|
||||||
|
1 A task with [0;31m actual color [0;30m
|
||||||
|
--
|
||||||
|
TODO: 1 of 1 tasks shown
|
||||||
|
EOF
|
||||||
|
|
||||||
|
test_done
|
||||||
@@ -8,10 +8,27 @@ This test covers the contract between todo.sh and custom actions.
|
|||||||
|
|
||||||
unset TODO_ACTIONS_DIR
|
unset TODO_ACTIONS_DIR
|
||||||
mkdir .todo.actions.d
|
mkdir .todo.actions.d
|
||||||
cat > .todo.actions.d/foo << EOF
|
make_action()
|
||||||
echo "TODO: foo"
|
{
|
||||||
|
cat > ".todo.actions.d/$1" <<- EOF
|
||||||
|
#!/bin/bash
|
||||||
|
echo "custom action $1"
|
||||||
|
EOF
|
||||||
|
chmod +x ".todo.actions.d/$1"
|
||||||
|
}
|
||||||
|
|
||||||
|
make_action "foo"
|
||||||
|
test_todo_session 'executable action' <<EOF
|
||||||
|
>>> todo.sh foo
|
||||||
|
custom action foo
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
|
chmod -x .todo.actions.d/foo
|
||||||
|
# On Cygwin, clearing the executable flag may have no effect, as the Windows ACL
|
||||||
|
# may still grant execution rights. In this case, we skip the test.
|
||||||
|
if [ -x .todo.actions.d/foo ]; then
|
||||||
|
SKIP_TESTS="${SKIP_TESTS}${SKIP_TESTS+ }t8000.2"
|
||||||
|
fi
|
||||||
test_todo_session 'nonexecutable action' <<EOF
|
test_todo_session 'nonexecutable action' <<EOF
|
||||||
>>> todo.sh foo
|
>>> todo.sh foo
|
||||||
Usage: todo.sh [-fhpantvV] [-d todo_config] action [task_number] [task_description]
|
Usage: todo.sh [-fhpantvV] [-d todo_config] action [task_number] [task_description]
|
||||||
@@ -19,33 +36,21 @@ Try 'todo.sh -h' for more information.
|
|||||||
=== 1
|
=== 1
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
chmod +x .todo.actions.d/foo
|
make_action "ls"
|
||||||
test_todo_session 'executable action' <<EOF
|
|
||||||
>>> todo.sh foo
|
|
||||||
TODO: foo
|
|
||||||
EOF
|
|
||||||
|
|
||||||
cat > .todo.actions.d/ls << EOF
|
|
||||||
echo "TODO: my ls"
|
|
||||||
EOF
|
|
||||||
chmod +x .todo.actions.d/ls
|
|
||||||
test_todo_session 'overriding built-in action' <<EOF
|
test_todo_session 'overriding built-in action' <<EOF
|
||||||
>>> todo.sh ls
|
>>> todo.sh ls
|
||||||
TODO: my ls
|
custom action ls
|
||||||
|
|
||||||
>>> todo.sh command ls
|
>>> todo.sh command ls
|
||||||
--
|
--
|
||||||
TODO: 0 of 0 tasks shown
|
TODO: 0 of 0 tasks shown
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
cat > .todo.actions.d/bad << EOF
|
make_action "bad"
|
||||||
echo "TODO: bad"
|
echo "exit 42" >> .todo.actions.d/bad
|
||||||
exit 42
|
|
||||||
EOF
|
|
||||||
chmod +x .todo.actions.d/bad
|
|
||||||
test_todo_session 'failing action' <<EOF
|
test_todo_session 'failing action' <<EOF
|
||||||
>>> todo.sh bad
|
>>> todo.sh bad
|
||||||
TODO: bad
|
custom action bad
|
||||||
=== 42
|
=== 42
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
|
|||||||
@@ -12,8 +12,10 @@ done,*)
|
|||||||
*' --tee '*|*' --va'*)
|
*' --tee '*|*' --va'*)
|
||||||
mkdir -p test-results
|
mkdir -p test-results
|
||||||
BASE=test-results/$(basename "$0" .sh)
|
BASE=test-results/$(basename "$0" .sh)
|
||||||
(TEST_TEE_STARTED=done ${SHELL-sh} "$0" "$@" 2>&1;
|
(
|
||||||
echo $? > $BASE.exit) | tee $BASE.out
|
TEST_TEE_STARTED=done ${SHELL-sh} "$0" "$@" 2>&1;
|
||||||
|
echo $? > $BASE.exit
|
||||||
|
) | tee $BASE.out
|
||||||
test "$(cat $BASE.exit)" = 0
|
test "$(cat $BASE.exit)" = 0
|
||||||
exit
|
exit
|
||||||
;;
|
;;
|
||||||
@@ -527,7 +529,7 @@ test_todo_session () {
|
|||||||
cmd=""
|
cmd=""
|
||||||
status=0
|
status=0
|
||||||
> expect
|
> expect
|
||||||
while read line
|
while read -r line
|
||||||
do
|
do
|
||||||
case $line in
|
case $line in
|
||||||
">>> "*)
|
">>> "*)
|
||||||
@@ -552,7 +554,7 @@ test_todo_session () {
|
|||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo $line >> expect
|
echo "$line" >> expect
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|||||||
41
todo.sh
41
todo.sh
@@ -232,7 +232,7 @@ help()
|
|||||||
echo ""
|
echo ""
|
||||||
for action in "$TODO_ACTIONS_DIR"/*
|
for action in "$TODO_ACTIONS_DIR"/*
|
||||||
do
|
do
|
||||||
if [ -x "$action" ]
|
if [ -f "$action" -a -x "$action" ]
|
||||||
then
|
then
|
||||||
"$action" usage
|
"$action" usage
|
||||||
fi
|
fi
|
||||||
@@ -550,7 +550,7 @@ _addto() {
|
|||||||
if [ $TODOTXT_VERBOSE -gt 0 ]; then
|
if [ $TODOTXT_VERBOSE -gt 0 ]; then
|
||||||
TASKNUM=$(sed -n '$ =' "$file")
|
TASKNUM=$(sed -n '$ =' "$file")
|
||||||
BASE=$(basename "$file")
|
BASE=$(basename "$file")
|
||||||
PREFIX=$(echo ${BASE%%.[^.]*} | tr [a-z] [A-Z])
|
PREFIX=$(echo ${BASE%%.[^.]*} | tr 'a-z' 'A-Z')
|
||||||
echo "$TASKNUM $input"
|
echo "$TASKNUM $input"
|
||||||
echo "${PREFIX}: $TASKNUM added."
|
echo "${PREFIX}: $TASKNUM added."
|
||||||
fi
|
fi
|
||||||
@@ -622,12 +622,12 @@ _list() {
|
|||||||
| grep -v "^[ 0-9]\+ *$"
|
| grep -v "^[ 0-9]\+ *$"
|
||||||
)
|
)
|
||||||
if [ "${filter_command}" ]; then
|
if [ "${filter_command}" ]; then
|
||||||
filtered_items=$(echo -ne "$items" | eval ${filter_command})
|
filtered_items=$(echo -n "$items" | eval ${filter_command})
|
||||||
else
|
else
|
||||||
filtered_items=$items
|
filtered_items=$items
|
||||||
fi
|
fi
|
||||||
filtered_items=$(
|
filtered_items=$(
|
||||||
echo -ne "$filtered_items" \
|
echo -n "$filtered_items" \
|
||||||
| sed '''
|
| sed '''
|
||||||
s/^ /00000/;
|
s/^ /00000/;
|
||||||
s/^ /0000/;
|
s/^ /0000/;
|
||||||
@@ -636,17 +636,22 @@ _list() {
|
|||||||
s/^ /0/;
|
s/^ /0/;
|
||||||
''' \
|
''' \
|
||||||
| eval ${TODOTXT_SORT_COMMAND} \
|
| eval ${TODOTXT_SORT_COMMAND} \
|
||||||
| sed '''
|
| awk '''
|
||||||
/^[0-9]\{'$PADDING'\} x /s|^.*|'$COLOR_DONE'&'$DEFAULT'|
|
function highlight(colorVar, color) {
|
||||||
''' \
|
color = ENVIRON[colorVar]
|
||||||
| awk '''{
|
gsub(/\\+033/, "\033", color)
|
||||||
|
return color
|
||||||
|
}
|
||||||
|
{
|
||||||
pos = match($0, /\([A-Z]\)/)
|
pos = match($0, /\([A-Z]\)/)
|
||||||
if( pos > 0 && match($0, /^[0-9]+ x /) != 1 ) {
|
if (match($0, /^[0-9]+ x /)) {
|
||||||
clr=ENVIRON["PRI_" substr($0, pos+1, 1)]
|
print highlight("COLOR_DONE") $0 highlight("DEFAULT")
|
||||||
str = ( clr ? clr : ENVIRON["PRI_X"] ) $0 ENVIRON["DEFAULT"]
|
} else if (pos > 0) {
|
||||||
gsub( /\\+033/, "\033", str) ; print str
|
clr = highlight("PRI_" substr($0, pos+1, 1))
|
||||||
|
print ( clr ? clr : highlight("PRI_X") ) $0 highlight("DEFAULT")
|
||||||
} else { print }
|
} else { print }
|
||||||
}''' \
|
}
|
||||||
|
''' \
|
||||||
| sed '''
|
| sed '''
|
||||||
s/'${HIDE_PRIORITY_SUBSTITUTION:-^}'//g
|
s/'${HIDE_PRIORITY_SUBSTITUTION:-^}'//g
|
||||||
s/'${HIDE_PROJECTS_SUBSTITUTION:-^}'//g
|
s/'${HIDE_PROJECTS_SUBSTITUTION:-^}'//g
|
||||||
@@ -654,13 +659,13 @@ _list() {
|
|||||||
''' \
|
''' \
|
||||||
| eval ${TODOTXT_FINAL_FILTER} \
|
| eval ${TODOTXT_FINAL_FILTER} \
|
||||||
)
|
)
|
||||||
echo -ne "$filtered_items${filtered_items:+\n}"
|
[ "$filtered_items" ] && echo "$filtered_items"
|
||||||
|
|
||||||
if [ $TODOTXT_VERBOSE -gt 0 ]; then
|
if [ $TODOTXT_VERBOSE -gt 0 ]; then
|
||||||
BASE=$(basename "$FILE")
|
BASE=$(basename "$FILE")
|
||||||
PREFIX=$(echo ${BASE%%.[^.]*} | tr [a-z] [A-Z])
|
PREFIX=$(echo ${BASE%%.[^.]*} | tr 'a-z' 'A-Z')
|
||||||
NUMTASKS=$( echo -ne "$filtered_items" | sed -n '$ =' )
|
NUMTASKS=$( echo -n "$filtered_items" | sed -n '$ =' )
|
||||||
TOTALTASKS=$( echo -ne "$items" | sed -n '$ =' )
|
TOTALTASKS=$( echo -n "$items" | sed -n '$ =' )
|
||||||
|
|
||||||
echo "--"
|
echo "--"
|
||||||
echo "${PREFIX}: ${NUMTASKS:-0} of ${TOTALTASKS:-0} tasks shown"
|
echo "${PREFIX}: ${NUMTASKS:-0} of ${TOTALTASKS:-0} tasks shown"
|
||||||
@@ -877,7 +882,7 @@ case $action in
|
|||||||
now=`date '+%Y-%m-%d'`
|
now=`date '+%Y-%m-%d'`
|
||||||
# remove priority once item is done
|
# remove priority once item is done
|
||||||
sed -i.bak $item"s/^(.) //" "$TODO_FILE"
|
sed -i.bak $item"s/^(.) //" "$TODO_FILE"
|
||||||
sed -i.bak $item"s|^|&x $now |" "$TODO_FILE"
|
sed -i.bak $item"s|^|x $now |" "$TODO_FILE"
|
||||||
if [ $TODOTXT_VERBOSE -gt 0 ]; then
|
if [ $TODOTXT_VERBOSE -gt 0 ]; then
|
||||||
newtodo=$(sed "$item!d" "$TODO_FILE")
|
newtodo=$(sed "$item!d" "$TODO_FILE")
|
||||||
echo "$item $newtodo"
|
echo "$item $newtodo"
|
||||||
|
|||||||
Reference in New Issue
Block a user