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
| 2140 | * -- otherwise a negative expectation (CBM_LANG_COUNT) could pass vacuously |
| 2141 | * when setup silently failed. */ |
| 2142 | static bool shebang_probe(const char *prefix, const char *rel, const char *content, |
| 2143 | CBMLanguage *out_lang) { |
| 2144 | *out_lang = CBM_LANG_COUNT; |
| 2145 | char *base = th_mktempdir(prefix); |
| 2146 | if (!base) { |
| 2147 | return false; |
| 2148 | } |
| 2149 | bool ok = false; |
| 2150 | if (th_write_file(TH_PATH(base, rel), content) == 0) { |
| 2151 | cbm_discover_opts_t opts = {0}; |
| 2152 | cbm_file_info_t *files = NULL; |
| 2153 | int count = 0; |
| 2154 | if (cbm_discover(base, &opts, &files, &count) == 0) { |
| 2155 | *out_lang = discover_lang_of(files, count, rel); |
| 2156 | ok = true; |
| 2157 | } |
| 2158 | cbm_discover_free(files, count); |
| 2159 | } |
| 2160 | th_cleanup(base); |
| 2161 | return ok; |
| 2162 | } |
| 2163 | |
| 2164 | TEST(shebang_direct_python_path) { |
| 2165 | CBMLanguage lang; |
no test coverage detected