Build the smallest real Cargo workspace that exercises the direct parallel * resolve API. crate_a is a declared workspace member, while unlisted is a * graph-visible decoy with the same helper name. That decoy is intentional: * without manifest-aware routing, a bare-name match cannot accidentally make * the test green. The optional crate_b-local helper pins the second failure * mode where
| 3161 | * the test green. The optional crate_b-local helper pins the second failure |
| 3162 | * mode where a confident in-file resolution used to suppress cross-LSP. */ |
| 3163 | static cbm_gbuf_t *run_issue56_parallel_workspace(bool local_decoy) { |
| 3164 | static const char workspace_toml[] = "[workspace]\n" |
| 3165 | "members = [\"crate_a\", \"crate_b\"]\n" |
| 3166 | "resolver = \"2\"\n"; |
| 3167 | static const char crate_a_toml[] = |
| 3168 | "[package]\nname = \"crate_a\"\nversion = \"0.1.0\"\nedition = \"2021\"\n"; |
| 3169 | static const char crate_b_toml[] = |
| 3170 | "[package]\nname = \"crate_b\"\nversion = \"0.1.0\"\nedition = \"2021\"\n" |
| 3171 | "\n[dependencies]\ncrate_a = { path = \"../crate_a\" }\n"; |
| 3172 | static const char crate_a_source[] = "pub fn helper() {}\n"; |
| 3173 | static const char unlisted_source[] = "pub fn helper() {}\n"; |
| 3174 | static const char caller_without_local[] = "fn run() { crate_a::helper(); }\n" |
| 3175 | "fn main() { run(); }\n"; |
| 3176 | static const char caller_with_local[] = "fn helper() {}\n" |
| 3177 | "fn run() { crate_a::helper(); }\n" |
| 3178 | "fn main() { run(); }\n"; |
| 3179 | |
| 3180 | char tmpdir[256]; |
| 3181 | snprintf(tmpdir, sizeof(tmpdir), "/tmp/cbm_issue56_parallel_XXXXXX"); |
| 3182 | if (!cbm_mkdtemp(tmpdir)) |
| 3183 | return NULL; |
| 3184 | |
| 3185 | char crate_a[512]; |
| 3186 | char crate_a_src[512]; |
| 3187 | char crate_b[512]; |
| 3188 | char crate_b_src[512]; |
| 3189 | char unlisted[512]; |
| 3190 | char unlisted_src[512]; |
| 3191 | snprintf(crate_a, sizeof(crate_a), "%s/crate_a", tmpdir); |
| 3192 | snprintf(crate_a_src, sizeof(crate_a_src), "%s/src", crate_a); |
| 3193 | snprintf(crate_b, sizeof(crate_b), "%s/crate_b", tmpdir); |
| 3194 | snprintf(crate_b_src, sizeof(crate_b_src), "%s/src", crate_b); |
| 3195 | snprintf(unlisted, sizeof(unlisted), "%s/unlisted", tmpdir); |
| 3196 | snprintf(unlisted_src, sizeof(unlisted_src), "%s/src", unlisted); |
| 3197 | if (cbm_mkdir(crate_a) != 0 || cbm_mkdir(crate_a_src) != 0 || cbm_mkdir(crate_b) != 0 || |
| 3198 | cbm_mkdir(crate_b_src) != 0 || cbm_mkdir(unlisted) != 0 || cbm_mkdir(unlisted_src) != 0) { |
| 3199 | th_rmtree(tmpdir); |
| 3200 | return NULL; |
| 3201 | } |
| 3202 | |
| 3203 | char root_manifest[512]; |
| 3204 | char crate_a_manifest[512]; |
| 3205 | char crate_b_manifest[512]; |
| 3206 | char crate_a_file[512]; |
| 3207 | char crate_b_file[512]; |
| 3208 | char unlisted_file[512]; |
| 3209 | snprintf(root_manifest, sizeof(root_manifest), "%s/Cargo.toml", tmpdir); |
| 3210 | snprintf(crate_a_manifest, sizeof(crate_a_manifest), "%s/Cargo.toml", crate_a); |
| 3211 | snprintf(crate_b_manifest, sizeof(crate_b_manifest), "%s/Cargo.toml", crate_b); |
| 3212 | snprintf(crate_a_file, sizeof(crate_a_file), "%s/lib.rs", crate_a_src); |
| 3213 | snprintf(crate_b_file, sizeof(crate_b_file), "%s/main.rs", crate_b_src); |
| 3214 | snprintf(unlisted_file, sizeof(unlisted_file), "%s/lib.rs", unlisted_src); |
| 3215 | if (th_write_file(root_manifest, workspace_toml) != 0 || |
| 3216 | th_write_file(crate_a_manifest, crate_a_toml) != 0 || |
| 3217 | th_write_file(crate_b_manifest, crate_b_toml) != 0 || |
| 3218 | th_write_file(crate_a_file, crate_a_source) != 0 || |
| 3219 | th_write_file(crate_b_file, local_decoy ? caller_with_local : caller_without_local) != 0 || |
| 3220 | th_write_file(unlisted_file, unlisted_source) != 0) { |
no test coverage detected