MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / cbm_is_test_file

Function cbm_is_test_file

internal/cbm/helpers.c:292–351  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

290}
291
292bool cbm_is_test_file(const char *rel_path, CBMLanguage lang) {
293 if (!rel_path) {
294 return false;
295 }
296 const char *base = path_basename(rel_path);
297
298 /* Directory-based, language-agnostic: a file under a conventional test
299 * directory is a test file regardless of its own basename (e.g.
300 * tests/helpers/fixtures.c, which no per-language suffix/prefix rule
301 * below would otherwise catch). Mirrors the directory set cbm_is_test_path
302 * (src/pipeline/pass_tests.c) already uses for TESTS-edge detection, so
303 * the extraction-time is_test_file flag agrees with it (#1294). */
304 if (strstr(rel_path, "__tests__/") || strstr(rel_path, "/tests/") ||
305 strstr(rel_path, "/test/") || strstr(rel_path, "/spec/") ||
306 has_prefix(rel_path, "tests/") || has_prefix(rel_path, "test/") ||
307 has_prefix(rel_path, "spec/") || has_prefix(rel_path, "__tests__/")) {
308 return true;
309 }
310
311 switch (lang) {
312 case CBM_LANG_GO:
313 return has_suffix(base, "_test.go");
314 case CBM_LANG_PYTHON:
315 return has_prefix(base, "test_") || has_suffix(base, "_test.py");
316 case CBM_LANG_JAVASCRIPT:
317 case CBM_LANG_TYPESCRIPT:
318 case CBM_LANG_TSX: {
319 char noext[NOEXT_BUF];
320 strip_ext(base, noext, sizeof(noext));
321 return has_suffix(noext, ".test") || has_suffix(noext, ".spec") ||
322 has_suffix(noext, "_test") || has_suffix(noext, "_spec") ||
323 has_prefix(base, "test_");
324 }
325 case CBM_LANG_JAVA:
326 case CBM_LANG_KOTLIN:
327 case CBM_LANG_SCALA:
328 return has_suffix(base, "Test.java") || has_suffix(base, "Tests.java") ||
329 has_suffix(base, "Spec.java") || has_suffix(base, "Test.kt") ||
330 has_suffix(base, "Spec.kt") || has_suffix(base, "Test.scala") ||
331 has_suffix(base, "Spec.scala");
332 case CBM_LANG_RUST:
333 // Rust tests are typically mod tests inside the file, but test files too
334 return has_suffix(base, "_test.rs") || has_prefix(base, "test_");
335 case CBM_LANG_RUBY:
336 return has_suffix(base, "_test.rb") || has_suffix(base, "_spec.rb") ||
337 has_prefix(base, "test_");
338 case CBM_LANG_PHP:
339 return has_suffix(base, "Test.php");
340 case CBM_LANG_CSHARP:
341 return has_suffix(base, "Tests.cs") || has_suffix(base, "Test.cs");
342 case CBM_LANG_CPP:
343 case CBM_LANG_C:
344 return has_suffix(base, "_test.c") || has_suffix(base, "_test.cc") ||
345 has_suffix(base, "_test.cpp") || has_prefix(base, "test_");
346 case CBM_LANG_MATLAB:
347 return has_prefix(base, "test_") || has_prefix(base, "Test");
348 default:
349 return false;

Callers 1

cbm_extract_file_exFunction · 0.85

Calls 4

has_prefixFunction · 0.85
has_suffixFunction · 0.85
path_basenameFunction · 0.70
strip_extFunction · 0.70

Tested by

no test coverage detected