From f975557c3365e71490b3ae8002d711af4a6f6adf Mon Sep 17 00:00:00 2001 From: Laurent Mazet Date: Thu, 12 Jan 2023 15:31:08 +0100 Subject: [PATCH] full test converage --- hexdump.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/hexdump.c b/hexdump.c index cc29414..e6d5191 100644 --- a/hexdump.c +++ b/hexdump.c @@ -270,6 +270,7 @@ int specialchar (char *s, char *b) { case 'r': l = 0x0d; i += 2; break; case 't': l = 0x09; i += 2; break; case 'v': l = 0x0b; i += 2; break; + case '/': l = '/'; i += 2; break; case '\\': l = '\\'; i += 2; break; case '\'': l = '\''; i += 2; break; case '"': l = '"'; i += 2; break; @@ -411,7 +412,10 @@ int main (int argc, char *argv[]) case '/': /* read patern */ seq.sequence = commands; while (*commands) { - if (*commands == '/') { + if ((*commands == '\\') && + ((commands[1] == '/') || (commands[1] == '\\'))) { + commands++; + } else if (*commands == '/') { *commands++ = 0; break; } @@ -451,7 +455,7 @@ int main (int argc, char *argv[]) commands++; break; } else { - VERBOSE (ERROR, fprintf (stderr, "unkown print length (%s)\n", commands)); + VERBOSE (ERROR, fprintf (stderr, "unknown print length (%s)\n", commands)); rc = 1; break; } @@ -489,18 +493,28 @@ int main (int argc, char *argv[]) } // test: hexdump.exe -h | awk '/usage:/ { rc=1 } END { exit (1-rc) }' +// test: hexdump.exe foo 2>&1 | grep -q 'invalid option' +// test: hexdump.exe -n 2>&1 | grep -q 'missing number of columns' +// test: hexdump.exe -v 2>&1 | grep -q 'missing verbose level' // test: hexdump.exe -_ 2> /dev/null | awk 'END { if (NR == 0) { exit(0) } else exit (1) }' // test: hexdump.exe -_ 2>&1 | awk '/usage:/ { rc=1 } END { exit (1-rc) }' // test: hexdump.exe -i hexdump.c | grep -q '0x[0-9a-f]*: ' +// test: hexdump.exe -i hexdump.ko 2>&1 | grep -q "can't open file" +// test: hexdump.exe -i hexdump.c -o ko/test.c 2>&1 | grep -q "can't open file" +// test: cat hexdump.c | hexdump.exe -n 3 | head -2 | tail -1 | grep -q '0x000003: 64 65 70 dep' // test: hexdump.exe -i hexdump.c -n 3 | head -2 | tail -1 | grep -q '0x0003: 64 65 70 dep' // test: hexdump.exe -i hexdump.c -o test.c -e 'p 200' | tail -1 | grep -q '0x00c0:' // test: cmp hexdump.c test.c; x=$?; rm test.c; test x$x = x0 -// test: hexdump.exe -i hexdump.c -e ' /cflags/ p 17 /debug/ p 8' | grep -q '0x0019: 2a 2f 0a 2f 2a 20 6c 69 \*/\./\* li' +// test: hexdump.exe -i hexdump.c -e ' /cflags/ p 17 /debug/ p 8' | grep -q '0x0019: 2a 2f 0a 2f 2a 20 6c 69 \*\/\./\* li' // test: hexdump.exe -i hexdump.c -o test.c -e ' /cfl\x61gs/ p 16 /d\145bug/ p 8' | grep -q '0x0027: 64 65 62 75 67 2e 6f 20 debug.o' // test: cmp hexdump.c test.c; x=$?; rm test.c; test x$x = x0 // test: hexdump.exe -i hexdump.c -e ' /\n/ p 8' | grep -q '0x000d: 0a 2f 2a 20 63 66 6c 61 \./\* cfla' // test: hexdump.exe -i hexdump.c -o test.c -e ' /\a\b\e\f\r\t\v/ p 8'; x=$?; test x$x = x1 // test: cmp hexdump.c test.c; x=$?; rm test.c; test x$x = x0 -// test: hexdump.exe -i hexdump.c -e ' /\"/' -e " /\\'/" -e ' /\\/' +// test: hexdump.exe -i hexdump.c -v 3 -e " /\'/" -e ' /\"/' -e ' /\\/' -e ' /\x2a/' -e ' s/\x3A/' | grep l: | wc -l | xargs test 5 = +// test: hexdump.exe -i hexdump.c -e ' /\n\/* vim:/ p -' | grep -q ': 74 3a 20 2a 2f 0a *t: \*\/\.' +// test: hexdump.exe -i hexdump.c -e 'p go_to_end' 2>&1 | grep -q 'unknown print length' +// test: hexdump.exe -i hexdump.c -e '//' 2>&1 | grep -q 'incorrect sequence' +// test: hexdump.exe -i hexdump.c -e 'foo' 2>&1 | grep -q 'unknown command' /* vim: set ts=4 sw=4 et: */ -- 2.30.2