mirror of
https://github.com/Llewellynvdm/starship.git
synced 2025-02-04 04:58:32 +00:00
Add integration tests for Python segment (#38)
This commit is contained in:
parent
5fd715e7c3
commit
c95bb60571
@ -1,20 +1,12 @@
|
|||||||
parameters:
|
|
||||||
versionSpec: ""
|
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
# Install Rust at a fixed version for integration tests to pass
|
|
||||||
- script: |
|
- script: |
|
||||||
curl -sSf -o rustup-init.exe https://win.rustup.rs
|
curl -sSf -o rustup-init.exe https://win.rustup.rs
|
||||||
rustup-init.exe -y --default-toolchain ${{ parameters.versionSpec }}
|
rustup-init.exe -y --default-toolchain %RUSTUP_TOOLCHAIN%
|
||||||
echo "##vso[task.setvariable variable=PATH;]%PATH%;%USERPROFILE%\.cargo\bin"
|
echo "##vso[task.setvariable variable=PATH;]%PATH%;%USERPROFILE%\.cargo\bin"
|
||||||
displayName: Windows install Rust
|
displayName: Windows install rust
|
||||||
condition: eq( variables['Agent.OS'], 'Windows_NT' )
|
condition: eq( variables['Agent.OS'], 'Windows_NT' )
|
||||||
- script: |
|
- script: |
|
||||||
curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain ${{ parameters.versionSpec }}
|
curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain $RUSTUP_TOOLCHAIN
|
||||||
echo "##vso[task.setvariable variable=PATH;]$PATH:$HOME/.cargo/bin"
|
echo "##vso[task.setvariable variable=PATH;]$PATH:$HOME/.cargo/bin"
|
||||||
displayName: Install a fixed version of Rust
|
displayName: Install rust
|
||||||
condition: ne( variables['Agent.OS'], 'Windows_NT' )
|
condition: ne( variables['Agent.OS'], 'Windows_NT' )
|
||||||
|
|
||||||
# Install the version of Rust used for testing with
|
|
||||||
- script: rustup install $RUSTUP_TOOLCHAIN
|
|
||||||
displayName: Install Rust used for CI
|
|
||||||
|
@ -20,7 +20,7 @@ jobs:
|
|||||||
- script: rustup component add rustfmt
|
- script: rustup component add rustfmt
|
||||||
displayName: Install Rustfmt
|
displayName: Install Rustfmt
|
||||||
- script: cargo fmt --all -- --check
|
- script: cargo fmt --all -- --check
|
||||||
displayName: Run Rustfmt
|
displayName: Run rustfmt
|
||||||
|
|
||||||
# Run the integration tests in a Docker container
|
# Run the integration tests in a Docker container
|
||||||
- job: "Docker"
|
- job: "Docker"
|
||||||
@ -36,19 +36,19 @@ jobs:
|
|||||||
matrix:
|
matrix:
|
||||||
windows-stable:
|
windows-stable:
|
||||||
imageName: "vs2017-win2016"
|
imageName: "vs2017-win2016"
|
||||||
rustup_toolchain: stable
|
RUSTUP_TOOLCHAIN: stable
|
||||||
mac-stable:
|
mac-stable:
|
||||||
imageName: "macos-10.13"
|
imageName: "macos-10.13"
|
||||||
rustup_toolchain: stable
|
RUSTUP_TOOLCHAIN: stable
|
||||||
linux-stable:
|
linux-stable:
|
||||||
imageName: "ubuntu-16.04"
|
imageName: "ubuntu-16.04"
|
||||||
rustup_toolchain: stable
|
RUSTUP_TOOLCHAIN: stable
|
||||||
linux-beta:
|
linux-beta:
|
||||||
imageName: "ubuntu-16.04"
|
imageName: "ubuntu-16.04"
|
||||||
rustup_toolchain: beta
|
RUSTUP_TOOLCHAIN: beta
|
||||||
linux-nightly:
|
linux-nightly:
|
||||||
imageName: "ubuntu-16.04"
|
imageName: "ubuntu-16.04"
|
||||||
rustup_toolchain: nightly
|
RUSTUP_TOOLCHAIN: nightly
|
||||||
pool:
|
pool:
|
||||||
vmImage: "ubuntu-16.04"
|
vmImage: "ubuntu-16.04"
|
||||||
steps:
|
steps:
|
||||||
@ -60,13 +60,14 @@ jobs:
|
|||||||
- task: GoTool@0
|
- task: GoTool@0
|
||||||
inputs:
|
inputs:
|
||||||
versionSpec: "1.10"
|
versionSpec: "1.10"
|
||||||
# Install Rust at a fixed version for integration tests
|
# Install Python
|
||||||
|
- task: UsePythonVersion@0
|
||||||
|
inputs:
|
||||||
|
versionSpec: "3.7.2"
|
||||||
|
# Install Rust
|
||||||
- template: ".build/install-rust.yml"
|
- template: ".build/install-rust.yml"
|
||||||
parameters:
|
|
||||||
versionSpec: "1.34.0"
|
|
||||||
|
|
||||||
# Because integration tests rely on a fixed Rust version, we must use rustup to run with the intended toolkit
|
- script: cargo build
|
||||||
- script: rustup run $RUSTUP_TOOLCHAIN cargo build --all
|
|
||||||
displayName: Cargo build
|
displayName: Cargo build
|
||||||
- script: rustup run $RUSTUP_TOOLCHAIN cargo test -- --ignored
|
- script: cargo test -- --ignored
|
||||||
displayName: Cargo test
|
displayName: Cargo test
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
FROM rust:1.34.0
|
FROM rust:latest
|
||||||
|
|
||||||
# Install Node.js
|
# Install Node.js
|
||||||
ENV NODE_VERSION 12.0.0
|
ENV NODE_VERSION 12.0.0
|
||||||
@ -25,7 +25,18 @@ ENV PATH $GO_ROOT/bin:$PATH
|
|||||||
RUN goenv install $GO_VERSION
|
RUN goenv install $GO_VERSION
|
||||||
RUN goenv global $GO_VERSION
|
RUN goenv global $GO_VERSION
|
||||||
# Check that Go was correctly installed
|
# Check that Go was correctly installed
|
||||||
|
|
||||||
RUN go version
|
RUN go version
|
||||||
|
# Install Python
|
||||||
|
ENV PYTHON_VERSION 3.7.2
|
||||||
|
ENV PYENV_ROOT /root/.pyenv
|
||||||
|
ENV PATH $PYENV_ROOT/shims:$PYENV_ROOT/bin:$PATH
|
||||||
|
RUN curl https://pyenv.run | bash \
|
||||||
|
&& pyenv update \
|
||||||
|
&& pyenv install $PYTHON_VERSION \
|
||||||
|
&& pyenv global $PYTHON_VERSION
|
||||||
|
# Check that Python was correctly installed
|
||||||
|
RUN python --version
|
||||||
|
|
||||||
# Create blank project
|
# Create blank project
|
||||||
RUN USER=root cargo new --bin starship
|
RUN USER=root cargo new --bin starship
|
||||||
@ -40,8 +51,7 @@ RUN mkdir benches
|
|||||||
RUN touch benches/my_benchmark.rs
|
RUN touch benches/my_benchmark.rs
|
||||||
|
|
||||||
# This is a dummy build to get dependencies cached
|
# This is a dummy build to get dependencies cached
|
||||||
RUN rustup install stable
|
RUN cargo build --release
|
||||||
RUN rustup run stable cargo build --release
|
|
||||||
|
|
||||||
# Delete the dummy build
|
# Delete the dummy build
|
||||||
RUN rm -rf /starship
|
RUN rm -rf /starship
|
||||||
@ -50,5 +60,4 @@ RUN rm -rf /starship
|
|||||||
RUN mkdir starship
|
RUN mkdir starship
|
||||||
WORKDIR /starship
|
WORKDIR /starship
|
||||||
|
|
||||||
# Run with rustup to use stable instead of the Rust default
|
CMD ["cargo", "test", "--", "--ignored"]
|
||||||
CMD [ "rustup", "run", "stable", "cargo", "test", "--", "--ignored"]
|
|
||||||
|
79
tests/python.rs
Normal file
79
tests/python.rs
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
use ansi_term::Color;
|
||||||
|
use starship::segment::Segment;
|
||||||
|
use std::fs::File;
|
||||||
|
use std::io;
|
||||||
|
use tempfile::TempDir;
|
||||||
|
|
||||||
|
mod common;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn folder_with_python_version() -> io::Result<()> {
|
||||||
|
let dir = TempDir::new()?;
|
||||||
|
File::create(dir.path().join(".python-version"))?;
|
||||||
|
|
||||||
|
let expected = format!(
|
||||||
|
"via {} ",
|
||||||
|
Segment::new("python")
|
||||||
|
.set_value("🐍 v3.7.2")
|
||||||
|
.set_style(Color::Yellow.bold())
|
||||||
|
);
|
||||||
|
let actual = common::render_module("python", &dir.path());
|
||||||
|
assert_eq!(expected, actual);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn folder_with_requirements_txt() -> io::Result<()> {
|
||||||
|
let dir = TempDir::new()?;
|
||||||
|
File::create(dir.path().join("requirements.txt"))?;
|
||||||
|
|
||||||
|
let expected = format!(
|
||||||
|
"via {} ",
|
||||||
|
Segment::new("python")
|
||||||
|
.set_value("🐍 v3.7.2")
|
||||||
|
.set_style(Color::Yellow.bold())
|
||||||
|
);
|
||||||
|
let actual = common::render_module("python", &dir.path());
|
||||||
|
assert_eq!(expected, actual);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn folder_with_pyproject_toml() -> io::Result<()> {
|
||||||
|
let dir = TempDir::new()?;
|
||||||
|
File::create(dir.path().join("pyproject.toml"))?;
|
||||||
|
|
||||||
|
let expected = format!(
|
||||||
|
"via {} ",
|
||||||
|
Segment::new("python")
|
||||||
|
.set_value("🐍 v3.7.2")
|
||||||
|
.set_style(Color::Yellow.bold())
|
||||||
|
);
|
||||||
|
let actual = common::render_module("python", &dir.path());
|
||||||
|
assert_eq!(expected, actual);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn folder_with_py_file() -> io::Result<()> {
|
||||||
|
let dir = TempDir::new()?;
|
||||||
|
File::create(dir.path().join("main.py"))?;
|
||||||
|
|
||||||
|
let expected = format!(
|
||||||
|
"via {} ",
|
||||||
|
Segment::new("python")
|
||||||
|
.set_value("🐍 v3.7.2")
|
||||||
|
.set_style(Color::Yellow.bold())
|
||||||
|
);
|
||||||
|
let actual = common::render_module("python", &dir.path());
|
||||||
|
assert_eq!(expected, actual);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user