From 7424e9674cb2a966938861f4257a0b2963f5cdca Mon Sep 17 00:00:00 2001 From: Matan Kushner Date: Tue, 13 Aug 2019 12:30:59 -0400 Subject: [PATCH] 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 --- src/modules/golang.rs | 2 +- src/modules/mod.rs | 10 +++++----- src/modules/nodejs.rs | 2 +- tests/testsuite/cmd_duration.rs | 3 --- tests/testsuite/directory.rs | 28 +++++++++++++++++----------- tests/testsuite/golang.rs | 23 ++++++++++++++++++++++- tests/testsuite/nodejs.rs | 23 ++++++++++++++++++++++- 7 files changed, 68 insertions(+), 23 deletions(-) diff --git a/src/modules/golang.rs b/src/modules/golang.rs index 17af7d5f..0114c30d 100644 --- a/src/modules/golang.rs +++ b/src/modules/golang.rs @@ -30,7 +30,7 @@ pub fn module<'a>(context: &'a Context) -> Option> { const GO_CHAR: &str = "🐹 "; 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); let formatted_version = format_go_version(&go_version)?; diff --git a/src/modules/mod.rs b/src/modules/mod.rs index 9171f2a3..35bbe2d3 100644 --- a/src/modules/mod.rs +++ b/src/modules/mod.rs @@ -18,12 +18,12 @@ use crate::module::Module; pub fn handle<'a>(module: &str, context: &'a Context) -> Option> { match module { - "dir" | "directory" => directory::module(context), - "char" | "character" => character::module(context), - "node" | "nodejs" => nodejs::module(context), - "rust" | "rustlang" => rust::module(context), + "directory" => directory::module(context), + "character" => character::module(context), + "nodejs" => nodejs::module(context), + "rust" => rust::module(context), "python" => python::module(context), - "go" | "golang" => golang::module(context), + "golang" => golang::module(context), "line_break" => line_break::module(context), "package" => package::module(context), "git_branch" => git_branch::module(context), diff --git a/src/modules/nodejs.rs b/src/modules/nodejs.rs index eddbc5a7..c7029d88 100644 --- a/src/modules/nodejs.rs +++ b/src/modules/nodejs.rs @@ -26,7 +26,7 @@ pub fn module<'a>(context: &'a Context) -> Option> { const NODE_CHAR: &str = "⬢ "; 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); let formatted_version = node_version.trim(); diff --git a/tests/testsuite/cmd_duration.rs b/tests/testsuite/cmd_duration.rs index a7cf5e95..a8279032 100644 --- a/tests/testsuite/cmd_duration.rs +++ b/tests/testsuite/cmd_duration.rs @@ -1,8 +1,5 @@ use ansi_term::Color; -use std::fs; use std::io; -use std::path::Path; -use tempfile::TempDir; use crate::common::{self, TestCommand}; diff --git a/tests/testsuite/directory.rs b/tests/testsuite/directory.rs index 1a5e67dd..a390c0ab 100644 --- a/tests/testsuite/directory.rs +++ b/tests/testsuite/directory.rs @@ -10,7 +10,9 @@ use crate::common::{self, TestCommand}; #[test] 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 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"); fs::create_dir_all(&dir)?; - let output = common::render_module("dir") + let output = common::render_module("directory") .arg("--path") .arg(dir) .output()?; @@ -41,7 +43,7 @@ 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") + let output = common::render_module("directory") .arg("--path") .arg(dir) .output()?; @@ -57,7 +59,9 @@ fn truncated_directory_in_home() -> io::Result<()> { #[test] 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 expected = format!("in {} ", Color::Cyan.bold().paint("/")); @@ -67,7 +71,9 @@ fn root_directory() -> io::Result<()> { #[test] 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 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"); fs::create_dir_all(&dir)?; - let output = common::render_module("dir") + let output = common::render_module("directory") .arg("--path") .arg(dir) .output()?; @@ -101,7 +107,7 @@ fn truncated_directory_config_large() -> io::Result<()> { let dir = Path::new("/tmp/starship/thrusters/rocket"); fs::create_dir_all(&dir)?; - let output = common::render_module("dir") + let output = common::render_module("directory") .use_config(toml::toml! { [directory] truncation_length = 100 @@ -125,7 +131,7 @@ fn truncated_directory_config_small() -> io::Result<()> { let dir = Path::new("/tmp/starship/thrusters/rocket"); fs::create_dir_all(&dir)?; - let output = common::render_module("dir") + let output = common::render_module("directory") .use_config(toml::toml! { [directory] truncation_length = 2 @@ -151,7 +157,7 @@ fn git_repo_root() -> io::Result<()> { fs::create_dir(&repo_dir)?; Repository::init(&repo_dir).unwrap(); - let output = common::render_module("dir") + let output = common::render_module("directory") .arg("--path") .arg(repo_dir) .output()?; @@ -171,7 +177,7 @@ fn directory_in_git_repo() -> io::Result<()> { fs::create_dir_all(&dir)?; Repository::init(&repo_dir).unwrap(); - let output = common::render_module("dir") + let output = common::render_module("directory") .arg("--path") .arg(dir) .output()?; @@ -191,7 +197,7 @@ fn truncated_directory_in_git_repo() -> io::Result<()> { fs::create_dir_all(&dir)?; Repository::init(&repo_dir).unwrap(); - let output = common::render_module("dir") + let output = common::render_module("directory") .arg("--path") .arg(dir) .output()?; diff --git a/tests/testsuite/golang.rs b/tests/testsuite/golang.rs index 6419eefb..c63e25c0 100644 --- a/tests/testsuite/golang.rs +++ b/tests/testsuite/golang.rs @@ -2,7 +2,7 @@ use ansi_term::Color; use std::fs::{self, File}; use std::io; -use crate::common; +use crate::common::{self, TestCommand}; #[test] fn folder_without_go_files() -> io::Result<()> { @@ -138,3 +138,24 @@ fn folder_with_gopkg_lock() -> io::Result<()> { assert_eq!(expected, actual); 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(()) +} diff --git a/tests/testsuite/nodejs.rs b/tests/testsuite/nodejs.rs index 33b0df2a..bea6248a 100644 --- a/tests/testsuite/nodejs.rs +++ b/tests/testsuite/nodejs.rs @@ -2,7 +2,7 @@ use ansi_term::Color; use std::fs::{self, File}; use std::io; -use crate::common; +use crate::common::{self, TestCommand}; #[test] fn folder_without_node_files() -> io::Result<()> { @@ -70,3 +70,24 @@ fn folder_with_node_modules() -> io::Result<()> { assert_eq!(expected, actual); 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(()) +}