| 573 | #[tokio::test] |
| 574 | async fn test_format_path() { |
| 575 | async fn assert_paths(cwd: &str, path: &str, expected: &str) { |
| 576 | let os = Os::new().await.unwrap(); |
| 577 | let cwd = sanitize_path_tool_arg(&os, cwd); |
| 578 | let path = sanitize_path_tool_arg(&os, path); |
| 579 | let fs = os.fs; |
| 580 | fs.create_dir_all(&cwd).await.unwrap(); |
| 581 | fs.create_dir_all(&path).await.unwrap(); |
| 582 | |
| 583 | let formatted = format_path(&cwd, &path); |
| 584 | |
| 585 | if Path::new(expected).is_absolute() { |
| 586 | // If the expected path is relative, we need to ensure it is relative to the cwd. |
| 587 | let expected = fs.chroot_path_str(expected); |
| 588 | |
| 589 | assert!(formatted == expected, "Expected '{}' to be '{}'", formatted, expected); |
| 590 | |
| 591 | return; |
| 592 | } |
| 593 | |
| 594 | assert!( |
| 595 | formatted.contains(expected), |
| 596 | "Expected '{}' to be '{}'", |
| 597 | formatted, |
| 598 | expected |
| 599 | ); |
| 600 | } |
| 601 | |
| 602 | // Test relative path from src to Downloads (sibling directories) |
| 603 | assert_paths( |