dte test coverage


Directory: ./
File: src/filetype/directories.c
Date: 2025-09-07 23:01:39
Exec Total Coverage
Lines: 15 15 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/firejail/"), CONFIG},
8 {STRN("/etc/nginx/"), NGINX},
9 {STRN("/etc/pam.d/"), CONFIG},
10 {STRN("/etc/sudoers.d/"), CONFIG},
11 };
12
13 24 UNITTEST {
14
2/2
✓ Branch 0 (14→3) taken 120 times.
✓ Branch 1 (14→15) taken 24 times.
144 for (size_t i = 0; i < ARRAYLEN(prefixes); i++) {
15 120 const struct DirPrefixMap *p = &prefixes[i];
16 120 BUG_ON(p->dir_len < STRLEN("/a/b/"));
17 120 BUG_ON(p->dir_len > sizeof(prefixes[0].dir));
18 120 BUG_ON(p->dir[0] != '/');
19 120 BUG_ON(p->dir[p->dir_len - 1] != '/');
20 120 BUG_ON(p->filetype >= NR_BUILTIN_FILETYPES);
21 }
22 24 }
23
24 97 static FileTypeEnum filetype_from_dir_prefix(StringView path)
25 {
26
2/2
✓ Branch 0 (2→7) taken 46 times.
✓ Branch 1 (2→8) taken 51 times.
97 if (path.length < 5) {
27 return NONE;
28 }
29
2/2
✓ Branch 0 (7→3) taken 223 times.
✓ Branch 1 (7→8) taken 43 times.
266 for (size_t i = 0; i < ARRAYLEN(prefixes); i++) {
30 223 const struct DirPrefixMap *p = &prefixes[i];
31
2/2
✓ Branch 0 (4→5) taken 3 times.
✓ Branch 1 (4→6) taken 220 times.
223 if (strview_has_sv_prefix(path, string_view(p->dir, p->dir_len))) {
32 3 return p->filetype;
33 }
34 }
35 return NONE;
36 }
37