dte test coverage


Directory: ./
File: src/filetype/directories.c
Date: 2024-12-21 16:03: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 taken 72 times.
✓ Branch 1 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 89 static FileTypeEnum filetype_from_dir_prefix(StringView path)
22 {
23
2/2
✓ Branch 0 taken 41 times.
✓ Branch 1 taken 48 times.
89 if (path.length < 5) {
24 return NONE;
25 }
26
2/2
✓ Branch 0 taken 158 times.
✓ Branch 1 taken 38 times.
196 for (size_t i = 0; i < ARRAYLEN(prefixes); i++) {
27
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 155 times.
158 if (strview_has_prefix(&path, prefixes[i].dir)) {
28 3 return prefixes[i].filetype;
29 }
30 }
31 return NONE;
32 }
33