Discover a single file with the given first-line content and report the * language it was classified as via *out_lang (CBM_LANG_COUNT if unindexed). * Returns true only when temp-dir creation, the file write, and discovery all * succeeded, so callers can assert setup success before asserting the language * -- otherwise a negative expectation (CBM_LANG_COUNT) could pass vacuously * when setup
| 1467 | * -- otherwise a negative expectation (CBM_LANG_COUNT) could pass vacuously |
| 1468 | * when setup silently failed. */ |
| 1469 | static bool shebang_probe(const char *prefix, const char *rel, const char *content, |
| 1470 | CBMLanguage *out_lang) { |
| 1471 | *out_lang = CBM_LANG_COUNT; |
| 1472 | char *base = th_mktempdir(prefix); |
| 1473 | if (!base) { |
| 1474 | return false; |
| 1475 | } |
| 1476 | bool ok = false; |
| 1477 | if (th_write_file(TH_PATH(base, rel), content) == 0) { |
| 1478 | cbm_discover_opts_t opts = {0}; |
| 1479 | cbm_file_info_t *files = NULL; |
| 1480 | int count = 0; |
| 1481 | if (cbm_discover(base, &opts, &files, &count) == 0) { |
| 1482 | *out_lang = discover_lang_of(files, count, rel); |
| 1483 | ok = true; |
| 1484 | } |
| 1485 | cbm_discover_free(files, count); |
| 1486 | } |
| 1487 | th_cleanup(base); |
| 1488 | return ok; |
| 1489 | } |
| 1490 | |
| 1491 | TEST(shebang_direct_python_path) { |
| 1492 | CBMLanguage lang; |
no test coverage detected