dte test coverage


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 50.0% high: ≥ 85.0%
Coverage Exec / Excl / Total
Lines: 100.0% 14 / 0 / 14
Functions: 100.0% 1 / 0 / 1
Branches: 90.9% 20 / 0 / 22

src/filetype/basenames.c
Line Branch Exec Source
1 static const struct FileBasenameMap {
2 const char name[16];
3 uint8_t filetype; // FileTypeEnum
4 bool dotfile; // If true, name is matched with or without a leading dot
5 } basenames[] = {
6 {"APKBUILD", SH, false},
7 {"BSDmakefile", MAKE, false},
8 {"BUILD.bazel", PYTHON, false},
9 {"Brewfile", RUBY, true},
10 {"CMakeLists.txt", CMAKE, false},
11 {"COMMIT_EDITMSG", GITCOMMIT, false},
12 {"Capfile", RUBY, false},
13 {"Cargo.lock", TOML, false},
14 {"DIR_COLORS", CONFIG, false},
15 {"Dangerfile", RUBY, false},
16 {"Dockerfile", DOCKER, false},
17 {"Doxyfile", CONFIG, false},
18 {"GNUmakefile", MAKE, false},
19 {"Gemfile", RUBY, false},
20 {"Gemfile.lock", RUBY, false},
21 {"Guardfile", RUBY, true},
22 {"Kbuild", MAKE, false},
23 {"Kconfig", CONFIG, false},
24 {"Kconfig.debug", CONFIG, false},
25 {"MERGE_MSG", GITCOMMIT, false},
26 {"Makefile", MAKE, false},
27 {"Makefile.am", MAKE, false},
28 {"Makefile.in", MAKE, false},
29 {"NOTES_EDITMSG", GITNOTE, false},
30 {"PKGBUILD", SH, false},
31 {"Pipfile", TOML, false},
32 {"Pipfile.lock", JSON, false},
33 {"Project.ede", LISP, false},
34 {"Puppetfile", RUBY, false},
35 {"Rakefile", RUBY, false},
36 {"Steepfile", RUBY, false},
37 {"Thorfile", RUBY, false},
38 {"Vagrantfile", RUBY, false},
39 {"XCompose", CONFIG, true},
40 {"Xresources", XRESOURCES, true},
41 {"ackrc", CONFIG, true},
42 {"alsoftrc", INI, true}, // https://github.com/kcat/openal-soft/blob/master/alsoftrc.sample
43 {"bash_aliases", SH, true},
44 {"bash_functions", SH, true},
45 {"bash_logout", SH, true},
46 {"bash_profile", SH, true},
47 {"bashrc", SH, true},
48 {"bazelrc", CONFIG, true},
49 {"btop.conf", CONFIG, true},
50 {"build.gradle", GRADLE, false},
51 {"buildozer.spec", INI, false},
52 {"bun.lock", JSONC, false}, // https://bun.sh/blog/bun-lock-text-lockfile#tooling-compatibility
53 {"clang-format", YAML, true},
54 {"clang-tidy", YAML, true},
55 {"colordiffrc", CONFIG, true},
56 {"composer.lock", JSON, false},
57 {"config.ld", LUA, false},
58 {"configure.ac", M4, false},
59 {"coveragerc", INI, true},
60 {"csh.login", CSH, true},
61 {"csh.logout", CSH, true},
62 {"cshdirs", CSH, true},
63 {"cshrc", CSH, true},
64 {"curlrc", CONFIG, true},
65 {"deno.lock", JSON, false},
66 {"dir_colors", CONFIG, true},
67 {"dircolors", CONFIG, true},
68 {"doas.conf", CONFIG, false},
69 {"drirc", XML, true},
70 {"dterc", DTE, true},
71 {"editorconfig", INI, true},
72 {"emacs", LISP, true},
73 {"flake.lock", JSON, false},
74 {"flake8", INI, true},
75 {"fstab", CONFIG, false},
76 {"gdbinit", CONFIG, true},
77 {"gemrc", YAML, true},
78 {"git-rebase-todo", GITREBASE, false},
79 {"gitattributes", CONFIG, true},
80 {"gitconfig", INI, true},
81 {"gitignore", GITIGNORE, true},
82 {"gitmodules", INI, true},
83 {"gnus", LISP, true},
84 {"go.mod", GOMODULE, false},
85 {"hosts", CONFIG, false},
86 {"htmlhintrc", JSON, true},
87 {"indent.pro", INDENT, true},
88 {"inputrc", CONFIG, true},
89 {"ip6tables.rules", CONFIG, false},
90 {"iptables.rules", CONFIG, false},
91 {"jshintrc", JSON, true},
92 {"kitty.conf", CONFIG_NTC, false},
93 {"krb5.conf", INI, false},
94 {"lcovrc", CONFIG, true},
95 {"lesskey", CONFIG, true},
96 {"luacheckrc", LUA, true},
97 {"luacov", LUA, true},
98 {"makefile", MAKE, false},
99 {"mcmod.info", JSON, false},
100 {"menu.lst", CONFIG, false},
101 {"meson.build", MESON, false},
102 {"mimeapps.list", INI, false},
103 {"mkinitcpio.conf", SH, false},
104 {"muttrc", CONFIG, true},
105 {"nanorc", CONFIG, true},
106 {"nftables.conf", NFTABLES, false},
107 {"nginx.conf", NGINX, false},
108 {"pacman.conf", INI, false},
109 {"pdm.lock", TOML, false},
110 {"poetry.lock", TOML, false},
111 {"profile", SH, true},
112 {"pylintrc", INI, true},
113 {"robots.txt", ROBOTSTXT, false},
114 {"rockspec.in", LUA, false},
115 {"shellcheckrc", CONFIG, true},
116 {"shrc", SH, true},
117 {"sudoers", CONFIG, false},
118 {"sxhkdrc", CONFIG, true},
119 {"tags", CTAGS, false},
120 {"tcshrc", CSH, true},
121 {"terminalrc", INI, false},
122 {"terminfo.src", TERMINFO, false},
123 {"texmf.cnf", TEXMFCNF, false},
124 {"tigrc", CONFIG, true},
125 {"tmux.conf", TMUX, true},
126 {"user-dirs.conf", CONFIG, false},
127 {"user-dirs.dirs", CONFIG, false},
128 {"vconsole.conf", CONFIG, false},
129 {"watchmanconfig", JSON, true},
130 {"xinitrc", SH, true},
131 {"xprofile", SH, true},
132 {"xserverrc", SH, true},
133 {"yum.conf", INI, false},
134 {"zlogin", SH, true},
135 {"zlogout", SH, true},
136 {"zprofile", SH, true},
137 {"zshenv", SH, true},
138 {"zshrc", SH, true},
139 };
140
141 216 static FileTypeEnum filetype_from_basename(StringView name)
142 {
143 216 size_t dotprefix = 0;
144
2/2
✓ Branch 3 → 4 taken 187 times.
✓ Branch 3 → 7 taken 29 times.
216 if (strview_has_prefix(name, ".")) {
145 dotprefix = 1;
146
2/2
✓ Branch 5 → 6 taken 6 times.
✓ Branch 5 → 7 taken 181 times.
187 } else if (strview_has_prefix(name, "dot_")) {
147 6 dotprefix = 4;
148 }
149
150 216 strview_remove_prefix(&name, dotprefix);
151
2/2
✓ Branch 8 → 9 taken 141 times.
✓ Branch 8 → 25 taken 75 times.
216 if (name.length < 4) {
152 return NONE;
153 }
154
155
2/2
✓ Branch 9 → 10 taken 6 times.
✓ Branch 9 → 20 taken 135 times.
141 if (name.length >= ARRAYLEN(basenames[0].name)) {
156
2/2
✓ Branch 11 → 12 taken 1 time.
✓ Branch 11 → 15 taken 5 times.
6 if (strview_equal_cstring(name, "meson_options.txt")) {
157
1/2
✓ Branch 12 → 13 taken 1 time.
✗ Branch 12 → 14 not taken.
1 return dotprefix ? NONE : MESON;
158
2/2
✓ Branch 16 → 17 taken 1 time.
✓ Branch 16 → 25 taken 4 times.
5 } else if (strview_equal_cstring(name, "git-blame-ignore-revs")) {
159
1/2
✗ Branch 17 → 18 not taken.
✓ Branch 17 → 19 taken 1 time.
1 return dotprefix ? CONFIG : NONE;
160 }
161 return NONE;
162 }
163
164 135 const struct FileBasenameMap *e = BSEARCH(&name, basenames, ft_compare);
165
6/6
✓ Branch 21 → 22 taken 38 times.
✓ Branch 21 → 25 taken 97 times.
✓ Branch 22 → 23 taken 20 times.
✓ Branch 22 → 24 taken 18 times.
✓ Branch 23 → 24 taken 19 times.
✓ Branch 23 → 25 taken 1 time.
135 return (e && (dotprefix == 0 || e->dotfile)) ? e->filetype : NONE;
166 }
167