mirror of
https://github.com/Llewellynvdm/starship.git
synced 2024-11-09 14:51:04 +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:
|
||||
# Install Rust at a fixed version for integration tests to pass
|
||||
- script: |
|
||||
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"
|
||||
displayName: Windows install Rust
|
||||
displayName: Windows install rust
|
||||
condition: eq( variables['Agent.OS'], 'Windows_NT' )
|
||||
- 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"
|
||||
displayName: Install a fixed version of Rust
|
||||
displayName: Install rust
|
||||
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
|
||||
displayName: Install Rustfmt
|
||||
- script: cargo fmt --all -- --check
|
||||
displayName: Run Rustfmt
|
||||
displayName: Run rustfmt
|
||||
|
||||
# Run the integration tests in a Docker container
|
||||
- job: "Docker"
|
||||
@ -36,19 +36,19 @@ jobs:
|
||||
matrix:
|
||||
windows-stable:
|
||||
imageName: "vs2017-win2016"
|
||||
rustup_toolchain: stable
|
||||
RUSTUP_TOOLCHAIN: stable
|
||||
mac-stable:
|
||||
imageName: "macos-10.13"
|
||||
rustup_toolchain: stable
|
||||
RUSTUP_TOOLCHAIN: stable
|
||||
linux-stable:
|
||||
imageName: "ubuntu-16.04"
|
||||
rustup_toolchain: stable
|
||||
RUSTUP_TOOLCHAIN: stable
|
||||
linux-beta:
|
||||
imageName: "ubuntu-16.04"
|
||||
rustup_toolchain: beta
|
||||
RUSTUP_TOOLCHAIN: beta
|
||||
linux-nightly:
|
||||
imageName: "ubuntu-16.04"
|
||||
rustup_toolchain: nightly
|
||||
RUSTUP_TOOLCHAIN: nightly
|
||||
pool:
|
||||
vmImage: "ubuntu-16.04"
|
||||
steps:
|
||||
@ -60,13 +60,14 @@ jobs:
|
||||
- task: GoTool@0
|
||||
inputs:
|
||||
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"
|
||||
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: rustup run $RUSTUP_TOOLCHAIN cargo build --all
|
||||
- script: cargo build
|
||||
displayName: Cargo build
|
||||
- script: rustup run $RUSTUP_TOOLCHAIN cargo test -- --ignored
|
||||
- script: cargo test -- --ignored
|
||||
displayName: Cargo test
|
||||
|
@ -1,4 +1,4 @@
|
||||
FROM rust:1.34.0
|
||||
FROM rust:latest
|
||||
|
||||
# Install Node.js
|
||||
ENV NODE_VERSION 12.0.0
|
||||
@ -25,7 +25,18 @@ ENV PATH $GO_ROOT/bin:$PATH
|
||||
RUN goenv install $GO_VERSION
|
||||
RUN goenv global $GO_VERSION
|
||||
# Check that Go was correctly installed
|
||||
|
||||
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
|
||||
RUN USER=root cargo new --bin starship
|
||||
@ -40,8 +51,7 @@ RUN mkdir benches
|
||||
RUN touch benches/my_benchmark.rs
|
||||
|
||||
# This is a dummy build to get dependencies cached
|
||||
RUN rustup install stable
|
||||
RUN rustup run stable cargo build --release
|
||||
RUN cargo build --release
|
||||
|
||||
# Delete the dummy build
|
||||
RUN rm -rf /starship
|
||||
@ -50,5 +60,4 @@ RUN rm -rf /starship
|
||||
RUN mkdir starship
|
||||
WORKDIR /starship
|
||||
|
||||
# Run with rustup to use stable instead of the Rust default
|
||||
CMD [ "rustup", "run", "stable", "cargo", "test", "--", "--ignored"]
|
||||
CMD ["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…
Reference in New Issue
Block a user