logo

utils

~/.local/bin tools and git-hooks git clone https://hacktivis.me/git/utils.git
commit: 4e3854cb75cdf223504b10d73aeb0981218d4ea0
parent d270ca83b129714c7b6168bd0b571b0633272784
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Wed,  2 Mar 2022 19:17:56 +0100

test-bin/basename: Add tests on doubledash

Diffstat:

Mbin/basename.c4++--
Mtest-bin/basename10++++++++++
2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/bin/basename.c b/bin/basename.c @@ -5,7 +5,7 @@ #include <assert.h> // assert() #include <libgen.h> // basename() #include <stdio.h> // fprintf(), puts(), perror() -#include <string.h> // strlen(), strcmp() +#include <string.h> // strlen(), strncmp() static char * suffix_basename(char *name, char *suffix) @@ -30,7 +30,7 @@ main(int argc, char *argv[]) { int ret = 0; - if((argc > 1) && (strcmp(argv[1], "--") == 0)) + if((argc > 1) && (strncmp(argv[1], "--", 3) == 0)) { argv++; argc--; diff --git a/test-bin/basename b/test-bin/basename @@ -50,6 +50,14 @@ nullarg_body() { atf_check -e "inline:bin\n" ../bin/basename "/usr/bin" "$(printf '\x00')" } +atf_test_case doubledash +doubledash_body() { + atf_check -o 'inline:-\n' -- ../bin/basename '-' + atf_check -o 'inline:.\n' -- ../bin/basename '--' + atf_check -o 'inline:--\n' -- ../bin/basename --a a + atf_check -o 'inline:---\n' -- ../bin/basename '---' +} + atf_init_test_cases() { cd "$(atf_get_srcdir)" || exit 1 atf_add_test_case noargs @@ -64,4 +72,6 @@ atf_init_test_cases() { # Broken behavior in ATF, might be caused by stripping out \x00 #atf_add_test_case nullarg + + atf_add_test_case doubledash }