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

WIP: Update readtags to support escape sequences and fix & improve its testing #1605

Closed
wants to merge 30 commits into from
Closed
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
3d7f38f
readtags: Add support for escape sequences in tag names
b4n Nov 24, 2017
a6e4bde
testing: Don't unconditionally silent test rules
b4n Nov 24, 2017
72fc6df
testing: Define $(SILENT)
b4n Nov 24, 2017
215abb1
roundtrip: Cleanup and fix so it actually does check something
b4n Nov 24, 2017
a9433ab
roundtrip: Try and match unescaped names too
b4n Nov 24, 2017
5692578
Run roundtrip on make check
b4n Nov 24, 2017
d59b3af
roundtrip: Fix running on non-C locales
b4n Nov 24, 2017
378c53e
roundtrip: Try and fix macos compatibility
b4n Nov 24, 2017
c814e65
readtags: Build with coverage support if requested
b4n Nov 24, 2017
21a8b0e
WIP: roundtrip: add debugging output because of Windows
b4n Nov 24, 2017
247a93b
roundtrip: Fix unescaping
b4n Nov 29, 2017
df5e6bd
roundtrip: Fix handling of escaped newlines
b4n Nov 29, 2017
e2dc477
readtags: Don't expect escaped search string
b4n Nov 29, 2017
0714968
roundtirp: Improve message for failing tests
b4n Nov 29, 2017
4bae9ed
fixup! roundtrip: Fix unescaping
b4n Nov 29, 2017
cd6c100
roundtrip: Fix handling of trailing newlines
b4n Nov 29, 2017
2b51abe
fixup! readtags: Add support for escape sequences in tag names
b4n Nov 29, 2017
f7ade0c
roundtrip: Exit on command failure
b4n Nov 29, 2017
0d502b3
circleci: Install find for roundtrip
b4n Nov 30, 2017
e441795
roundtrip: Fix MacOS compatibility
b4n Nov 30, 2017
15fe94c
roundtrip: Fix some escaping cases
b4n Nov 30, 2017
3b19b37
fixup! WIP: roundtrip: add debugging output because of Windows
b4n Nov 30, 2017
386a0a1
roundtrip: Further OSX fixing (hopefully)
b4n Dec 1, 2017
143075b
roundtrip: Add a test case for all escape sequences
b4n Dec 1, 2017
9e56104
roundtrip: Don't hide error output from readtags
b4n Dec 1, 2017
11b9d16
readtags: Add debugging info
b4n Dec 1, 2017
a4f9247
fixup! roundtrip: Further OSX fixing (hopefully)
b4n Dec 2, 2017
168eb2a
roundtrip: Try and workaround AppVeyor/MSYS2 weirdness
b4n Dec 2, 2017
0ed2741
fixup! roundtrip: Try and workaround AppVeyor/MSYS2 weirdness
b4n Dec 2, 2017
341db19
roundtrip: Try and actually fix erroneous MSYS2 path rewrites
b4n Dec 2, 2017
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
1 change: 1 addition & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ bin_PROGRAMS = ctags
if USE_READCMD
bin_PROGRAMS+= readtags
readtags_CPPFLAGS = -I. -I$(srcdir) -I$(srcdir)/main -I$(srcdir)/read
readtags_CFLAGS = $(COVERAGE_CFLAGS)
dist_readtags_SOURCES = $(READTAGS_SRCS) $(READTAGS_HEADS)
readtags_CPPFLAGS += -DQUALIFIER -I$(srcdir)/dsl
dist_readtags_SOURCES += $(QUALIFIER_SRCS) $(QUALIFIER_HEADS)
Expand Down
37 changes: 23 additions & 14 deletions makefiles/testing.mak
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- makefile -*-
.PHONY: check units fuzz noise tmain tinst clean-units clean-tmain clean-gcov run-gcov codecheck cppcheck dicts cspell

check: tmain units
check: tmain units roundtrip

clean-local: clean-units clean-tmain

Expand All @@ -18,13 +18,21 @@ LANGUAGES=
CATEGORIES=
UNITS=

