dte test coverage


Directory: ./
File: src/filetype/directories.c
Date: 2025-02-14 16:55:22
Exec Total Coverage
Lines: 13 13 100.0%
Functions: 2 2 100.0%
Branches: 8 8 100.0%

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