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:
Matan Kushner 2019-08-13 12:30:59 -04:00 committed by GitHub
parent 589b6cf712
commit 7424e9674c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 68 additions and 23 deletions

View File

@ -30,7 +30,7 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
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)?;

View File

@ -18,12 +18,12 @@ use crate::module::Module;
pub fn handle<'a>(module: &str, context: &'a Context) -> Option<Module<'a>> {
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),

View File

@ -26,7 +26,7 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
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();

View File

@ -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};

View File

@ -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()?;

View File

@ -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(())
}

View File

@ -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(())
}