mirror of
https://github.com/Llewellynvdm/starship.git
synced 2024-09-17 00:39:02 +00:00
8239fbd12b
- Create subcommands to be able to print modules independently
- `starship prompt` will print the full prompt
- `starship module <MODULE_NAME>` will print a specific module
e.g. `starship module python`
- Added `--path` flag to print the prompt or modules without being in a specific directory
- Added `--status` flag to provide the status of the last command, instead of requiring it as an argument
- Refactored integration tests to be end-to-end tests, since there was no way in integration tests to set the environment variables for a specific command, which was required for the `username` module
- Moved e2e tests to `tests/testsuite` to allow for a single binary to be built
- Tests will build/run faster
- No more false positives for unused functions
- Added tests for `username`
- Removed codecov + tarpaulin 😢
159 lines
4.4 KiB
Rust
159 lines
4.4 KiB
Rust
use ansi_term::Color;
|
|
use dirs::home_dir;
|
|
use git2::Repository;
|
|
use std::fs;
|
|
use std::io;
|
|
use std::path::Path;
|
|
use tempfile::TempDir;
|
|
|
|
use crate::common;
|
|
|
|
#[test]
|
|
fn home_directory() -> io::Result<()> {
|
|
let output = common::render_module("dir").arg("--path=~").output()?;
|
|
let actual = String::from_utf8(output.stdout).unwrap();
|
|
|
|
let expected = format!("in {} ", Color::Cyan.bold().paint("~"));
|
|
assert_eq!(expected, actual);
|
|
Ok(())
|
|
}
|
|
|
|
#[test]
|
|
#[ignore]
|
|
fn directory_in_home() -> io::Result<()> {
|
|
let dir = home_dir().unwrap().join("starship/engine");
|
|
fs::create_dir_all(&dir)?;
|
|
|
|
let output = common::render_module("dir")
|
|
.arg("--path")
|
|
.arg(dir)
|
|
.output()?;
|
|
let actual = String::from_utf8(output.stdout).unwrap();
|
|
|
|
let expected = format!("in {} ", Color::Cyan.bold().paint("~/starship/engine"));
|
|
assert_eq!(expected, actual);
|
|
Ok(())
|
|
}
|
|
|
|
#[test]
|
|
#[ignore]
|
|
fn truncated_directory_in_home() -> io::Result<()> {
|
|
let dir = home_dir().unwrap().join("starship/engine/schematics");
|
|
fs::create_dir_all(&dir)?;
|
|
|
|
let output = common::render_module("dir")
|
|
.arg("--path")
|
|
.arg(dir)
|
|
.output()?;
|
|
let actual = String::from_utf8(output.stdout).unwrap();
|
|
|
|
let expected = format!(
|
|
"in {} ",
|
|
Color::Cyan.bold().paint("starship/engine/schematics")
|
|
);
|
|
assert_eq!(expected, actual);
|
|
Ok(())
|
|
}
|
|
|
|
#[test]
|
|
fn root_directory() -> io::Result<()> {
|
|
let output = common::render_module("dir").arg("--path=/").output()?;
|
|
let actual = String::from_utf8(output.stdout).unwrap();
|
|
|
|
let expected = format!("in {} ", Color::Cyan.bold().paint("/"));
|
|
assert_eq!(expected, actual);
|
|
Ok(())
|
|
}
|
|
|
|
#[test]
|
|
fn directory_in_root() -> io::Result<()> {
|
|
let output = common::render_module("dir").arg("--path=/tmp").output()?;
|
|
let actual = String::from_utf8(output.stdout).unwrap();
|
|
|
|
let expected = format!("in {} ", Color::Cyan.bold().paint("/tmp"));
|
|
assert_eq!(expected, actual);
|
|
Ok(())
|
|
}
|
|
|
|
#[test]
|
|
#[ignore]
|
|
fn truncated_directory_in_root() -> io::Result<()> {
|
|
let dir = Path::new("/tmp/starship/thrusters/rocket");
|
|
fs::create_dir_all(&dir)?;
|
|
|
|
let output = common::render_module("dir")
|
|
.arg("--path")
|
|
.arg(dir)
|
|
.output()?;
|
|
let actual = String::from_utf8(output.stdout).unwrap();
|
|
|
|
let expected = format!(
|
|
"in {} ",
|
|
Color::Cyan.bold().paint("starship/thrusters/rocket")
|
|
);
|
|
assert_eq!(expected, actual);
|
|
Ok(())
|
|
}
|
|
|
|
#[test]
|
|
#[ignore]
|
|
fn git_repo_root() -> io::Result<()> {
|
|
// TODO: Investigate why git repo related tests fail when the tempdir is within /tmp/...
|
|
// Temporarily making the tempdir within $HOME
|
|
// #[ignore] can be removed after this TODO is addressed
|
|
let tmp_dir = TempDir::new_in(dirs::home_dir().unwrap())?;
|
|
let repo_dir = tmp_dir.path().join("rocket-controls");
|
|
fs::create_dir(&repo_dir)?;
|
|
Repository::init(&repo_dir).unwrap();
|
|
|
|
let output = common::render_module("dir")
|
|
.arg("--path")
|
|
.arg(repo_dir)
|
|
.output()?;
|
|
let actual = String::from_utf8(output.stdout).unwrap();
|
|
|
|
let expected = format!("in {} ", Color::Cyan.bold().paint("rocket-controls"));
|
|
assert_eq!(expected, actual);
|
|
Ok(())
|
|
}
|
|
|
|
#[test]
|
|
#[ignore]
|
|
fn directory_in_git_repo() -> io::Result<()> {
|
|
let tmp_dir = TempDir::new_in(dirs::home_dir().unwrap())?;
|
|
let repo_dir = tmp_dir.path().join("rocket-controls");
|
|
let dir = repo_dir.join("src");
|
|
fs::create_dir_all(&dir)?;
|
|
Repository::init(&repo_dir).unwrap();
|
|
|
|
let output = common::render_module("dir")
|
|
.arg("--path")
|
|
.arg(dir)
|
|
.output()?;
|
|
let actual = String::from_utf8(output.stdout).unwrap();
|
|
|
|
let expected = format!("in {} ", Color::Cyan.bold().paint("rocket-controls/src"));
|
|
assert_eq!(expected, actual);
|
|
Ok(())
|
|
}
|
|
|
|
#[test]
|
|
#[ignore]
|
|
fn truncated_directory_in_git_repo() -> io::Result<()> {
|
|
let tmp_dir = TempDir::new_in(dirs::home_dir().unwrap())?;
|
|
let repo_dir = tmp_dir.path().join("rocket-controls");
|
|
let dir = repo_dir.join("src/meters/fuel-gauge");
|
|
fs::create_dir_all(&dir)?;
|
|
Repository::init(&repo_dir).unwrap();
|
|
|
|
let output = common::render_module("dir")
|
|
.arg("--path")
|
|
.arg(dir)
|
|
.output()?;
|
|
let actual = String::from_utf8(output.stdout).unwrap();
|
|
|
|
let expected = format!("in {} ", Color::Cyan.bold().paint("src/meters/fuel-gauge"));
|
|
assert_eq!(expected, actual);
|
|
Ok(())
|
|
}
|