summaryrefslogtreecommitdiffstats
path: root/tests/testsuite/directory.rs
diff options
context:
space:
mode:
authorKevin Song <chipbuster@users.noreply.github.com>2019-09-20 11:28:09 -0500
committerMatan Kushner <hello@matchai.me>2019-09-20 12:28:09 -0400
commitc2875d99b678c547c15681e85a4a96d9d264989a (patch)
treec6666e6b453223a97636f731ef3515b11f6d4d57 /tests/testsuite/directory.rs
parentcd892ebb60231cce84bd5c2cfed280571026ad9d (diff)
feat: add support for logical paths in directory (#366)
Adds the ability for starship to display the logical path instead of the physical path.
Diffstat (limited to 'tests/testsuite/directory.rs')
-rw-r--r--tests/testsuite/directory.rs63
1 files changed, 63 insertions, 0 deletions
diff --git a/tests/testsuite/directory.rs b/tests/testsuite/directory.rs
index dce7f7983..25926a240 100644
--- a/tests/testsuite/directory.rs
+++ b/tests/testsuite/directory.rs
@@ -418,3 +418,66 @@ fn directory_in_git_repo_truncate_to_repo_true() -> io::Result<()> {
assert_eq!(expected, actual);
Ok(())
}
+
+#[test]
+#[ignore]
+fn use_logical_and_physical_paths() -> io::Result<()> {
+ /* This test is a bit of a smoke + mirrors trick because all it shows is that
+ the application is reading the PWD envar correctly (if the shell doesn't
+ correctly set PWD, we're still in trouble). */
+ let tmp_dir = Path::new("/tmp/starship/porthole/viewport");
+ let dir = tmp_dir.join("directory");
+ let sym = tmp_dir.join("symlink_to_directory");
+ fs::create_dir_all(&dir)?;
+ // Create a symlink on the appropriate system
+ #[cfg(target_family = "unix")]
+ std::os::unix::fs::symlink(&dir, &sym).unwrap();
+ #[cfg(target_family = "windows")]
+ std::os::windows::fs::symlink_file(&dir, &sym).unwrap();
+
+ // Test when using physical paths
+ let output = common::render_module("directory")
+ .use_config(toml::toml! {
+ [directory]
+ use_logical_path = false
+ })
+ .arg("--path")
+ .arg(&dir)
+ .env(
+ "PWD",
+ "/tmp/starship/porthole/viewport/symlink_to_directory",
+ )
+ .output()?;
+ let actual = String::from_utf8(output.stdout).unwrap();
+
+ let expected = format!(
+ "in {} ",
+ Color::Cyan.bold().paint("porthole/viewport/directory")
+ );
+ assert_eq!(expected, actual);
+
+ // Test when using logical paths
+ let output = common::render_module("directory")
+ .use_config(toml::toml! {
+ [directory]
+ use_logical_path = true
+ })
+ .arg("--path")
+ .arg(&sym)
+ .env(
+ "PWD",
+ "/tmp/starship/porthole/viewport/symlink_to_directory",
+ )
+ .output()?;
+ let actual = String::from_utf8(output.stdout).unwrap();
+
+ let expected = format!(
+ "in {} ",
+ Color::Cyan
+ .bold()
+ .paint("porthole/viewport/symlink_to_directory")
+ );
+ assert_eq!(expected, actual);
+
+ Ok(())
+}