SILENT = $(SILENT_@AM_V@)
SILENT_ = $(SILENT_@AM_DEFAULT_V@)
SILENT_0 = @

V_RUN = $(V_RUN_@AM_V@)
V_RUN_ = $(V_RUN_@AM_DEFAULT_V@)
V_RUN_0 = @echo " RUN $@";

#
# FUZZ Target
#
# SHELL must be dash or bash.
#
fuzz: $(CTAGS_TEST)
@ \
$(V_RUN) \
if test -n "$${ZSH_VERSION+set}"; then set -o SH_WORD_SPLIT; fi; \
if test x$(VG) = x1; then \
VALGRIND=--with-valgrind; \
Expand All @@ -40,7 +48,7 @@ fuzz: $(CTAGS_TEST)
# NOISE Target
#
noise: $(CTAGS_TEST)
@ \
$(V_RUN) \
if test -n "$${ZSH_VERSION+set}"; then set -o SH_WORD_SPLIT; fi; \
if test x$(VG) = x1; then \
VALGRIND=--with-valgrind; \
Expand All @@ -56,7 +64,7 @@ noise: $(CTAGS_TEST)
# CHOP Target
#
chop: $(CTAGS_TEST)
@ \
$(V_RUN) \
if test -n "$${ZSH_VERSION+set}"; then set -o SH_WORD_SPLIT; fi; \
if test x$(VG) = x1; then \
VALGRIND=--with-valgrind; \
Expand All @@ -68,7 +76,7 @@ chop: $(CTAGS_TEST)
--with-timeout=$(TIMEOUT)"; \
$(SHELL) $${c} $(srcdir)/Units
slap: $(CTAGS_TEST)
@ \
$(V_RUN) \
if test -n "$${ZSH_VERSION+set}"; then set -o SH_WORD_SPLIT; fi; \
if test x$(VG) = x1; then \
VALGRIND=--with-valgrind; \
Expand All @@ -84,7 +92,7 @@ slap: $(CTAGS_TEST)
# UNITS Target
#
units: $(CTAGS_TEST)
@ \
$(V_RUN) \
if test -n "$${ZSH_VERSION+set}"; then set -o SH_WORD_SPLIT; fi; \
if test x$(VG) = x1; then \
VALGRIND=--with-valgrind; \
Expand Down Expand Up @@ -115,8 +123,7 @@ clean-units:
# Test main part, not parsers
#
tmain: $(CTAGS_TEST)
@ \
\
$(V_RUN) \
if test -n "$${ZSH_VERSION+set}"; then set -o SH_WORD_SPLIT; fi; \
if test x$(VG) = x1; then \
VALGRIND=--with-valgrind; \
Expand Down Expand Up @@ -144,22 +151,24 @@ clean-tmain:
# Test installation
#
tinst:
@ \
\
$(V_RUN) \
builddir=$$(pwd); \
rm -rf $$builddir/$(TINST_ROOT); \
\
$(SHELL) $(srcdir)/misc/tinst $(srcdir) $$builddir/$(TINST_ROOT)

#
# Test readtags
#
if USE_READCMD
roundtrip: $(READ_TEST)
@ \
\
$(V_RUN) \
builddir=$$(pwd); \
\
$(SHELL) $(srcdir)/misc/roundtrip $(READ_TEST) $${builddir}/Units
else
# apparently Automake doesn't like adding an extra dependency in a conditional,
# so add it unconditionally and simply have it not do anything if it's disabled.
roundtrip:
endif

#
# Checking code in ctags own rules
Expand Down
97 changes: 85 additions & 12 deletions misc/roundtrip
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,13 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

# Avoid trouble with weird bytes on non-C locales
export LC_ALL=C

READTAGS=${1:-./readtags}
UNITS=${2:-./Units}
s=0

sink()
{
cat > /dev/null
}

if ! [ -f "${READTAGS}" ]; then
echo "No such file: ${READTAGS}" 1>&2
exit 1
Expand All @@ -40,16 +38,91 @@ if ! [ -x "${UNITS}" ]; then
fi


