dte test coverage


Directory: ./
File: src/filetype/directories.c
Date: 2025-07-13 15:27:15
Exec Total Coverage
Lines: 14 14 100.0%
Functions: 2 2 100.0%
Branches: 8 8 100.0%

Line Branch Exec Source
1 static const struct DirPrefixMap {
2 const char NONSTRING dir[15];
3 uint8_t dir_len;
4 FileTypeEnum filetype;
5 } prefixes[] = {
6 {STRN("/etc/default/"), SH},
7 {STRN("/etc/nginx/"), NGINX},
8 {STRN("/etc/pam.d/"), CONFIG},
9 {STRN("/etc/sudoers.d/"), CONFIG},
10 };
11
12 24 UNITTEST {
13
2/2
✓ Branch 0 (12→3) taken 96 times.
✓ Branch 1 (12→13) taken 24 times.
120 for (size_t i = 0; i < ARRAYLEN(prefixes); i++) {
14 96 const struct DirPrefixMap *p = &prefixes[i];
15 96 BUG_ON(p->dir_len > sizeof(prefixes[0].dir));
16 96 BUG_ON(p->dir[0] != '/');
17 96 BUG_ON(p->dir[p->dir_len - 1] != '/');
18 96 BUG_ON(p->filetype >= NR_BUILTIN_FILETYPES);
19 }
20 24 }
21
22 97 static FileTypeEnum filetype_from_dir_prefix(StringView path)
23 {
24
2/2
✓ Branch 0 (2→7) taken 46 times.
✓ Branch 1 (2→8) taken 51 times.
97 if (path.length < 5) {
25 return NONE;
26 }
27
2/2
✓ Branch 0 (7→3) taken 178 times.
✓ Branch 1 (7→8) taken 43 times.
221 for (size_t i = 0; i < ARRAYLEN(prefixes); i++) {
28 178 const struct DirPrefixMap *p = &prefixes[i];
29
2/2
✓ Branch 0 (4→5) taken 3 times.
✓ Branch 1 (4→6) taken 175 times.
178 if (strview_has_strn_prefix(&path, p->dir, p->dir_len)) {
30 3 return p->filetype;
31 }
32 }
33 return NONE;
34 }
35