1use std::error::Error;
2use std::fmt;
3use std::fs;
4use std::io::ErrorKind;
5use std::path::Path;
6use std::path::PathBuf;
7use std::time::Instant;
8
9use anyhow::Context as _;
10use anyhow::Result;
11use anyhow::ensure;
12use derive_new::new;
13use protobuf::Message as _;
14use serde_json::Map;
15use serde_json::Value;
16
17use crate::analyzer::config::without_test_cfg;
18use crate::analyzer::options::Options as AnalyzerOptions;
19use crate::analyzer::parallel::try_pair;
20use crate::analyzer::prerequisites;
21use crate::analyzer::process::Phase;
22use crate::analyzer::process::ScipProcess;
23use crate::analyzer::repair::IndexRepair;
24use crate::diagnostics::emit;
25use crate::scip::index::ParsedIndex;
26use crate::scip::test_dependencies::mark_test_references;
27
28const NAME_CARGO_MANIFEST: &str = "Cargo.toml";
29const NAME_RUST_PROJECT_FILE: &str = "rust-project.json";
30const MESSAGE_PROJECT_INPUT_ERROR: &str = "Expected a project directory or Cargo.toml";
31const MESSAGE_SCIP_READ_ERROR: &str = "Cannot read SCIP index";
32
33pub trait IndexSource {
34 fn index(&self) -> Result<Vec<u8>>;
35}
36
37#[must_use]
38pub fn contains_project_file(directory: &Path) -> bool {
39 directory.join(NAME_CARGO_MANIFEST).is_file() || directory.join(NAME_RUST_PROJECT_FILE).is_file()
40}
41
42#[derive(new)]
43pub struct RustAnalyzer<'a> {
44 project: &'a Path,
45 configuration_path_original: Option<&'a Path>,
46 options: &'a AnalyzerOptions,
47}
48
49impl IndexSource for RustAnalyzer<'_> {
50 fn index(&self) -> Result<Vec<u8>> {
51 self.index_parsed()?.into_index().write_to_bytes().context("Cannot serialize classified SCIP index")
52 }
53}
54
55impl RustAnalyzer<'_> {
56 pub(crate) fn index_parsed(&self) -> Result<ParsedIndex> {
57 let project = resolve_project_directory(self.project)?;
58 prerequisites::ensure_available(&project)?;
59 let index_directory = tempfile::tempdir().context("Cannot create temporary index directory")?;
60 let index_file_original = index_directory.path().join("original.scip");
61 let index_file_without_test = index_directory.path().join("without_test.scip");
62 let configuration_path_original = self.configuration_path_original.map(dunce::canonicalize).transpose();
63 let configuration_path_original = configuration_path_original.context("Cannot resolve original rust-analyzer config")?;
64 let configuration_original = configuration_path_original.as_ref().map_or_else(
65 || Ok(Value::Object(Map::default())),
66 |path| -> Result<Value> {
67 let contents = fs::read(path).context("Cannot read original rust-analyzer config")?;
68 serde_json::from_slice(&contents).context("Cannot parse original rust-analyzer config")
69 },
70 )?;
71 let configuration_path_without_test = index_directory.path().join("without_test.json");
72 let configuration_without_test = serde_json::to_vec(&without_test_cfg(configuration_original)?)?;
73 let configuration_write_without_test = fs::write(&configuration_path_without_test, configuration_without_test);
74 configuration_write_without_test.context("Cannot write analysis configuration without cfg(test)")?;
75 let analyzer_original = ScipProcess::new(&project, configuration_path_original.as_deref(), self.options);
76 let analyzer_without_test = ScipProcess::new(&project, Some(&configuration_path_without_test), self.options);
77 let indexing_started = Instant::now();
78 emit(format_args!("Analyzing Rust dependencies..."));
79 if self.options.verbose() {
80 emit(format_args!("Indexing original cfg and without cfg(test) in parallel (Cargo may serialize shared builds)..."));
81 }
82 let (index_original, index_without_test) = try_pair(
83 || {
84 let index = analyzer_original.generate_index(&index_file_original, Phase::Original)?;
85 ParsedIndex::parse(&index).context("Cannot decode original dependency index")
86 },
87 || {
88 let index = analyzer_without_test.generate_index(&index_file_without_test, Phase::WithoutTest)?;
89 ParsedIndex::parse(&index).context("Cannot decode dependency index without cfg(test)")
90 },
91 )?;
92 if self.options.verbose() {
93 emit(format_args!("SCIP processes completed in {:.2}s.", indexing_started.elapsed().as_secs_f64()));
94 }
95 let repair = IndexRepair::new(
96 &project, configuration_path_original.as_deref(), &configuration_path_without_test, self.options,
97 );
98 let (index_original, index_without_test) = repair.perform(index_original, index_without_test)?;
99 if self.options.verbose() {
100 emit(format_args!("Comparing SCIP references to classify test dependencies..."));
101 }
102 let classification_started = Instant::now();
103 let classified = mark_test_references(index_original, &index_without_test)?;
104 if self.options.verbose() {
105 emit(format_args!("Test classification completed in {:.2}s.", classification_started.elapsed().as_secs_f64()));
106 }
107 emit(format_args!("Dependency analysis completed in {:.2}s.", indexing_started.elapsed().as_secs_f64()));
108 Ok(classified)
109 }
110}
111
112#[derive(Debug)]
113enum ProjectValidationError {
114 InspectPath(PathBuf),
115 UnsupportedFile(PathBuf),
116 ResolveDirectory(PathBuf),
117 ReadManifest(PathBuf),
118 ReadProjectFile { project_file: PathBuf, directory: PathBuf },
119}
120
121impl fmt::Display for ProjectValidationError {
122 fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
123 match *self {
124 Self::InspectPath(ref path) => write!(formatter, "Cannot inspect Rust project path {}", path.display()),
125 Self::UnsupportedFile(ref path) => write!(formatter, "{MESSAGE_PROJECT_INPUT_ERROR}: {}", path.display()),
126 Self::ResolveDirectory(ref path) => write!(formatter, "Cannot resolve Rust project directory {}", path.display()),
127 Self::ReadManifest(ref path) => write!(formatter, "Cannot read project manifest {}", path.display()),
128 Self::ReadProjectFile { ref project_file, ref directory } => write!(
129 formatter,
130 "Cannot read project file {} after {NAME_CARGO_MANIFEST} was not found in {}",
131 project_file.display(),
132 directory.display()
133 ),
134 }
135 }
136}
137
138impl Error for ProjectValidationError {}
139
140fn resolve_project_directory(project: &Path) -> Result<PathBuf> {
141 let metadata = fs::metadata(project).with_context(|| ProjectValidationError::InspectPath(project.to_path_buf()))?;
142 let directory = if metadata.is_dir() {
143 project
144 } else {
145 ensure!(
146 project.file_name().is_some_and(|name| name == NAME_CARGO_MANIFEST),
147 ProjectValidationError::UnsupportedFile(project.to_path_buf())
148 );
149 project.parent().filter(|parent| !parent.as_os_str().is_empty()).unwrap_or_else(|| Path::new("."))
150 };
151 let directory = dunce::canonicalize(directory).with_context(|| {
152 ProjectValidationError::ResolveDirectory(directory.to_path_buf())
153 })?;
154 let manifest = directory.join(NAME_CARGO_MANIFEST);
155 match fs::read(&manifest) {
156 Ok(_) => {}
157 Err(error) if error.kind() == ErrorKind::NotFound => {
158 let project_file = directory.join(NAME_RUST_PROJECT_FILE);
159 fs::read(&project_file).with_context(|| ProjectValidationError::ReadProjectFile {
160 project_file,
161 directory: directory.clone(),
162 })?;
163 }
164 Err(error) => {
165 return Err(error).context(ProjectValidationError::ReadManifest(manifest));
166 }
167 }
168 Ok(directory)
169}
170
171#[derive(new)]
172pub struct ScipFile {
173 path: PathBuf,
174}
175
176impl IndexSource for ScipFile {
177 fn index(&self) -> Result<Vec<u8>> {
178 fs::read(&self.path).with_context(|| format!("{MESSAGE_SCIP_READ_ERROR} {}", self.path.display()))
179 }
180}
181
182#[cfg(test)]
183mod tests {
184 use std::collections::BTreeSet;
185 use std::fs;
186 use std::io;
187 use std::path::Path;
188 use std::path::PathBuf;
189
190 use claims::assert_ok;
191 use claims::assert_some;
192 use pretty_assertions::assert_eq;
193 use rstest::rstest;
194 use tempfile::tempdir;
195
196 use super::NAME_CARGO_MANIFEST;
197 use super::IndexSource as _;
198 use super::NAME_RUST_PROJECT_FILE;
199 use super::RustAnalyzer;
200 use super::MESSAGE_SCIP_READ_ERROR;
201 use super::ProjectValidationError;
202 use super::ScipFile;
203 use super::contains_project_file;
204 use super::resolve_project_directory;
205 use crate::SourcePath;
206 use crate::analyzer::options::Options;
207 use crate::model::DependencyKind;
208 use crate::model::FileEdge;
209 use crate::model::FileGraph;
210 use crate::model::FileNode;
211 use crate::scip::backend::file_graph;
212 use crate::scip::backend::parse_scip;
213
214 #[rstest]
215 #[case::empty(&[], &[], false)]
216 #[case::cargo(&[NAME_CARGO_MANIFEST], &[], true)]
217 #[case::rust_project(&[NAME_RUST_PROJECT_FILE], &[], true)]
218 #[case::both(&[NAME_CARGO_MANIFEST, NAME_RUST_PROJECT_FILE], &[], true)]
219 #[case::unrelated(&["source.rs"], &[], false)]
220 #[case::directories(&[], &[NAME_CARGO_MANIFEST, NAME_RUST_PROJECT_FILE], false)]
221 #[case::cargo_directory(&[NAME_RUST_PROJECT_FILE], &[NAME_CARGO_MANIFEST], true)]
222 fn test_project_file_detection(#[case] files: &[&str], #[case] directories: &[&str], #[case] expected: bool) {
223 let fixture_creation = tempdir();
224 let fixture = assert_ok!(fixture_creation, "The project-file detection fixture directory must be created");
225 for filename in files {
226 let file_write = fs::write(fixture.path().join(filename), "");
227 assert_ok!(file_write, "The project-file detection fixture must write {filename}");
228 }
229 for directory in directories {
230 let directory_creation = fs::create_dir_all(fixture.path().join(directory));
231 assert_ok!(directory_creation, "The project-file detection fixture must create directory {directory}");
232 }
233
234 let system_under_test = contains_project_file(fixture.path());
235
236 assert_eq!(system_under_test, expected, "Project detection must distinguish supported files from directories");
237 }
238
239 #[rstest]
240 #[case::missing_project(false)]
241 #[case::missing_project_files(true)]
242 fn test_rust_analyzer_index_project_validation(#[case] create_project: bool) {
243 let fixture_creation = tempdir();
244 let fixture = assert_ok!(fixture_creation, "The analyzer project-validation fixture directory must be created");
245 let project = fixture.path().join("project");
246 if create_project {
247 let project_creation = fs::create_dir_all(&project);
248 assert_ok!(project_creation, "The project fixture without project files must be created");
249 }
250 let options = Options::new(false);
251 let system_under_test = RustAnalyzer::new(&project, None, &options);
252
253 let index_generation = system_under_test.index();
254
255 let error = assert_some!(index_generation.err(), "IndexSource::index must reject an invalid project");
256 assert!(
257 error.is::<ProjectValidationError>(),
258 "IndexSource::index must preserve the project-validation error, not a later analyzer failure: {error:#}"
259 );
260 let cause = error.downcast_ref::<io::Error>();
261 let cause = assert_some!(cause, "IndexSource::index must retain the project filesystem error");
262 assert_eq!(cause.kind(), io::ErrorKind::NotFound, "IndexSource::index must reject a missing project or project file");
263 }
264
265 #[rstest]
266 #[case::binary(&[0, 1, 255, 128, 13, 10, 42])]
267 #[case::empty(&[])]
268 fn test_scip_file_bytes(#[case] bytes: &[u8]) {
269 let fixture_creation = tempdir();
270 let fixture = assert_ok!(fixture_creation, "The SCIP byte-preservation fixture directory must be created");
271 let path = fixture.path().join("input.scip");
272 let index_write = fs::write(&path, bytes);
273 assert_ok!(index_write, "The SCIP fixture bytes must be written before reading the index");
274 let system_under_test = ScipFile::new(path);
275
276 let index_read = system_under_test.index();
277 let index = assert_ok!(index_read, "The file adapter must read the SCIP fixture bytes");
278
279 assert_eq!(index, bytes, "The file adapter must preserve bytes without decoding or rewriting them");
280 }
281
282 #[rstest]
283 #[case::missing(false)]
284 #[case::directory(true)]
285 fn test_scip_file_read_failure(#[case] unreadable_directory: bool) {
286 let fixture_creation = tempdir();
287 let fixture = assert_ok!(fixture_creation, "The SCIP read-failure fixture directory must be created");
288 let path = fixture.path().join("input.scip");
289 if unreadable_directory {
290 let directory_creation = fs::create_dir_all(&path);
291 assert_ok!(directory_creation, "The unreadable SCIP fixture must contain a directory at the index path");
292 }
293 let expected_message = format!("{MESSAGE_SCIP_READ_ERROR} {}", path.display());
294 let system_under_test = ScipFile::new(path);
295
296 let index_read = system_under_test.index();
297
298 let error = index_read.as_ref().err();
299 let error = assert_some!(error, "A missing SCIP file or directory at the index path must fail to read");
300 assert_eq!(error.to_string(), expected_message, "SCIP read errors must identify the requested index path");
301 let cause = error.downcast_ref::<io::Error>();
302 let cause = assert_some!(cause, "SCIP read errors must retain their filesystem cause");
303 assert_eq!(cause.kind() == io::ErrorKind::NotFound, !unreadable_directory, "Missing and unreadable indexes must differ");
304 }
305
306 #[rstest]
307 #[case::directory(false)]
308 #[case::manifest(true)]
309 fn test_project_directory_selection(#[case] manifest_input: bool) {
310 let (system_under_test, expected) = {
311 let fixture_creation = tempdir();
312 let fixture = assert_ok!(fixture_creation, "The project-directory selection fixture must be created");
313 let manifest = fixture.path().join(NAME_CARGO_MANIFEST);
314 let manifest_write = fs::write(&manifest, "");
315 assert_ok!(manifest_write, "The project-directory selection fixture must contain a Cargo manifest");
316 let project = if manifest_input { &manifest } else { fixture.path() };
317 let project_resolution = resolve_project_directory(project);
318 let directory = assert_ok!(project_resolution, "A project directory or its manifest must resolve successfully");
319 let fixture_resolution = dunce::canonicalize(fixture.path());
320 let expected = assert_ok!(fixture_resolution, "The selected project fixture must have a canonical path");
321 (directory, expected)
322 };
323
324 assert_eq!(system_under_test, expected, "Project input must select its canonical directory");
325 }
326
327 #[test]
328 fn test_project_path_io_error() {
329 let system_under_test = {
330 let fixture_creation = tempdir();
331 let fixture = assert_ok!(fixture_creation, "The missing-project-path fixture directory must be created");
332 resolve_project_directory(&fixture.path().join("missing"))
333 };
334
335 assert!(
336 system_under_test.is_err_and(|error| {
337 error.downcast_ref::<io::Error>().is_some_and(|cause| cause.kind() == io::ErrorKind::NotFound)
338 }),
339 "Missing project path lost its filesystem error"
340 );
341 }
342
343 #[test]
344 fn test_rust_project_file() {
345 let (system_under_test, expected) = {
346 let fixture_creation = tempdir();
347 let fixture = assert_ok!(fixture_creation, "The rust-project.json fixture directory must be created");
348 let project_file_write = fs::write(fixture.path().join(NAME_RUST_PROJECT_FILE), "{}");
349 assert_ok!(project_file_write, "The rust-project.json fixture must be written before project resolution");
350 let project_resolution = resolve_project_directory(fixture.path());
351 let directory = assert_ok!(project_resolution, "A rust-project.json project must resolve without a manifest");
352 let fixture_resolution = dunce::canonicalize(fixture.path());
353 let expected = assert_ok!(fixture_resolution, "The rust-project.json fixture must have a canonical path");
354 (directory, expected)
355 };
356
357 assert_eq!(system_under_test, expected, "A rust-project.json project must select its canonical directory");
358 }
359
360 #[rstest]
361 #[case::manifest(NAME_CARGO_MANIFEST)]
362 #[case::rust_project(NAME_RUST_PROJECT_FILE)]
363 fn test_project_file_read_error(#[case] filename: &str) {
364 let system_under_test = {
365 let fixture_creation = tempdir();
366 let fixture = assert_ok!(fixture_creation, "The unreadable project-file fixture directory must be created");
367 let directory_creation = fs::create_dir_all(fixture.path().join(filename));
368 assert_ok!(directory_creation, "The project fixture must contain a directory at the {filename} file path");
369 resolve_project_directory(fixture.path())
370 };
371
372 assert!(
373 system_under_test.is_err_and(|error| {
374 error.downcast_ref::<io::Error>().is_some_and(|cause| cause.kind() != io::ErrorKind::NotFound)
375 }),
376 "An unreadable project file was reported as a missing file"
377 );
378 }
379
380 #[test]
381 fn test_missing_project_files() {
382 let system_under_test = {
383 let fixture_creation = tempdir();
384 let fixture = assert_ok!(fixture_creation, "The project fixture without project files must be created");
385 resolve_project_directory(fixture.path())
386 };
387
388 assert!(
389 system_under_test.is_err_and(|error| {
390 error.downcast_ref::<io::Error>().is_some_and(|cause| cause.kind() == io::ErrorKind::NotFound)
391 }),
392 "A directory without project files lost its missing-file error"
393 );
394 }
395
396 #[test]
397 fn test_non_manifest_project_file() {
398 let fixture_creation = tempdir();
399 let fixture = assert_ok!(fixture_creation, "The non-manifest project-file fixture directory must be created");
400 let project = fixture.path().join("source.rs");
401 let source_write = fs::write(&project, "");
402 assert_ok!(source_write, "The non-manifest source file must exist before project resolution");
403
404 let system_under_test = resolve_project_directory(&project);
405
406 let error = assert_some!(system_under_test.err(), "A non-manifest project file must be rejected");
407 let validation_error = error.downcast_ref::<ProjectValidationError>();
408 let validation_error = assert_some!(validation_error, "Project validation must retain its failure context: {error:#}");
409 assert!(
410 matches!(*validation_error, ProjectValidationError::UnsupportedFile(ref path) if path == &project),
411 "Project validation must reject the supplied file as unsupported, not fail for an unrelated reason: {error:#}"
412 );
413 }
414
415 #[must_use]
416 fn analyzer_fixture() -> (PathBuf, Options) {
417 (PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("src").join("fixtures"), Options::new(false))
418 }
419
420 #[test]
421 #[ignore = "slow multi-pass rust-analyzer indexing; excluded to keep default tests fast; \
422 run Test-All.ps1 from the repository root"]
423 fn test_rust_analyzer_generated_method_dependencies() {
424 let (fixture, options) = analyzer_fixture();
425 let project = fixture.join("generated-methods");
426 let source_directory = Path::new("src");
427 let client_path_result = SourcePath::new(source_directory.join("client.rs"));
428 let client_path = assert_ok!(client_path_result, "The generated-method caller must have a valid source path");
429 let client = FileNode::new(client_path);
430 let factory_path_result = SourcePath::new(source_directory.join("factory.rs"));
431 let factory_path = assert_ok!(factory_path_result, "The generated-method factory must have a valid source path");
432 let factory = FileNode::new(factory_path);
433 let model_path_result = SourcePath::new(source_directory.join("model.rs"));
434 let model_path = assert_ok!(model_path_result, "The generated-method model must have a valid source path");
435 let model = FileNode::new(model_path);
436 let validation_path_result = SourcePath::new(source_directory.join("validation.rs"));
437 let validation_path = assert_ok!(validation_path_result, "The generated-method test caller path must be valid");
438 let validation = FileNode::new(validation_path);
439 let expected = BTreeSet::from([
440 FileEdge::new(client.clone(), factory.clone(), DependencyKind::Production),
441 FileEdge::new(client, model.clone(), DependencyKind::Production),
442 FileEdge::new(factory.clone(), model.clone(), DependencyKind::Production),
443 FileEdge::new(validation.clone(), factory, DependencyKind::Test),
444 FileEdge::new(validation, model, DependencyKind::Test),
445 ]);
446 let system_under_test = RustAnalyzer::new(&project, None, &options);
447
448 let index_generation = system_under_test.index_parsed();
449 let index = assert_ok!(index_generation, "rust-analyzer must index the generated-method fixture");
450 let graph_build = file_graph(&index);
451 let graph = assert_ok!(graph_build, "The generated-method index must produce a file dependency graph");
452
453 assert_eq!(
454 graph.edges(),
455 &expected,
456 "Calls to generated accessors must retain their defining file and test classification"
457 );
458 }
459
460 #[test]
461 #[ignore = "slow multi-pass rust-analyzer indexing; excluded to keep default tests fast; \
462 run Test-All.ps1 from the repository root"]
463 fn test_rust_analyzer_cargo_target_collisions() {
464 let (fixture, options) = analyzer_fixture();
465 let project = fixture.join("cargo-targets");
466 let library_path_result = SourcePath::new(Path::new("src").join("library.rs"));
467 let library_path = assert_ok!(library_path_result, "The shared Cargo library must have a valid source path");
468 let library = FileNode::new(library_path);
469 let first_binary_path_result = SourcePath::new(Path::new("src").join("bin").join("first.rs"));
470 let first_binary_path = assert_ok!(first_binary_path_result, "The first Cargo binary path must be valid");
471 let second_binary_path_result = SourcePath::new(Path::new("src").join("bin").join("second.rs"));
472 let second_binary_path = assert_ok!(second_binary_path_result, "The second Cargo binary path must be valid");
473 let expected = BTreeSet::from([
474 FileEdge::new(FileNode::new(first_binary_path), library.clone(), DependencyKind::Production),
475 FileEdge::new(FileNode::new(second_binary_path), library, DependencyKind::Production),
476 ]);
477 let system_under_test = RustAnalyzer::new(&project, None, &options);
478
479 let index_generation = system_under_test.index_parsed();
480 let index = assert_ok!(index_generation, "rust-analyzer must index the colliding Cargo targets");
481 let graph_build = file_graph(&index);
482 let graph = assert_ok!(graph_build, "The Cargo-target index must produce a file dependency graph");
483
484 assert_eq!(
485 graph.edges(),
486 &expected,
487 "Cargo target collisions must not create links between binaries or hide library calls"
488 );
489 }
490 #[test]
491 #[ignore = "slow multi-pass rust-analyzer indexing; excluded to keep default tests fast; \
492 run Test-All.ps1 from the repository root"]
493 fn test_rust_analyzer_manifest_file_graph() {
494 let (fixture, options) = analyzer_fixture();
495 let manifest = fixture.join("dependency-graph").join(NAME_CARGO_MANIFEST);
496 let expected = {
497 let fixture_read = ScipFile::new(fixture.join("dependency-graph.scip")).index();
498 let expected_index = assert_ok!(fixture_read, "The checked-in dependency-graph SCIP fixture must be readable");
499 let fixture_parse = parse_scip(&expected_index);
500 assert_ok!(fixture_parse, "The checked-in SCIP fixture must produce the expected dependency graph")
501 };
502 let system_under_test = RustAnalyzer::new(&manifest, None, &options);
503
504 let index_generation = system_under_test.index();
505 let index = assert_ok!(index_generation, "rust-analyzer must index a project selected by its Cargo manifest");
506 let index_parse = parse_scip(&index);
507 let graph = assert_ok!(index_parse, "The analyzer index bytes must parse into a file dependency graph");
508
509 assert_eq!(graph.files(), expected.files(), "rust-analyzer indexing changed fixture files");
510 assert_eq!(graph.edges(), expected.edges(), "rust-analyzer indexing changed fixture dependencies");
511 }
512
513 #[test]
514 #[ignore = "slow multi-pass rust-analyzer indexing; excluded to keep default tests fast; \
515 run Test-All.ps1 from the repository root"]
516 fn test_rust_analyzer_test_configuration_classification() {
517 let (fixture, options) = analyzer_fixture();
518 let manifest = fixture.join("test-dependencies").join(NAME_CARGO_MANIFEST);
519 let source_directory = Path::new("src");
520 let module_file = "mod.rs";
521 let client_path_result = SourcePath::new(source_directory.join("client").join("calls.rs"));
522 let client_path = assert_ok!(client_path_result, "The classified fixture caller must have a valid source path");
523 let client = FileNode::new(client_path);
524 let shared_path_result = SourcePath::new(source_directory.join("shared").join("value.rs"));
525 let shared_path = assert_ok!(shared_path_result, "The classified fixture shared value must have a valid path");
526 let shared = FileNode::new(shared_path);
527 let test_only_path_result = SourcePath::new(source_directory.join("test_only").join("value.rs"));
528 let test_only_path = assert_ok!(test_only_path_result, "The classified fixture test-only value path must be valid");
529 let test_only = FileNode::new(test_only_path);
530 let validation_path_result = SourcePath::new(source_directory.join("validation").join("checks.rs"));
531 let validation_path = assert_ok!(validation_path_result, "The classified fixture validation path must be valid");
532 let validation = FileNode::new(validation_path);
533 let library_path_result = SourcePath::new(source_directory.join("lib.rs"));
534 let library = assert_ok!(library_path_result, "The classified fixture library must have a valid source path");
535 let client_module_result = SourcePath::new(source_directory.join("client").join(module_file));
536 let client_module = assert_ok!(client_module_result, "The classified fixture client module path must be valid");
537 let shared_module_result = SourcePath::new(source_directory.join("shared").join(module_file));
538 let shared_module = assert_ok!(shared_module_result, "The classified fixture shared module path must be valid");
539 let test_only_module_result = SourcePath::new(source_directory.join("test_only").join(module_file));
540 let test_only_module = assert_ok!(test_only_module_result, "The classified fixture test-only module path must be valid");
541 let expected_graph_build = FileGraph::new(
542 BTreeSet::from([
543 FileNode::new(library),
544 FileNode::new(client_module),
545 FileNode::new(shared_module),
546 FileNode::new(test_only_module),
547 client.clone(),
548 shared.clone(),
549 test_only.clone(),
550 validation.clone(),
551 ]),
552 BTreeSet::from([
553 FileEdge::new(client.clone(), shared.clone(), DependencyKind::Production),
554 FileEdge::new(client.clone(), shared, DependencyKind::Test),
555 FileEdge::new(client, test_only.clone(), DependencyKind::Test),
556 FileEdge::new(validation, test_only, DependencyKind::Test),
557 ]),
558 );
559 let expected = assert_ok!(expected_graph_build, "Expected classified dependencies must form a valid file graph");
560 let system_under_test = RustAnalyzer::new(&manifest, None, &options);
561
562 let index_generation = system_under_test.index_parsed();
563 let index = assert_ok!(index_generation, "rust-analyzer must index the test-configuration fixture");
564 let graph_build = file_graph(&index);
565 let graph = assert_ok!(graph_build, "The classified analyzer index must produce a file dependency graph");
566
567 assert_eq!(graph.files(), expected.files(), "rust-analyzer analysis changed classified fixture files");
568 assert_eq!(graph.edges(), expected.edges(), "rust-analyzer analysis changed classified fixture dependencies");
569 }
570}