mirror of
https://github.com/Llewellynvdm/starship.git
synced 2024-12-25 03:16:01 +00:00
feat: Implement PowerShell support (#470)
This commit is contained in:
parent
b5bb6d6994
commit
6ab70796db
16
.github/workflows/workflow.yml
vendored
16
.github/workflows/workflow.yml
vendored
@ -70,7 +70,7 @@ jobs:
|
||||
command: check
|
||||
args: --all
|
||||
|
||||
# Run tests on Linux, and macOS
|
||||
# Run tests on Linux, macOS, and Windows
|
||||
# On both Rust stable and Rust nightly
|
||||
test:
|
||||
name: Test Suite
|
||||
@ -79,7 +79,7 @@ jobs:
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
os: [ubuntu-latest, macOS-latest]
|
||||
os: [ubuntu-latest, macOS-latest, windows-latest]
|
||||
rust: [stable, nightly]
|
||||
steps:
|
||||
# Checkout the branch being tested
|
||||
@ -109,7 +109,7 @@ jobs:
|
||||
# Install Python at a fixed version
|
||||
- uses: actions/setup-python@master
|
||||
with:
|
||||
python-version: "3.6.9"
|
||||
python-version: "3.7.4"
|
||||
|
||||
# Install dotnet at a fixed version
|
||||
- uses: actions/setup-dotnet@master
|
||||
@ -187,6 +187,8 @@ jobs:
|
||||
- x86_64-unknown-linux-gnu
|
||||
- x86_64-unknown-linux-musl
|
||||
- x86_64-apple-darwin
|
||||
- x86_64-pc-windows-gnu
|
||||
- x86_64-pc-windows-msvc
|
||||
include:
|
||||
- target: x86_64-unknown-linux-gnu
|
||||
os: ubuntu-latest
|
||||
@ -197,6 +199,12 @@ jobs:
|
||||
- target: x86_64-apple-darwin
|
||||
os: macOS-latest
|
||||
name: starship-x86_64-apple-darwin.tar.gz
|
||||
- target: x86_64-pc-windows-gnu
|
||||
os: windows-latest
|
||||
name: starship-x86_64-pc-windows-gnu.zip
|
||||
- target: x86_64-pc-windows-msvc
|
||||
os: windows-latest
|
||||
name: starship-x86_64-pc-windows-msvc.zip
|
||||
runs-on: ${{ matrix.os }}
|
||||
steps:
|
||||
- uses: actions/checkout@v1
|
||||
@ -224,7 +232,7 @@ jobs:
|
||||
cd target/${{ matrix.target }}/release
|
||||
if [[ "${{ matrix.os }}" == "windows-latest" ]]
|
||||
then
|
||||
7z a ../../../${{ matrix.name }} starship
|
||||
7z a ../../../${{ matrix.name }} starship.exe
|
||||
else
|
||||
tar czvf ../../../${{ matrix.name }} starship
|
||||
fi
|
||||
|
@ -97,3 +97,12 @@ footer: ISC Licensed | Copyright © 2019-present Starship Contributors
|
||||
|
||||
eval "$(starship init zsh)"
|
||||
```
|
||||
|
||||
#### Powershell
|
||||
|
||||
Add the following to the end of `~\Documents\PowerShell\Microsoft.PowerShell_profile.ps1` (or `~/.config/powershell/Microsoft.PowerShell_profile.ps1` on -Nix):
|
||||
|
||||
```sh
|
||||
# ~\Documents\PowerShell\Profile.ps1
|
||||
Invoke-Expression (&starship init powershell)
|
||||
```
|
||||
|
@ -94,6 +94,21 @@ fi"#,
|
||||
);
|
||||
Some(script)
|
||||
}
|
||||
Some("powershell") => {
|
||||
// Explanation of syntax:
|
||||
// &: Explicitly tells powershell to execute path with starship executable.
|
||||
//
|
||||
// @: multi-line stdout is returned as an array, but a single line or no lines
|
||||
// are returned as-is. @ ensures it's always an array.
|
||||
//
|
||||
// -join "`n": Joins the stdout array together as a string with newlines.
|
||||
// Powershell escapes with ` instead of \ thus `n translates to a newline.
|
||||
let script = format!(
|
||||
"Invoke-Expression (@(&\"{}\" init powershell --print-full-init) -join \"`n\")",
|
||||
starship
|
||||
);
|
||||
Some(script)
|
||||
}
|
||||
None => {
|
||||
println!(
|
||||
"Invalid shell name provided: {}\\n\
|
||||
@ -130,6 +145,7 @@ pub fn init_main(shell_name: &str) -> io::Result<()> {
|
||||
"bash" => Some(BASH_INIT),
|
||||
"zsh" => Some(ZSH_INIT),
|
||||
"fish" => Some(FISH_INIT),
|
||||
"powershell" => Some(PWSH_INIT),
|
||||
_ => {
|
||||
println!(
|
||||
"printf \"Shell name detection failed on phase two init.\\n\
|
||||
@ -168,3 +184,5 @@ const BASH_INIT: &str = include_str!("starship.bash");
|
||||
const ZSH_INIT: &str = include_str!("starship.zsh");
|
||||
|
||||
const FISH_INIT: &str = include_str!("starship.fish");
|
||||
|
||||
const PWSH_INIT: &str = include_str!("starship.ps1");
|
||||
|
23
src/init/starship.ps1
Normal file
23
src/init/starship.ps1
Normal file
@ -0,0 +1,23 @@
|
||||
#!/usr/bin/env pwsh
|
||||
|
||||
# Starship assumes UTF-8
|
||||
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
|
||||
function global:prompt {
|
||||
$out = $null
|
||||
# @ makes sure the result is an array even if single or no values are returned
|
||||
$jobs = @(Get-Job | Where-Object { $_.State -eq 'Running' }).Count
|
||||
|
||||
if ($lastCmd = Get-History -Count 1) {
|
||||
$duration = [math]::Round(($lastCmd.EndExecutionTime - $lastCmd.StartExecutionTime).TotalSeconds)
|
||||
# & ensures the path is interpreted as something to execute
|
||||
$out = @(&::STARSHIP:: prompt --status=$lastexitcode --jobs=$jobs --cmd-duration=$duration)
|
||||
} else {
|
||||
$out = @(&::STARSHIP:: prompt --status=$lastexitcode --jobs=$jobs)
|
||||
}
|
||||
|
||||
# Convert stdout (array of lines) to expected return type string
|
||||
# `n is an escaped newline
|
||||
$out -join "`n"
|
||||
}
|
||||
|
||||
$ENV:STARSHIP_SHELL = "powershell"
|
@ -34,7 +34,7 @@ fn main() {
|
||||
let shell_arg = Arg::with_name("shell")
|
||||
.value_name("SHELL")
|
||||
.help(
|
||||
"The name of the currently running shell\nCurrently supported options: bash, zsh, fish",
|
||||
"The name of the currently running shell\nCurrently supported options: bash, zsh, fish, powershell",
|
||||
)
|
||||
.required(true);
|
||||
|
||||
|
@ -8,6 +8,7 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
|
||||
let shell = std::env::var("STARSHIP_SHELL").unwrap_or_default();
|
||||
let percentage_char = match shell.as_str() {
|
||||
"zsh" => "%%", // % is an escape in zsh, see PROMPT in `man zshmisc`
|
||||
"powershell" => "`%",
|
||||
_ => "%",
|
||||
};
|
||||
|
||||
|
@ -10,8 +10,8 @@ use crate::configs::conda::CondaConfig;
|
||||
/// Will display the Conda environment iff `$CONDA_DEFAULT_ENV` is set.
|
||||
pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
|
||||
// Reference implementation: https://github.com/denysdovhan/spaceship-prompt/blob/master/sections/conda.zsh
|
||||
let conda_env = env::var("CONDA_DEFAULT_ENV").ok()?;
|
||||
if conda_env.is_empty() {
|
||||
let conda_env = env::var("CONDA_DEFAULT_ENV").unwrap_or_else(|_| "".into());
|
||||
if conda_env.trim().is_empty() {
|
||||
return None;
|
||||
}
|
||||
|
||||
|
@ -38,7 +38,7 @@ RUN curl -fsSL https://github.com/rbenv/rbenv-installer/raw/master/bin/rbenv-ins
|
||||
RUN ruby --version
|
||||
|
||||
# Install Python
|
||||
ENV PYTHON_VERSION 3.6.9
|
||||
ENV PYTHON_VERSION 3.7.4
|
||||
ENV PYENV_ROOT /home/nonroot/.pyenv
|
||||
ENV PATH $PYENV_ROOT/bin:$PYENV_ROOT/shims:$PATH
|
||||
RUN curl https://pyenv.run | bash \
|
||||
|
@ -8,7 +8,10 @@ use crate::common;
|
||||
|
||||
#[test]
|
||||
fn no_region_set() -> io::Result<()> {
|
||||
let output = common::render_module("aws").env_clear().output()?;
|
||||
let output = common::render_module("aws")
|
||||
.env_clear()
|
||||
.env("PATH", env!("PATH"))
|
||||
.output()?;
|
||||
let expected = "";
|
||||
let actual = String::from_utf8(output.stdout).unwrap();
|
||||
assert_eq!(expected, actual);
|
||||
|
@ -8,9 +8,15 @@ use std::{env, fs, io, process};
|
||||
static MANIFEST_DIR: Lazy<&'static Path> = Lazy::new(|| Path::new(env!("CARGO_MANIFEST_DIR")));
|
||||
static EMPTY_CONFIG: Lazy<PathBuf> = Lazy::new(|| MANIFEST_DIR.join("empty_config.toml"));
|
||||
|
||||
#[cfg(windows)]
|
||||
const EXE_PATH: &str = "./target/debug/starship.exe";
|
||||
|
||||
#[cfg(not(windows))]
|
||||
const EXE_PATH: &str = "./target/debug/starship";
|
||||
|
||||
/// Render the full starship prompt
|
||||
pub fn render_prompt() -> process::Command {
|
||||
let mut command = process::Command::new("./target/debug/starship");
|
||||
let mut command = process::Command::new(EXE_PATH);
|
||||
|
||||
command
|
||||
.arg("prompt")
|
||||
@ -23,7 +29,7 @@ pub fn render_prompt() -> process::Command {
|
||||
|
||||
/// Render a specific starship module by name
|
||||
pub fn render_module(module_name: &str) -> process::Command {
|
||||
let binary = fs::canonicalize("./target/debug/starship").unwrap();
|
||||
let binary = fs::canonicalize(EXE_PATH).unwrap();
|
||||
let mut command = process::Command::new(binary);
|
||||
|
||||
command
|
||||
@ -44,31 +50,37 @@ pub fn create_fixture_repo() -> io::Result<PathBuf> {
|
||||
|
||||
let fixture_repo_dir = path_str(&fixture_repo_path)?;
|
||||
let repo_dir = path_str(&repo_path)?;
|
||||
let fixture = path_str(&fixture_path)?;
|
||||
|
||||
Command::new("git")
|
||||
.args(&["clone", "-b", "master", fixture, fixture_repo_dir])
|
||||
.args(&["clone", "-b", "master"])
|
||||
.args(&[&fixture_path, &repo_path])
|
||||
.output()?;
|
||||
|
||||
git2::Repository::clone(fixture_repo_dir, repo_dir).ok();
|
||||
git2::Repository::clone(&fixture_repo_dir, &repo_dir).ok();
|
||||
|
||||
Command::new("git")
|
||||
.args(&["config", "--local", "user.email", "starship@example.com"])
|
||||
.current_dir(repo_dir)
|
||||
.current_dir(&repo_path)
|
||||
.output()?;
|
||||
|
||||
Command::new("git")
|
||||
.args(&["config", "--local", "user.name", "starship"])
|
||||
.current_dir(repo_dir)
|
||||
.current_dir(&repo_path)
|
||||
.output()?;
|
||||
|
||||
Command::new("git")
|
||||
.args(&["reset", "--hard", "HEAD"])
|
||||
.current_dir(&repo_path)
|
||||
.output()?;
|
||||
|
||||
Ok(repo_path)
|
||||
}
|
||||
|
||||
fn path_str(repo_dir: &PathBuf) -> io::Result<&str> {
|
||||
fn path_str(repo_dir: &PathBuf) -> io::Result<String> {
|
||||
repo_dir
|
||||
.to_str()
|
||||
.ok_or_else(|| Error::from(ErrorKind::Other))
|
||||
.map(|i| i.replace("\\", "/"))
|
||||
}
|
||||
|
||||
/// Extends `std::process::Command` with methods for testing
|
||||
|
@ -5,7 +5,10 @@ use crate::common;
|
||||
|
||||
#[test]
|
||||
fn not_in_env() -> io::Result<()> {
|
||||
let output = common::render_module("conda").env_clear().output()?;
|
||||
let output = common::render_module("conda")
|
||||
.env_clear()
|
||||
.env("PATH", env!("PATH"))
|
||||
.output()?;
|
||||
|
||||
let expected = "";
|
||||
let actual = String::from_utf8(output.stdout).unwrap();
|
||||
|
@ -111,7 +111,9 @@ fn directory_in_root() -> io::Result<()> {
|
||||
#[test]
|
||||
#[cfg(target_os = "windows")]
|
||||
fn directory_in_root() -> io::Result<()> {
|
||||
let output = common::render_module("dir").arg("--path=C:\\").output()?;
|
||||
let output = common::render_module("directory")
|
||||
.arg("--path=C:\\")
|
||||
.output()?;
|
||||
let actual = String::from_utf8(output.stdout).unwrap();
|
||||
|
||||
let expected = format!("in {} ", Color::Cyan.bold().paint("/c"));
|
||||
|
@ -113,7 +113,8 @@ fn touch_path(workspace: &TempDir, relative_path: &str, contents: Option<&str>)
|
||||
.create(true)
|
||||
.truncate(true)
|
||||
.open(&path)?;
|
||||
write!(file, "{}", contents.unwrap_or(""))
|
||||
write!(file, "{}", contents.unwrap_or(""))?;
|
||||
file.sync_data()
|
||||
}
|
||||
|
||||
fn make_pinned_sdk_json(version: &str) -> String {
|
||||
|
@ -5,6 +5,18 @@ use std::process::Command;
|
||||
|
||||
use crate::common::{self, TestCommand};
|
||||
|
||||
/// Right after the calls to git the filesystem state may not have finished
|
||||
/// updating yet causing some of the tests to fail. These barriers are placed
|
||||
/// after each call to git.
|
||||
/// This barrier is windows-specific though other operating systems may need it
|
||||
/// in the future.
|
||||
#[cfg(not(windows))]
|
||||
fn barrier() {}
|
||||
#[cfg(windows)]
|
||||
fn barrier() {
|
||||
std::thread::sleep(std::time::Duration::from_millis(500));
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore]
|
||||
fn shows_behind() -> io::Result<()> {
|
||||
@ -14,6 +26,7 @@ fn shows_behind() -> io::Result<()> {
|
||||
.args(&["reset", "--hard", "HEAD^"])
|
||||
.current_dir(repo_dir.as_path())
|
||||
.output()?;
|
||||
barrier();
|
||||
|
||||
let output = common::render_module("git_status")
|
||||
.arg("--path")
|
||||
@ -36,6 +49,7 @@ fn shows_behind_with_count() -> io::Result<()> {
|
||||
.args(&["reset", "--hard", "HEAD^"])
|
||||
.current_dir(repo_dir.as_path())
|
||||
.output()?;
|
||||
barrier();
|
||||
|
||||
let output = common::render_module("git_status")
|
||||
.use_config(toml::toml! {
|
||||
@ -58,12 +72,13 @@ fn shows_behind_with_count() -> io::Result<()> {
|
||||
fn shows_ahead() -> io::Result<()> {
|
||||
let repo_dir = common::create_fixture_repo()?;
|
||||
|
||||
File::create(repo_dir.join("readme.md"))?;
|
||||
File::create(repo_dir.join("readme.md"))?.sync_all()?;
|
||||
|
||||
Command::new("git")
|
||||
.args(&["commit", "-am", "Update readme"])
|
||||
.current_dir(&repo_dir)
|
||||
.output()?;
|
||||
barrier();
|
||||
|
||||
let output = common::render_module("git_status")
|
||||
.arg("--path")
|
||||
@ -82,12 +97,13 @@ fn shows_ahead() -> io::Result<()> {
|
||||
fn shows_ahead_with_count() -> io::Result<()> {
|
||||
let repo_dir = common::create_fixture_repo()?;
|
||||
|
||||
File::create(repo_dir.join("readme.md"))?;
|
||||
File::create(repo_dir.join("readme.md"))?.sync_all()?;
|
||||
|
||||
Command::new("git")
|
||||
.args(&["commit", "-am", "Update readme"])
|
||||
.current_dir(&repo_dir)
|
||||
.output()?;
|
||||
barrier();
|
||||
|
||||
let output = common::render_module("git_status")
|
||||
.use_config(toml::toml! {
|
||||
@ -122,6 +138,8 @@ fn shows_diverged() -> io::Result<()> {
|
||||
.current_dir(repo_dir.as_path())
|
||||
.output()?;
|
||||
|
||||
barrier();
|
||||
|
||||
let output = common::render_module("git_status")
|
||||
.arg("--path")
|
||||
.arg(repo_dir)
|
||||
@ -151,6 +169,8 @@ fn shows_diverged_with_count() -> io::Result<()> {
|
||||
.current_dir(repo_dir.as_path())
|
||||
.output()?;
|
||||
|
||||
barrier();
|
||||
|
||||
let output = common::render_module("git_status")
|
||||
.use_config(toml::toml! {
|
||||
[git_status]
|
||||
@ -179,23 +199,29 @@ fn shows_conflicted() -> io::Result<()> {
|
||||
.args(&["reset", "--hard", "HEAD^"])
|
||||
.current_dir(repo_dir.as_path())
|
||||
.output()?;
|
||||
barrier();
|
||||
|
||||
fs::write(repo_dir.join("readme.md"), "# goodbye")?;
|
||||
barrier();
|
||||
|
||||
Command::new("git")
|
||||
.args(&["add", "."])
|
||||
.current_dir(repo_dir.as_path())
|
||||
.output()?;
|
||||
|
||||
barrier();
|
||||
|
||||
Command::new("git")
|
||||
.args(&["commit", "-m", "Change readme"])
|
||||
.current_dir(repo_dir.as_path())
|
||||
.output()?;
|
||||
|
||||
barrier();
|
||||
Command::new("git")
|
||||
.args(&["pull", "--rebase"])
|
||||
.current_dir(repo_dir.as_path())
|
||||
.output()?;
|
||||
barrier();
|
||||
|
||||
let output = common::render_module("git_status")
|
||||
.arg("--path")
|
||||
@ -214,7 +240,7 @@ fn shows_conflicted() -> io::Result<()> {
|
||||
fn shows_untracked_file() -> io::Result<()> {
|
||||
let repo_dir = common::create_fixture_repo()?;
|
||||
|
||||
File::create(repo_dir.join("license"))?;
|
||||
File::create(repo_dir.join("license"))?.sync_all()?;
|
||||
|
||||
let output = common::render_module("git_status")
|
||||
.arg("--path")
|
||||
@ -233,12 +259,13 @@ fn shows_untracked_file() -> io::Result<()> {
|
||||
fn doesnt_show_untracked_file_if_disabled() -> io::Result<()> {
|
||||
let repo_dir = common::create_fixture_repo()?;
|
||||
|
||||
File::create(repo_dir.join("license"))?;
|
||||
File::create(repo_dir.join("license"))?.sync_all()?;
|
||||
|
||||
Command::new("git")
|
||||
.args(&["config", "status.showUntrackedFiles", "no"])
|
||||
.current_dir(repo_dir.as_path())
|
||||
.output()?;
|
||||
barrier();
|
||||
|
||||
let output = common::render_module("git_status")
|
||||
.arg("--path")
|
||||
@ -256,13 +283,23 @@ fn doesnt_show_untracked_file_if_disabled() -> io::Result<()> {
|
||||
#[ignore]
|
||||
fn shows_stashed() -> io::Result<()> {
|
||||
let repo_dir = common::create_fixture_repo()?;
|
||||
barrier();
|
||||
|
||||
File::create(repo_dir.join("readme.md"))?;
|
||||
File::create(repo_dir.join("readme.md"))?.sync_all()?;
|
||||
|
||||
barrier();
|
||||
|
||||
Command::new("git")
|
||||
.arg("stash")
|
||||
.args(&["stash", "--all"])
|
||||
.current_dir(repo_dir.as_path())
|
||||
.output()?;
|
||||
barrier();
|
||||
|
||||
Command::new("git")
|
||||
.args(&["reset", "--hard", "HEAD"])
|
||||
.current_dir(repo_dir.as_path())
|
||||
.output()?;
|
||||
barrier();
|
||||
|
||||
let output = common::render_module("git_status")
|
||||
.arg("--path")
|
||||
@ -281,7 +318,7 @@ fn shows_stashed() -> io::Result<()> {
|
||||
fn shows_modified() -> io::Result<()> {
|
||||
let repo_dir = common::create_fixture_repo()?;
|
||||
|
||||
File::create(repo_dir.join("readme.md"))?;
|
||||
File::create(repo_dir.join("readme.md"))?.sync_all()?;
|
||||
|
||||
let output = common::render_module("git_status")
|
||||
.arg("--path")
|
||||
@ -300,12 +337,13 @@ fn shows_modified() -> io::Result<()> {
|
||||
fn shows_staged_file() -> io::Result<()> {
|
||||
let repo_dir = common::create_fixture_repo()?;
|
||||
|
||||
File::create(repo_dir.join("license"))?;
|
||||
File::create(repo_dir.join("license"))?.sync_all()?;
|
||||
|
||||
Command::new("git")
|
||||
.args(&["add", "."])
|
||||
.current_dir(repo_dir.as_path())
|
||||
.output()?;
|
||||
barrier();
|
||||
|
||||
let output = common::render_module("git_status")
|
||||
.arg("--path")
|
||||
@ -333,6 +371,7 @@ fn shows_renamed_file() -> io::Result<()> {
|
||||
.args(&["add", "-A"])
|
||||
.current_dir(repo_dir.as_path())
|
||||
.output()?;
|
||||
barrier();
|
||||
|
||||
let output = common::render_module("git_status")
|
||||
.arg("--path")
|
||||
@ -369,7 +408,7 @@ fn shows_deleted_file() -> io::Result<()> {
|
||||
#[ignore]
|
||||
fn prefix() -> io::Result<()> {
|
||||
let repo_dir = common::create_fixture_repo()?;
|
||||
File::create(repo_dir.join("prefix"))?;
|
||||
File::create(repo_dir.join("prefix"))?.sync_all()?;
|
||||
let output = common::render_module("git_status")
|
||||
.arg("--path")
|
||||
.arg(repo_dir)
|
||||
@ -390,7 +429,7 @@ fn prefix() -> io::Result<()> {
|
||||
#[ignore]
|
||||
fn suffix() -> io::Result<()> {
|
||||
let repo_dir = common::create_fixture_repo()?;
|
||||
File::create(repo_dir.join("suffix"))?;
|
||||
File::create(repo_dir.join("suffix"))?.sync_all()?;
|
||||
let output = common::render_module("git_status")
|
||||
.arg("--path")
|
||||
.arg(repo_dir)
|
||||
|
@ -24,7 +24,7 @@ fn folder_without_go_files() -> io::Result<()> {
|
||||
#[ignore]
|
||||
fn folder_with_go_file() -> io::Result<()> {
|
||||
let dir = tempfile::tempdir()?;
|
||||
File::create(dir.path().join("main.go"))?;
|
||||
File::create(dir.path().join("main.go"))?.sync_all()?;
|
||||
|
||||
let output = common::render_module("golang")
|
||||
.arg("--path")
|
||||
@ -41,7 +41,7 @@ fn folder_with_go_file() -> io::Result<()> {
|
||||
#[ignore]
|
||||
fn folder_with_go_mod() -> io::Result<()> {
|
||||
let dir = tempfile::tempdir()?;
|
||||
File::create(dir.path().join("go.mod"))?;
|
||||
File::create(dir.path().join("go.mod"))?.sync_all()?;
|
||||
|
||||
let output = common::render_module("golang")
|
||||
.arg("--path")
|
||||
@ -58,7 +58,7 @@ fn folder_with_go_mod() -> io::Result<()> {
|
||||
#[ignore]
|
||||
fn folder_with_go_sum() -> io::Result<()> {
|
||||
let dir = tempfile::tempdir()?;
|
||||
File::create(dir.path().join("go.sum"))?;
|
||||
File::create(dir.path().join("go.sum"))?.sync_all()?;
|
||||
|
||||
let output = common::render_module("golang")
|
||||
.arg("--path")
|
||||
@ -93,7 +93,7 @@ fn folder_with_godeps() -> io::Result<()> {
|
||||
#[ignore]
|
||||
fn folder_with_glide_yaml() -> io::Result<()> {
|
||||
let dir = tempfile::tempdir()?;
|
||||
File::create(dir.path().join("glide.yaml"))?;
|
||||
File::create(dir.path().join("glide.yaml"))?.sync_all()?;
|
||||
|
||||
let output = common::render_module("golang")
|
||||
.arg("--path")
|
||||
@ -110,7 +110,7 @@ fn folder_with_glide_yaml() -> io::Result<()> {
|
||||
#[ignore]
|
||||
fn folder_with_gopkg_yml() -> io::Result<()> {
|
||||
let dir = tempfile::tempdir()?;
|
||||
File::create(dir.path().join("Gopkg.yml"))?;
|
||||
File::create(dir.path().join("Gopkg.yml"))?.sync_all()?;
|
||||
|
||||
let output = common::render_module("golang")
|
||||
.arg("--path")
|
||||
@ -127,7 +127,7 @@ fn folder_with_gopkg_yml() -> io::Result<()> {
|
||||
#[ignore]
|
||||
fn folder_with_gopkg_lock() -> io::Result<()> {
|
||||
let dir = tempfile::tempdir()?;
|
||||
File::create(dir.path().join("Gopkg.lock"))?;
|
||||
File::create(dir.path().join("Gopkg.lock"))?.sync_all()?;
|
||||
|
||||
let output = common::render_module("golang")
|
||||
.arg("--path")
|
||||
|
@ -5,11 +5,31 @@ use tempfile;
|
||||
|
||||
use crate::common;
|
||||
|
||||
/// Wrapper around common::render_module("nodejs") to work around platform quirks
|
||||
fn render_node_module() -> std::process::Command {
|
||||
let mut command = common::render_module("nodejs");
|
||||
|
||||
// If SYSTEMROOT is not set on Windows node will refuse to print its version
|
||||
if cfg!(windows) {
|
||||
let system_root = std::env::var("SYSTEMROOT")
|
||||
.map(|i| {
|
||||
if i.trim().is_empty() {
|
||||
"C:\\WINDOWS".into()
|
||||
} else {
|
||||
i
|
||||
}
|
||||
})
|
||||
.unwrap_or_else(|_| "C:\\WINDOWS".into());
|
||||
command.env("SYSTEMROOT", system_root);
|
||||
}
|
||||
command
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn folder_without_node_files() -> io::Result<()> {
|
||||
let dir = tempfile::tempdir()?;
|
||||
|
||||
let output = common::render_module("nodejs")
|
||||
let output = render_node_module()
|
||||
.arg("--path")
|
||||
.arg(dir.path())
|
||||
.output()?;
|
||||
@ -24,9 +44,9 @@ fn folder_without_node_files() -> io::Result<()> {
|
||||
#[ignore]
|
||||
fn folder_with_package_json() -> io::Result<()> {
|
||||
let dir = tempfile::tempdir()?;
|
||||
File::create(dir.path().join("package.json"))?;
|
||||
File::create(dir.path().join("package.json"))?.sync_all()?;
|
||||
|
||||
let output = common::render_module("nodejs")
|
||||
let output = render_node_module()
|
||||
.arg("--path")
|
||||
.arg(dir.path())
|
||||
.output()?;
|
||||
@ -41,9 +61,9 @@ fn folder_with_package_json() -> io::Result<()> {
|
||||
#[ignore]
|
||||
fn folder_with_js_file() -> io::Result<()> {
|
||||
let dir = tempfile::tempdir()?;
|
||||
File::create(dir.path().join("index.js"))?;
|
||||
File::create(dir.path().join("index.js"))?.sync_all()?;
|
||||
|
||||
let output = common::render_module("nodejs")
|
||||
let output = render_node_module()
|
||||
.arg("--path")
|
||||
.arg(dir.path())
|
||||
.output()?;
|
||||
@ -61,7 +81,7 @@ fn folder_with_node_modules() -> io::Result<()> {
|
||||
let node_modules = dir.path().join("node_modules");
|
||||
fs::create_dir_all(&node_modules)?;
|
||||
|
||||
let output = common::render_module("nodejs")
|
||||
let output = render_node_module()
|
||||
.arg("--path")
|
||||
.arg(dir.path())
|
||||
.output()?;
|
||||
|
@ -10,7 +10,7 @@ use crate::common;
|
||||
#[ignore]
|
||||
fn folder_with_python_version() -> io::Result<()> {
|
||||
let dir = tempfile::tempdir()?;
|
||||
File::create(dir.path().join(".python-version"))?;
|
||||
File::create(dir.path().join(".python-version"))?.sync_all()?;
|
||||
|
||||
let output = common::render_module("python")
|
||||
.arg("--path")
|
||||
@ -18,7 +18,7 @@ fn folder_with_python_version() -> io::Result<()> {
|
||||
.output()?;
|
||||
let actual = String::from_utf8(output.stdout).unwrap();
|
||||
|
||||
let expected = format!("via {} ", Color::Yellow.bold().paint("🐍 v3.6.9"));
|
||||
let expected = format!("via {} ", Color::Yellow.bold().paint("🐍 v3.7.4"));
|
||||
assert_eq!(expected, actual);
|
||||
Ok(())
|
||||
}
|
||||
@ -27,7 +27,7 @@ fn folder_with_python_version() -> io::Result<()> {
|
||||
#[ignore]
|
||||
fn folder_with_requirements_txt() -> io::Result<()> {
|
||||
let dir = tempfile::tempdir()?;
|
||||
File::create(dir.path().join("requirements.txt"))?;
|
||||
File::create(dir.path().join("requirements.txt"))?.sync_all()?;
|
||||
|
||||
let output = common::render_module("python")
|
||||
.arg("--path")
|
||||
@ -35,7 +35,7 @@ fn folder_with_requirements_txt() -> io::Result<()> {
|
||||
.output()?;
|
||||
let actual = String::from_utf8(output.stdout).unwrap();
|
||||
|
||||
let expected = format!("via {} ", Color::Yellow.bold().paint("🐍 v3.6.9"));
|
||||
let expected = format!("via {} ", Color::Yellow.bold().paint("🐍 v3.7.4"));
|
||||
assert_eq!(expected, actual);
|
||||
Ok(())
|
||||
}
|
||||
@ -44,7 +44,7 @@ fn folder_with_requirements_txt() -> io::Result<()> {
|
||||
#[ignore]
|
||||
fn folder_with_pyproject_toml() -> io::Result<()> {
|
||||
let dir = tempfile::tempdir()?;
|
||||
File::create(dir.path().join("pyproject.toml"))?;
|
||||
File::create(dir.path().join("pyproject.toml"))?.sync_all()?;
|
||||
|
||||
let output = common::render_module("python")
|
||||
.arg("--path")
|
||||
@ -52,7 +52,7 @@ fn folder_with_pyproject_toml() -> io::Result<()> {
|
||||
.output()?;
|
||||
let actual = String::from_utf8(output.stdout).unwrap();
|
||||
|
||||
let expected = format!("via {} ", Color::Yellow.bold().paint("🐍 v3.6.9"));
|
||||
let expected = format!("via {} ", Color::Yellow.bold().paint("🐍 v3.7.4"));
|
||||
assert_eq!(expected, actual);
|
||||
Ok(())
|
||||
}
|
||||
@ -61,7 +61,7 @@ fn folder_with_pyproject_toml() -> io::Result<()> {
|
||||
#[ignore]
|
||||
fn folder_with_pipfile() -> io::Result<()> {
|
||||
let dir = tempfile::tempdir()?;
|
||||
File::create(dir.path().join("Pipfile"))?;
|
||||
File::create(dir.path().join("Pipfile"))?.sync_all()?;
|
||||
|
||||
let output = common::render_module("python")
|
||||
.arg("--path")
|
||||
@ -69,7 +69,7 @@ fn folder_with_pipfile() -> io::Result<()> {
|
||||
.output()?;
|
||||
let actual = String::from_utf8(output.stdout).unwrap();
|
||||
|
||||
let expected = format!("via {} ", Color::Yellow.bold().paint("🐍 v3.6.9"));
|
||||
let expected = format!("via {} ", Color::Yellow.bold().paint("🐍 v3.7.4"));
|
||||
assert_eq!(expected, actual);
|
||||
Ok(())
|
||||
}
|
||||
@ -78,7 +78,7 @@ fn folder_with_pipfile() -> io::Result<()> {
|
||||
#[ignore]
|
||||
fn folder_with_tox() -> io::Result<()> {
|
||||
let dir = tempfile::tempdir()?;
|
||||
File::create(dir.path().join("tox.ini"))?;
|
||||
File::create(dir.path().join("tox.ini"))?.sync_all()?;
|
||||
|
||||
let output = common::render_module("python")
|
||||
.arg("--path")
|
||||
@ -86,7 +86,7 @@ fn folder_with_tox() -> io::Result<()> {
|
||||
.output()?;
|
||||
let actual = String::from_utf8(output.stdout).unwrap();
|
||||
|
||||
let expected = format!("via {} ", Color::Yellow.bold().paint("🐍 v3.6.9"));
|
||||
let expected = format!("via {} ", Color::Yellow.bold().paint("🐍 v3.7.4"));
|
||||
assert_eq!(expected, actual);
|
||||
Ok(())
|
||||
}
|
||||
@ -95,7 +95,7 @@ fn folder_with_tox() -> io::Result<()> {
|
||||
#[ignore]
|
||||
fn folder_with_py_file() -> io::Result<()> {
|
||||
let dir = tempfile::tempdir()?;
|
||||
File::create(dir.path().join("main.py"))?;
|
||||
File::create(dir.path().join("main.py"))?.sync_all()?;
|
||||
|
||||
let output = common::render_module("python")
|
||||
.arg("--path")
|
||||
@ -103,7 +103,7 @@ fn folder_with_py_file() -> io::Result<()> {
|
||||
.output()?;
|
||||
let actual = String::from_utf8(output.stdout).unwrap();
|
||||
|
||||
let expected = format!("via {} ", Color::Yellow.bold().paint("🐍 v3.6.9"));
|
||||
let expected = format!("via {} ", Color::Yellow.bold().paint("🐍 v3.7.4"));
|
||||
assert_eq!(expected, actual);
|
||||
Ok(())
|
||||
}
|
||||
@ -112,7 +112,7 @@ fn folder_with_py_file() -> io::Result<()> {
|
||||
#[ignore]
|
||||
fn with_virtual_env() -> io::Result<()> {
|
||||
let dir = tempfile::tempdir()?;
|
||||
File::create(dir.path().join("main.py"))?;
|
||||
File::create(dir.path().join("main.py"))?.sync_all()?;
|
||||
let output = common::render_module("python")
|
||||
.env("VIRTUAL_ENV", "/foo/bar/my_venv")
|
||||
.arg("--path")
|
||||
@ -120,7 +120,7 @@ fn with_virtual_env() -> io::Result<()> {
|
||||
.output()?;
|
||||
let actual = String::from_utf8(output.stdout).unwrap();
|
||||
|
||||
let expected = format!("via {} ", Color::Yellow.bold().paint("🐍 v3.6.9(my_venv)"));
|
||||
let expected = format!("via {} ", Color::Yellow.bold().paint("🐍 v3.7.4(my_venv)"));
|
||||
assert_eq!(expected, actual);
|
||||
Ok(())
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ fn folder_without_ruby_files() -> io::Result<()> {
|
||||
#[ignore]
|
||||
fn folder_with_gemfile() -> io::Result<()> {
|
||||
let dir = tempfile::tempdir()?;
|
||||
File::create(dir.path().join("Gemfile"))?;
|
||||
File::create(dir.path().join("Gemfile"))?.sync_all()?;
|
||||
|
||||
let output = common::render_module("ruby")
|
||||
.arg("--path")
|
||||
@ -41,7 +41,7 @@ fn folder_with_gemfile() -> io::Result<()> {
|
||||
#[ignore]
|
||||
fn folder_with_rb_file() -> io::Result<()> {
|
||||
let dir = tempfile::tempdir()?;
|
||||
File::create(dir.path().join("any.rb"))?;
|
||||
File::create(dir.path().join("any.rb"))?.sync_all()?;
|
||||
|
||||
let output = common::render_module("ruby")
|
||||
.arg("--path")
|
||||
|
Loading…
Reference in New Issue
Block a user