Skip to content

Commit acbd555

Browse files
authored
Merge pull request #3510 from masatake/tutil-more-test-cases
Tutil: add more test cases
2 parents cf1c7c9 + b3e535b commit acbd555

File tree

5 files changed

+47
-11
lines changed

5 files changed

+47
-11
lines changed

extra-cmds/utiltest.c

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,47 @@
88
#include "general.h"
99

1010
#include "acutest.h"
11+
#include "fname.h"
1112
#include "htable.h"
1213
#include "routines.h"
1314
#include <string.h>
1415

15-
void test_htable_update(void)
16+
static void test_fname_absolute(void)
17+
{
18+
char *str;
19+
char *in;
20+
21+
#define T(INPUT,OUTPUT) \
22+
TEST_CHECK((in = eStrdup (INPUT), \
23+
strcmp((str = canonicalizeAbsoluteFileName (in)), OUTPUT) == 0)); \
24+
eFree (in); \
25+
eFree (str)
26+
27+
T("/abc/efg/..", "/abc");
28+
T("/abc/efg/hij/..", "/abc/efg");
29+
T("/abc/efg/../", "/abc");
30+
T("/abc/efg/./", "/abc/efg");
31+
T("/abc/efg/./../.", "/abc");
32+
T("/abc/..", "/");
33+
34+
T("..", "/");
35+
T(".", "/");
36+
T("a", "/a");
37+
T("abc", "/abc");
38+
T("", "/");
39+
40+
T("../a", "/a");
41+
T("../abc", "/abc");
42+
T("./a", "/a");
43+
T("./abc", "/abc");
44+
T("a/../b", "/b");
45+
T("abc/../efg", "/efg");
46+
47+
T("..//////a", "/a");
48+
T("..//..//..//a", "/a");
49+
}
50+
51+
static void test_htable_update(void)
1652
{
1753
hashTable *htable = hashTableNew (3, hashCstrhash, hashCstreq,
1854
eFree, NULL);
@@ -28,12 +64,13 @@ void test_htable_update(void)
2864
hashTableDelete(htable);
2965
}
3066

31-
void test_routines_strrstr(void)
67+
static void test_routines_strrstr(void)
3268
{
3369
TEST_CHECK(strcmp(strrstr("abcdcdb", "cd"), "cdb") == 0);
3470
}
3571

3672
TEST_LIST = {
73+
{ "fname/absolute", test_fname_absolute },
3774
{ "htable/update", test_htable_update },
3875
{ "routines/strrstr", test_routines_strrstr },
3976
{ NULL, NULL } /* zeroed record marking the end of the list */

main/e_msoft.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
#define HAVE_DIRECT_H 1
2121
#define HAVE_STRICMP 1
2222
#define HAVE_STRNICMP 1
23-
#define HAVE_STRSTR 1
2423
#define HAVE_STRERROR 1
2524
#define HAVE__FINDFIRST 1
2625
#define HAVE_FINDNEXT 1

main/fname.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -134,12 +134,10 @@ extern char *canonicalizeAbsoluteFileName (char *fname)
134134
fname [1] = '\0';
135135
return strdup (fname);
136136
}
137-
{
138-
char *r = xMalloc (strlen (fname) + 2, char);
139-
r[0] = '/';
140-
strcpy (r + 1, fname);
141-
return r;
142-
}
137+
char *r = xMalloc (strlen (fname) + 2, char);
138+
r[0] = '/';
139+
strcpy (r + 1, fname);
140+
return r;
143141
}
144142

145143
*next = '\0';

main/fname.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ extern hashTable *canonFnameCacheTableNew (void);
2020
extern const char *canonicalizeRelativeFileName(const char *cwd, size_t cwd_len, const char *input,
2121
hashTable* cache_table);
2222

23-
/* eFree() is for freeing the cstring returned from this function. */
23+
/* eFree() is for freeing the cstring returned from this function.
24+
* This function may modify FNAME[].
25+
*/
2426
extern char *canonicalizeAbsoluteFileName (char *fname);
2527

2628
#endif /* CTAGS_MAIN_FNAME_UTIL_H */

makefiles/testing.mak

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,4 +384,4 @@ tutil: $(UTILTEST_DEP)
384384
fi; \
385385
\
386386
builddir=$$(pwd); \
387-
$$vg $$builddir/$(UTILTEST_TEST)
387+
$$vg $$builddir/$(UTILTEST_TEST) -v

0 commit comments

Comments
 (0)