# Expand CTags escape sequences (and keep the original, too)
# See docs/format.rst
expandEscapeSequences()
{
sed -e '
# early out if there is no escape sequence (common case)
/\\/!q

# loop until we handled all occurrences of \.
# as it is not possible to do all replacements at once and we need not to
# ever use the result of an replacement to perform another one, use two
# reserved placeholders.
:again
s/\\/__BACKSLASH__/
T out
s/__BACKSLASH__\\/__LITBACKSLASH__/; t again
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you tell me why this change is needed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not needed per se, but I changed the name for clarity as it's not only used for the last backslash but for all literal backslashes

s/__BACKSLASH__t/ /; t again
s/__BACKSLASH__r/'"$(printf '\r')"'/; t again
s/__BACKSLASH__n/\n/; t again
s/__BACKSLASH__a//; t again
s/__BACKSLASH__b/'"$(printf '\b')"'/; t again
s/__BACKSLASH__v/ /; t again
s/__BACKSLASH__f/ /; t again
s/__BACKSLASH__x01//; t again
s/__BACKSLASH__x02//; t again
s/__BACKSLASH__x03//; t again
s/__BACKSLASH__x04//; t again
s/__BACKSLASH__x05//; t again
s/__BACKSLASH__x06//; t again
s/__BACKSLASH__x07//; t again
s/__BACKSLASH__x08//; t again
s/__BACKSLASH__x09/ /; t again
s/__BACKSLASH__x0[aA]/\n/; t again
s/__BACKSLASH__x0[bB]/ /; t again
s/__BACKSLASH__x0[cC]/ /; t again
s/__BACKSLASH__x0[dD]/'"$(printf '\r')"'/; t again
s/__BACKSLASH__x0[eE]//; t again
s/__BACKSLASH__x0[fF]//; t again
s/__BACKSLASH__x10//; t again
s/__BACKSLASH__x11//; t again
s/__BACKSLASH__x12//; t again
s/__BACKSLASH__x13//; t again
s/__BACKSLASH__x14//; t again
s/__BACKSLASH__x15//; t again
s/__BACKSLASH__x16//; t again
s/__BACKSLASH__x17//; t again
s/__BACKSLASH__x18//; t again
s/__BACKSLASH__x19//; t again
s/__BACKSLASH__x1[aA]//; t again
s/__BACKSLASH__x1[bB]//; t again
s/__BACKSLASH__x1[cC]//; t again
s/__BACKSLASH__x1[dD]//; t again
s/__BACKSLASH__x1[eE]//; t again
s/__BACKSLASH__x1[fF]//; t again
s/__BACKSLASH__x21/!/; t again
s/__BACKSLASH__x20/ /; t again
s/__BACKSLASH__x7[fF]//; t again

:out
# replace lonely "\"es
s/__BACKSLASH__/\\/g
# replace literal "\"es ("\\" from the input)
s/__LITBACKSLASH__/\\/g
'
}

# disable path expansion, because we don't need it and it's applied on the
# result of the commands used to loop on, and we don't want that.
set -f
# remove space from IFS as it's valid in tag names
OLD_IFS="$IFS"
IFS='
'
set -x
for tags in $(find "$UNITS" -name expected.tags); do
for t in $(sed -e 's/^\([^\t]*\)\t.*/\1/' "$tags"); do
if r=$( "${READTAGS}" -t "$tags" - "$t" 2>/dev/null ); then
:
else
printf "FAILED[%3d]: " $?
echo "${READTAGS}" -t "$tags" - "$t"
for name in $(sed -e 's/^\([^ ]*\) .*/\1/' "$tags"); do
# don't expand in the loop to handle "\n" sequence properly
t="$(printf '%s' "$name" | expandEscapeSequences)"
if [ 1 -gt $("${READTAGS}" -t "$tags" - "$t" 2>/dev/null | wc -l) ]; then
printf 'FAILED: "%s" -t "%s" - "%s"\n' "${READTAGS}" "$tags" "$t"
s=1
fi
done
done
done

IFS="$OLD_IFS"

exit $s
Loading