mirror of
https://github.com/Llewellynvdm/starship.git
synced 2024-11-28 07:46:28 +00:00
fix: Fix issues with nodejs and golang configuration (#146)
* fix: Give all modules a single name * test: Add missing config tests for nodejs and golang * test: Rename dir to directory
This commit is contained in:
parent
589b6cf712
commit
7424e9674c
@ -30,7 +30,7 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
|
|||||||
const GO_CHAR: &str = "🐹 ";
|
const GO_CHAR: &str = "🐹 ";
|
||||||
let module_color = Color::Cyan.bold();
|
let module_color = Color::Cyan.bold();
|
||||||
|
|
||||||
let mut module = context.new_module("go")?;
|
let mut module = context.new_module("golang")?;
|
||||||
module.set_style(module_color);
|
module.set_style(module_color);
|
||||||
|
|
||||||
let formatted_version = format_go_version(&go_version)?;
|
let formatted_version = format_go_version(&go_version)?;
|
||||||
|
@ -18,12 +18,12 @@ use crate::module::Module;
|
|||||||
|
|
||||||
pub fn handle<'a>(module: &str, context: &'a Context) -> Option<Module<'a>> {
|
pub fn handle<'a>(module: &str, context: &'a Context) -> Option<Module<'a>> {
|
||||||
match module {
|
match module {
|
||||||
"dir" | "directory" => directory::module(context),
|
"directory" => directory::module(context),
|
||||||
"char" | "character" => character::module(context),
|
"character" => character::module(context),
|
||||||
"node" | "nodejs" => nodejs::module(context),
|
"nodejs" => nodejs::module(context),
|
||||||
"rust" | "rustlang" => rust::module(context),
|
"rust" => rust::module(context),
|
||||||
"python" => python::module(context),
|
"python" => python::module(context),
|
||||||
"go" | "golang" => golang::module(context),
|
"golang" => golang::module(context),
|
||||||
"line_break" => line_break::module(context),
|
"line_break" => line_break::module(context),
|
||||||
"package" => package::module(context),
|
"package" => package::module(context),
|
||||||
"git_branch" => git_branch::module(context),
|
"git_branch" => git_branch::module(context),
|
||||||
|
@ -26,7 +26,7 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
|
|||||||
const NODE_CHAR: &str = "⬢ ";
|
const NODE_CHAR: &str = "⬢ ";
|
||||||
let module_color = Color::Green.bold();
|
let module_color = Color::Green.bold();
|
||||||
|
|
||||||
let mut module = context.new_module("node")?;
|
let mut module = context.new_module("nodejs")?;
|
||||||
module.set_style(module_color);
|
module.set_style(module_color);
|
||||||
|
|
||||||
let formatted_version = node_version.trim();
|
let formatted_version = node_version.trim();
|
||||||
|
@ -1,8 +1,5 @@
|
|||||||
use ansi_term::Color;
|
use ansi_term::Color;
|
||||||
use std::fs;
|
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::path::Path;
|
|
||||||
use tempfile::TempDir;
|
|
||||||
|
|
||||||
use crate::common::{self, TestCommand};
|
use crate::common::{self, TestCommand};
|
||||||
|
|
||||||
|
@ -10,7 +10,9 @@ use crate::common::{self, TestCommand};
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn home_directory() -> io::Result<()> {
|
fn home_directory() -> io::Result<()> {
|
||||||
let output = common::render_module("dir").arg("--path=~").output()?;
|
let output = common::render_module("directory")
|
||||||
|
.arg("--path=~")
|
||||||
|
.output()?;
|
||||||
let actual = String::from_utf8(output.stdout).unwrap();
|
let actual = String::from_utf8(output.stdout).unwrap();
|
||||||
|
|
||||||
let expected = format!("in {} ", Color::Cyan.bold().paint("~"));
|
let expected = format!("in {} ", Color::Cyan.bold().paint("~"));
|
||||||
@ -24,7 +26,7 @@ fn directory_in_home() -> io::Result<()> {
|
|||||||
let dir = home_dir().unwrap().join("starship/engine");
|
let dir = home_dir().unwrap().join("starship/engine");
|
||||||
fs::create_dir_all(&dir)?;
|
fs::create_dir_all(&dir)?;
|
||||||
|
|
||||||
let output = common::render_module("dir")
|
let output = common::render_module("directory")
|
||||||
.arg("--path")
|
.arg("--path")
|
||||||
.arg(dir)
|
.arg(dir)
|
||||||
.output()?;
|
.output()?;
|
||||||
@ -41,7 +43,7 @@ fn truncated_directory_in_home() -> io::Result<()> {
|
|||||||
let dir = home_dir().unwrap().join("starship/engine/schematics");
|
let dir = home_dir().unwrap().join("starship/engine/schematics");
|
||||||
fs::create_dir_all(&dir)?;
|
fs::create_dir_all(&dir)?;
|
||||||
|
|
||||||
let output = common::render_module("dir")
|
let output = common::render_module("directory")
|
||||||
.arg("--path")
|
.arg("--path")
|
||||||
.arg(dir)
|
.arg(dir)
|
||||||
.output()?;
|
.output()?;
|
||||||
@ -57,7 +59,9 @@ fn truncated_directory_in_home() -> io::Result<()> {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn root_directory() -> io::Result<()> {
|
fn root_directory() -> io::Result<()> {
|
||||||
let output = common::render_module("dir").arg("--path=/").output()?;
|
let output = common::render_module("directory")
|
||||||
|
.arg("--path=/")
|
||||||
|
.output()?;
|
||||||
let actual = String::from_utf8(output.stdout).unwrap();
|
let actual = String::from_utf8(output.stdout).unwrap();
|
||||||
|
|
||||||
let expected = format!("in {} ", Color::Cyan.bold().paint("/"));
|
let expected = format!("in {} ", Color::Cyan.bold().paint("/"));
|
||||||
@ -67,7 +71,9 @@ fn root_directory() -> io::Result<()> {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn directory_in_root() -> io::Result<()> {
|
fn directory_in_root() -> io::Result<()> {
|
||||||
let output = common::render_module("dir").arg("--path=/usr").output()?;
|
let output = common::render_module("directory")
|
||||||
|
.arg("--path=/usr")
|
||||||
|
.output()?;
|
||||||
let actual = String::from_utf8(output.stdout).unwrap();
|
let actual = String::from_utf8(output.stdout).unwrap();
|
||||||
|
|
||||||
let expected = format!("in {} ", Color::Cyan.bold().paint("/usr"));
|
let expected = format!("in {} ", Color::Cyan.bold().paint("/usr"));
|
||||||
@ -81,7 +87,7 @@ fn truncated_directory_in_root() -> io::Result<()> {
|
|||||||
let dir = Path::new("/tmp/starship/thrusters/rocket");
|
let dir = Path::new("/tmp/starship/thrusters/rocket");
|
||||||
fs::create_dir_all(&dir)?;
|
fs::create_dir_all(&dir)?;
|
||||||
|
|
||||||
let output = common::render_module("dir")
|
let output = common::render_module("directory")
|
||||||
.arg("--path")
|
.arg("--path")
|
||||||
.arg(dir)
|
.arg(dir)
|
||||||
.output()?;
|
.output()?;
|
||||||
@ -101,7 +107,7 @@ fn truncated_directory_config_large() -> io::Result<()> {
|
|||||||
let dir = Path::new("/tmp/starship/thrusters/rocket");
|
let dir = Path::new("/tmp/starship/thrusters/rocket");
|
||||||
fs::create_dir_all(&dir)?;
|
fs::create_dir_all(&dir)?;
|
||||||
|
|
||||||
let output = common::render_module("dir")
|
let output = common::render_module("directory")
|
||||||
.use_config(toml::toml! {
|
.use_config(toml::toml! {
|
||||||
[directory]
|
[directory]
|
||||||
truncation_length = 100
|
truncation_length = 100
|
||||||
@ -125,7 +131,7 @@ fn truncated_directory_config_small() -> io::Result<()> {
|
|||||||
let dir = Path::new("/tmp/starship/thrusters/rocket");
|
let dir = Path::new("/tmp/starship/thrusters/rocket");
|
||||||
fs::create_dir_all(&dir)?;
|
fs::create_dir_all(&dir)?;
|
||||||
|
|
||||||
let output = common::render_module("dir")
|
let output = common::render_module("directory")
|
||||||
.use_config(toml::toml! {
|
.use_config(toml::toml! {
|
||||||
[directory]
|
[directory]
|
||||||
truncation_length = 2
|
truncation_length = 2
|
||||||
@ -151,7 +157,7 @@ fn git_repo_root() -> io::Result<()> {
|
|||||||
fs::create_dir(&repo_dir)?;
|
fs::create_dir(&repo_dir)?;
|
||||||
Repository::init(&repo_dir).unwrap();
|
Repository::init(&repo_dir).unwrap();
|
||||||
|
|
||||||
let output = common::render_module("dir")
|
let output = common::render_module("directory")
|
||||||
.arg("--path")
|
.arg("--path")
|
||||||
.arg(repo_dir)
|
.arg(repo_dir)
|
||||||
.output()?;
|
.output()?;
|
||||||
@ -171,7 +177,7 @@ fn directory_in_git_repo() -> io::Result<()> {
|
|||||||
fs::create_dir_all(&dir)?;
|
fs::create_dir_all(&dir)?;
|
||||||
Repository::init(&repo_dir).unwrap();
|
Repository::init(&repo_dir).unwrap();
|
||||||
|
|
||||||
let output = common::render_module("dir")
|
let output = common::render_module("directory")
|
||||||
.arg("--path")
|
.arg("--path")
|
||||||
.arg(dir)
|
.arg(dir)
|
||||||
.output()?;
|
.output()?;
|
||||||
@ -191,7 +197,7 @@ fn truncated_directory_in_git_repo() -> io::Result<()> {
|
|||||||
fs::create_dir_all(&dir)?;
|
fs::create_dir_all(&dir)?;
|
||||||
Repository::init(&repo_dir).unwrap();
|
Repository::init(&repo_dir).unwrap();
|
||||||
|
|
||||||
let output = common::render_module("dir")
|
let output = common::render_module("directory")
|
||||||
.arg("--path")
|
.arg("--path")
|
||||||
.arg(dir)
|
.arg(dir)
|
||||||
.output()?;
|
.output()?;
|
||||||
|
@ -2,7 +2,7 @@ use ansi_term::Color;
|
|||||||
use std::fs::{self, File};
|
use std::fs::{self, File};
|
||||||
use std::io;
|
use std::io;
|
||||||
|
|
||||||
use crate::common;
|
use crate::common::{self, TestCommand};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn folder_without_go_files() -> io::Result<()> {
|
fn folder_without_go_files() -> io::Result<()> {
|
||||||
@ -138,3 +138,24 @@ fn folder_with_gopkg_lock() -> io::Result<()> {
|
|||||||
assert_eq!(expected, actual);
|
assert_eq!(expected, actual);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn config_disabled() -> io::Result<()> {
|
||||||
|
let dir = common::new_tempdir()?;
|
||||||
|
File::create(dir.path().join("main.go"))?;
|
||||||
|
|
||||||
|
let output = common::render_module("golang")
|
||||||
|
.use_config(toml::toml! {
|
||||||
|
[golang]
|
||||||
|
disabled = true
|
||||||
|
})
|
||||||
|
.arg("--path")
|
||||||
|
.arg(dir.path())
|
||||||
|
.output()?;
|
||||||
|
let actual = String::from_utf8(output.stdout).unwrap();
|
||||||
|
|
||||||
|
let expected = "";
|
||||||
|
assert_eq!(expected, actual);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
@ -2,7 +2,7 @@ use ansi_term::Color;
|
|||||||
use std::fs::{self, File};
|
use std::fs::{self, File};
|
||||||
use std::io;
|
use std::io;
|
||||||
|
|
||||||
use crate::common;
|
use crate::common::{self, TestCommand};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn folder_without_node_files() -> io::Result<()> {
|
fn folder_without_node_files() -> io::Result<()> {
|
||||||
@ -70,3 +70,24 @@ fn folder_with_node_modules() -> io::Result<()> {
|
|||||||
assert_eq!(expected, actual);
|
assert_eq!(expected, actual);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn config_disabled() -> io::Result<()> {
|
||||||
|
let dir = common::new_tempdir()?;
|
||||||
|
File::create(dir.path().join("package.json"))?;
|
||||||
|
|
||||||
|
let output = common::render_module("nodejs")
|
||||||
|
.use_config(toml::toml! {
|
||||||
|
[nodejs]
|
||||||
|
disabled = true
|
||||||
|
})
|
||||||
|
.arg("--path")
|
||||||
|
.arg(dir.path())
|
||||||
|
.output()?;
|
||||||
|
let actual = String::from_utf8(output.stdout).unwrap();
|
||||||
|
|
||||||
|
let expected = "";
|
||||||
|
assert_eq!(expected, actual);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user