diff --git a/.build/install-rust.yml b/.build/install-rust.yml deleted file mode 100644 index 765fdff4..00000000 --- a/.build/install-rust.yml +++ /dev/null @@ -1,12 +0,0 @@ -steps: - - script: | - curl -sSf -o rustup-init.exe https://win.rustup.rs - rustup-init.exe -y --default-toolchain %RUSTUP_TOOLCHAIN% - echo "##vso[task.setvariable variable=PATH;]%PATH%;%USERPROFILE%\.cargo\bin" - displayName: Windows install rust - condition: eq( variables['Agent.OS'], 'Windows_NT' ) - - script: | - curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain $RUSTUP_TOOLCHAIN - echo "##vso[task.setvariable variable=PATH;]$PATH:$HOME/.cargo/bin" - displayName: Install rust - condition: ne( variables['Agent.OS'], 'Windows_NT' ) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 4d669a15..70ce2c23 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -1,73 +1,25 @@ jobs: - # Run the Rust linter - - job: "Clippy" - pool: - vmImage: "ubuntu-16.04" - container: "rust:latest" - steps: - - script: rustup component add clippy - displayName: Install Clippy - - script: cargo clippy --all - displayName: Run clippy + # Check formatting + - template: ci/azure-rustfmt.yml + parameters: + name: rustfmt - # Run the Rust formatter - - job: "Rustfmt" - pool: - vmImage: "ubuntu-16.04" - container: "rust:latest" - condition: eq(variables['Build.Reason'], 'PullRequest') - steps: - - script: rustup component add rustfmt - displayName: Install Rustfmt - - script: cargo fmt --all -- --check - displayName: Run rustfmt + # Test with Rust stable + - template: ci/azure-test-stable.yml + parameters: + name: test_starship + displayName: Test starship + + # Test with Rust nightly + - template: ci/azure-test-nightly.yml + parameters: + name: test_nightly + displayName: Check starship with nightly # Run the integration tests in a Docker container - - job: "Docker" + - job: test_docker + displayName: Test starship Docker pool: - vmImage: "ubuntu-16.04" + vmImage: ubuntu-16.04 steps: - script: ./integration_test - displayName: Dockerized tests - - # Run the integration tests on virtual machines - - job: "Test" - strategy: - matrix: - windows-stable: - imageName: "vs2017-win2016" - RUSTUP_TOOLCHAIN: stable - mac-stable: - imageName: "macos-10.13" - RUSTUP_TOOLCHAIN: stable - linux-stable: - imageName: "ubuntu-16.04" - RUSTUP_TOOLCHAIN: stable - linux-beta: - imageName: "ubuntu-16.04" - RUSTUP_TOOLCHAIN: beta - linux-nightly: - imageName: "ubuntu-16.04" - RUSTUP_TOOLCHAIN: nightly - pool: - vmImage: "ubuntu-16.04" - steps: - # Install Node.js - - task: NodeTool@0 - inputs: - versionSpec: "12.0.0" - # Install Go - - task: GoTool@0 - inputs: - versionSpec: "1.10" - # Install Python - - task: UsePythonVersion@0 - inputs: - versionSpec: "3.7.2" - # Install Rust - - template: ".build/install-rust.yml" - - - script: cargo build - displayName: Cargo build - - script: cargo test -- --ignored - displayName: Cargo test diff --git a/ci/azure-install-rust.yml b/ci/azure-install-rust.yml new file mode 100644 index 00000000..122e8a98 --- /dev/null +++ b/ci/azure-install-rust.yml @@ -0,0 +1,25 @@ +steps: + # Linux and macOS + - script: | + set -e + curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain $RUSTUP_TOOLCHAIN + echo "##vso[task.setvariable variable=PATH;]$PATH:$HOME/.cargo/bin:/usr/local/cargo/bin" + env: + RUSTUP_TOOLCHAIN: ${{parameters.rust_version}} + displayName: "Install rust (*nix)" + condition: not(eq(variables['Agent.OS'], 'Windows_NT')) + # Windows + - script: | + curl -sSf -o rustup-init.exe https://win.rustup.rs + rustup-init.exe -y --default-toolchain %RUSTUP_TOOLCHAIN% + set PATH=%PATH%;%USERPROFILE%\.cargo\bin + echo "##vso[task.setvariable variable=PATH;]%PATH%;%USERPROFILE%\.cargo\bin" + env: + RUSTUP_TOOLCHAIN: ${{parameters.rust_version}} + displayName: "Install rust (windows)" + condition: eq(variables['Agent.OS'], 'Windows_NT') + # All platforms. + - script: | + rustc -Vv + cargo -V + displayName: Query rust and cargo versions diff --git a/ci/azure-rustfmt.yml b/ci/azure-rustfmt.yml new file mode 100644 index 00000000..60bb51aa --- /dev/null +++ b/ci/azure-rustfmt.yml @@ -0,0 +1,16 @@ +jobs: +# Check formatting +- job: ${{ parameters.name }} + displayName: Check rustfmt + pool: + vmImage: ubuntu-16.04 + steps: + - template: azure-install-rust.yml + parameters: + rust_version: stable + - script: | + rustup component add rustfmt + displayName: Install rustfmt + - script: | + cargo fmt --all -- --check + displayName: Check formatting diff --git a/ci/azure-setup-test-env.yml b/ci/azure-setup-test-env.yml new file mode 100644 index 00000000..c2c54b07 --- /dev/null +++ b/ci/azure-setup-test-env.yml @@ -0,0 +1,16 @@ +steps: + # Install Node.js + - task: NodeTool@0 + inputs: + versionSpec: "12.0.0" + displayName: "Install a fixed version of Node" + # Install Go + - task: GoTool@0 + inputs: + versionSpec: "1.10" + displayName: "Install a fixed version of Go" + # Install Python + - task: UsePythonVersion@0 + inputs: + versionSpec: "3.6.8" + displayName: "Install a fixed version of Python" diff --git a/ci/azure-test-nightly.yml b/ci/azure-test-nightly.yml new file mode 100644 index 00000000..e6f50788 --- /dev/null +++ b/ci/azure-test-nightly.yml @@ -0,0 +1,13 @@ +jobs: +- job: ${{ parameters.name }} + displayName: ${{ parameters.displayName }} + pool: + vmImage: ubuntu-16.04 + + steps: + - template: azure-install-rust.yml + parameters: + rust_version: nightly + + - script: cargo check --all + displayName: cargo +nightly check --all diff --git a/ci/azure-test-stable.yml b/ci/azure-test-stable.yml new file mode 100644 index 00000000..031b6939 --- /dev/null +++ b/ci/azure-test-stable.yml @@ -0,0 +1,23 @@ +jobs: +- job: ${{ parameters.name }} + displayName: ${{ parameters.displayName }} + strategy: + matrix: + Linux: + vmImage: ubuntu-16.04 + MacOS: + vmImage: macOS-10.13 + Windows: + vmImage: vs2017-win2016 + pool: + vmImage: $(vmImage) + + steps: + - template: azure-install-rust.yml + parameters: + rust_version: stable + + - template: azure-setup-test-env.yml + + - script: cargo test -- --ignored + displayName: cargo test diff --git a/src/modules/directory.rs b/src/modules/directory.rs index e0f4a9e1..710f7359 100644 --- a/src/modules/directory.rs +++ b/src/modules/directory.rs @@ -21,6 +21,7 @@ pub fn segment(context: &Context) -> Option { module.set_style(module_color); let current_dir = &context.current_dir; + log::debug!("Current directory: {:?}", current_dir); let dir_string; if let Some(repo_root) = &context.repo_root { @@ -58,7 +59,7 @@ fn contract_path(full_path: &Path, top_level_path: &Path, top_level_replacement: format!( "{replacement}{separator}{path}", replacement = top_level_replacement, - separator = std::path::MAIN_SEPARATOR, + separator = "/", path = full_path .strip_prefix(top_level_path) .unwrap() @@ -76,15 +77,13 @@ fn truncate(dir_string: String, length: usize) -> String { return dir_string; } - let components = dir_string - .split(std::path::MAIN_SEPARATOR) - .collect::>(); + let components = dir_string.split("/").collect::>(); if components.len() <= length { return dir_string; } let truncated_components = &components[components.len() - length..]; - truncated_components.join(&std::path::MAIN_SEPARATOR.to_string()) + truncated_components.join("/") } #[cfg(test)] diff --git a/tests/Dockerfile b/tests/Dockerfile index 8218fd31..ef00a407 100644 --- a/tests/Dockerfile +++ b/tests/Dockerfile @@ -28,7 +28,7 @@ RUN goenv global $GO_VERSION RUN go version # Install Python -ENV PYTHON_VERSION 3.7.2 +ENV PYTHON_VERSION 3.6.8 ENV PYENV_ROOT /root/.pyenv ENV PATH $PYENV_ROOT/shims:$PYENV_ROOT/bin:$PATH RUN curl https://pyenv.run | bash \ diff --git a/tests/directory.rs b/tests/directory.rs index 38efc298..d14b7fc2 100644 --- a/tests/directory.rs +++ b/tests/directory.rs @@ -67,9 +67,9 @@ fn root_directory() -> io::Result<()> { #[test] fn directory_in_root() -> io::Result<()> { - let dir = Path::new("/opt"); + let dir = Path::new("/tmp"); - let expected = format!("via {} ", Color::Cyan.bold().paint("/opt").to_string()); + let expected = format!("via {} ", Color::Cyan.bold().paint("/tmp").to_string()); let actual = common::render_module("dir", &dir); assert_eq!(expected, actual); @@ -79,7 +79,7 @@ fn directory_in_root() -> io::Result<()> { #[test] #[ignore] fn truncated_directory_in_root() -> io::Result<()> { - let dir = Path::new("/opt/starship/thrusters/rocket"); + let dir = Path::new("/tmp/starship/thrusters/rocket"); fs::create_dir_all(&dir)?; let expected = format!( @@ -98,7 +98,7 @@ fn truncated_directory_in_root() -> io::Result<()> { #[test] #[ignore] fn git_repo_root() -> io::Result<()> { - let tmp_dir = TempDir::new()?; + let tmp_dir = TempDir::new_in(home_dir().unwrap())?; let repo_dir = tmp_dir.path().join("rocket-controls"); fs::create_dir(&repo_dir)?; @@ -117,7 +117,7 @@ fn git_repo_root() -> io::Result<()> { #[test] #[ignore] fn directory_in_git_repo() -> io::Result<()> { - let tmp_dir = TempDir::new()?; + let tmp_dir = TempDir::new_in(home_dir().unwrap())?; let repo_dir = tmp_dir.path().join("rocket-controls"); let dir = repo_dir.join("src"); fs::create_dir_all(&dir)?; diff --git a/tests/python.rs b/tests/python.rs index f497e571..237c1f30 100644 --- a/tests/python.rs +++ b/tests/python.rs @@ -15,7 +15,7 @@ fn folder_with_python_version() -> io::Result<()> { let expected = format!( "via {} ", Segment::new("python") - .set_value("🐍 v3.7.2") + .set_value("🐍 v3.6.8") .set_style(Color::Yellow.bold()) ); let actual = common::render_module("python", &dir.path()); @@ -33,7 +33,7 @@ fn folder_with_requirements_txt() -> io::Result<()> { let expected = format!( "via {} ", Segment::new("python") - .set_value("🐍 v3.7.2") + .set_value("🐍 v3.6.8") .set_style(Color::Yellow.bold()) ); let actual = common::render_module("python", &dir.path()); @@ -51,7 +51,7 @@ fn folder_with_pyproject_toml() -> io::Result<()> { let expected = format!( "via {} ", Segment::new("python") - .set_value("🐍 v3.7.2") + .set_value("🐍 v3.6.8") .set_style(Color::Yellow.bold()) ); let actual = common::render_module("python", &dir.path()); @@ -69,7 +69,7 @@ fn folder_with_py_file() -> io::Result<()> { let expected = format!( "via {} ", Segment::new("python") - .set_value("🐍 v3.7.2") + .set_value("🐍 v3.6.8") .set_style(Color::Yellow.bold()) ); let actual = common::render_module("python", &dir.path());