Skip to content
This repository was archived by the owner on Aug 12, 2021. It is now read-only.

libtest on stable Rust #11

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 29 additions & 4 deletions .azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,39 @@ trigger:
- master

jobs:
- template: ci/azure-job-test-all.yml
- template: ci/azure-job-test-nightly.yml
parameters:
vmImage: vs2017-win2016
name: x86_64_msvc
name: x86_64_msvc_nightly
target: x86_64-pc-windows-msvc
- template: ci/azure-job-test-all.yml
toolchain: nightly-x86_64-msvc
- template: ci/azure-job-test-stable.yml
parameters:
vmImage: vs2017-win2016
name: x86_64_msvc_beta
target: x86_64-pc-windows-msvc
toolchain: beta-x86_64-msvc
- template: ci/azure-job-test-stable.yml
parameters:
vmImage: vs2017-win2016
name: x86_64_msvc_stable
target: x86_64-pc-windows-msvc
toolchain: stable-x86_64-msvc
- template: ci/azure-job-test-nightly.yml
parameters:
vmImage: vs2017-win2016
toolchain: nightly-x86_64-gnu
name: x86_64_mingw
name: x86_64_mingw_nightly
target: x86_64-pc-windows-gnu
- template: ci/azure-job-test-stable.yml
parameters:
vmImage: vs2017-win2016
toolchain: beta-x86_64-gnu
name: x86_64_mingw_beta
target: x86_64-pc-windows-gnu
- template: ci/azure-job-test-stable.yml
parameters:
vmImage: vs2017-win2016
toolchain: stable-x86_64-gnu
name: x86_64_mingw_stable
target: x86_64-pc-windows-gnu
55 changes: 49 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ matrix:
- name: "Tools"
install: true
script: sh ci/tools.sh

# cross targets:
- name: "Integration"
install: true
script: sh ci/integration.sh
- name: "aarch64-linux-android"
env: TARGET=aarch64-linux-android CROSS=1
- name: "aarch64-unknown-linux-gnu"
Expand Down Expand Up @@ -39,19 +40,37 @@ matrix:
packages:
- gcc-multilib

- name: "i686-apple-darwin"
- name: "i686-apple-darwin (nightly)"
env: TARGET=i686-apple-darwin
os: osx
osx_image: xcode10
- name: "i686-apple-darwin (beta)"
env: TARGET=i686-apple-darwin
os: osx
rust: beta
osx_image: xcode10
- name: "i686-apple-darwin (stable)"
env: TARGET=i686-apple-darwin
os: osx
rust: stable
osx_image: xcode10
- name: "i686-linux-android"
env: TARGET=i686-linux-android CROSS=1
- name: "i686-pc-windows-gnu"
env: TARGET=i686-pc-windows-gnu CROSS=1
- name: "i686-unknown-freebsd"
env: TARGET=i686-unknown-freebsd NORUN=1 CROSS=1
- name: "i686-unknown-linux-gnu"
- name: "i686-unknown-linux-gnu (nightly)"
env: TARGET=i686-unknown-linux-gnu CROSS=1
addons: *gcc_multilib
- name: "i686-unknown-linux-gnu (beta)"
env: TARGET=i686-unknown-linux-gnu CROSS=1
addons: *gcc_multilib
rust: beta
- name: "i686-unknown-linux-gnu (stable)"
env: TARGET=i686-unknown-linux-gnu CROSS=1
addons: *gcc_multilib
rust: stable
- name: "i686-unknown-linux-musl"
env: TARGET=i686-unknown-linux-musl CROSS=1
- name: "mips-unknown-linux-gnu"
Expand All @@ -72,25 +91,49 @@ matrix:
env: TARGET=s390x-unknown-linux-gnu CROSS=1 NORUN=1
- name: "sparc64-unknown-linux-gnu"
env: TARGET=sparc64-unknown-linux-gnu CROSS=1 NORUN=1
- name: "x86_64-apple-darwin"
- name: "x86_64-apple-darwin (nightly)"
env: TARGET=x86_64-apple-darwin
os: osx
osx_image: xcode10
install: true
- name: "x86_64-apple-darwin (beta)"
env: TARGET=x86_64-apple-darwin
os: osx
osx_image: xcode10
install: true
rust: beta
- name: "x86_64-apple-darwin (stable)"
env: TARGET=x86_64-apple-darwin
os: osx
osx_image: xcode10
install: true
rust: stable
- name: "x86_64-linux-android"
env: TARGET=x86_64-linux-android CROSS=1
- name: "x86_64-sun-solaris"
env: TARGET=x86_64-sun-solaris NORUN=1 CROSS=1
- name: "x86_64-unknown-freebsd"
env: TARGET=x86_64-unknown-freebsd NORUN=1 CROSS=1
- name: "x86_64-unknown-linux-gnu"
- name: "x86_64-unknown-linux-gnu (nightly)"
env: TARGET=x86_64-unknown-linux-gnu
install: true
- name: "x86_64-unknown-linux-gnu (beta)"
env: TARGET=x86_64-unknown-linux-gnu
install: true
rust: beta
- name: "x86_64-unknown-linux-gnu (stable)"
env: TARGET=x86_64-unknown-linux-gnu
install: true
rust: stable
- name: "x86_64-unknown-linux-musl"
env: TARGET=x86_64-unknown-linux-musl CROSS=1
- name: "x86_64-unknown-netbsd"
env: TARGET=x86_64-unknown-netbsd NORUN=1 CROSS=1

allow_failures:
# FIXME: the compiletest-rs crate needs to be updated to libtest 0.0.2
- name: "Integration"

install:
- travis_retry rustup target add $TARGET
- |
Expand Down
22 changes: 20 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,20 @@
[workspace]
members = [ "libtest" ]
[package]
authors = ["The Rust Project Developers"]
name = "libtest"
version = "0.0.2"
edition = "2018"
description = "Rust's built in unit-test and micro-benchmarking framework"
license = "MIT/Apache-2.0"
documentation = "https://docs.rs/libtest"
homepage = "https://github.com/rust-lang/libtest"
repository = "https://github.com/rust-lang/libtest"
readme = "README.md"

[dependencies]
getopts = "0.2"
termcolor = "1.0"
libc = "0.2"

[features]
default = []
unstable = []
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@ libtest - Rust's built-in unit-testing and benchmarking framework
See [The Rust Programming Language chapter on
Testing](https://doc.rust-lang.org/book/ch11-00-testing.html).

## Cargo features

* `unstable` (disabled by default): enables nightly features. Currently, this enables:
* `feature(set_stdio)`: better output reporting
* `feature(panic_unwind)`: explicitly links against the `panic_unwind` crate
on platforms that support it, but avoid that on platforms that do not. This
allows using `libtest` on platforms like `aarch64-pc-windows-msvc` which do
not yet support `panic_unwind`.
* `feature(termination_trait_lib)`: exposes the `assert_test_result` API
* `feature(test)`: uses `test::black_box` in benchmarks. On stable Rust, this is
worked around with volatile loads and stores which aren't as good.

## Platform support

* "build" shows whether the library compiles
Expand Down
17 changes: 17 additions & 0 deletions ci/azure-job-test-nightly.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
parameters:
toolchain: 'nightly'
vmImage: 'ubuntu-16.04'
name: ''

jobs:
- job: ${{ parameters.name }}
pool:
vmImage: ${{ parameters.vmImage }}
steps:
- template: azure-install-rust.yml
parameters:
toolchain: ${{ parameters.toolchain }}
- script: cargo test -vv --all --target ${{ parameters.target }}
- script: cargo test -vv --all --release --target ${{ parameters.target }}
- script: cargo test -vv --all --target ${{ parameters.target }} --features=unstable
- script: cargo test -vv --all --release --target ${{ parameters.target }} --features=unstable
File renamed without changes.
14 changes: 14 additions & 0 deletions ci/integration.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env sh

set -ex

# compile-test
rm -r compiletest-rs || true
git clone https://github.com/laumann/compiletest-rs
(
cd compiletest-rs
sed -i '' 's@libtest = "0.0.2"@libtest = { path = "..", features = [ "unstable" ] }@g' Cargo.toml
echo "[workspace]" >> Cargo.toml
cargo build
cargo build --features=unstable
)
5 changes: 5 additions & 0 deletions ci/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,8 @@ fi

"${CARGO}" "${CMD}" -vv --all --target="${TARGET}"
"${CARGO}" "${CMD}" -vv --all --target="${TARGET}" --release

if [ "${TRAVIS_RUST_VERSION}" = "nightly" ]; then
"${CARGO}" "${CMD}" -vv --all --target="${TARGET}" --features=unstable
"${CARGO}" "${CMD}" -vv --all --target="${TARGET}" --features=unstable --release
fi
20 changes: 0 additions & 20 deletions libtest/Cargo.toml

This file was deleted.

1 change: 0 additions & 1 deletion libtest/README.md

This file was deleted.

File renamed without changes.
File renamed without changes.
24 changes: 14 additions & 10 deletions libtest/formatters/pretty.rs → src/formatters/pretty.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use super::*;
use termcolor::Color;

pub(crate) struct PrettyFormatter<T> {
out: OutputLocation<T>,
Expand Down Expand Up @@ -31,29 +32,29 @@ impl<T: Write> PrettyFormatter<T> {
}

pub fn write_ok(&mut self) -> io::Result<()> {
self.write_short_result("ok", term::color::GREEN)
self.write_short_result("ok", Color::Green)
}

pub fn write_failed(&mut self) -> io::Result<()> {
self.write_short_result("FAILED", term::color::RED)
self.write_short_result("FAILED", Color::Red)
}

pub fn write_ignored(&mut self) -> io::Result<()> {
self.write_short_result("ignored", term::color::YELLOW)
self.write_short_result("ignored", Color::Yellow)
}

pub fn write_allowed_fail(&mut self) -> io::Result<()> {
self.write_short_result("FAILED (allowed)", term::color::YELLOW)
self.write_short_result("FAILED (allowed)", Color::Yellow)
}

pub fn write_bench(&mut self) -> io::Result<()> {
self.write_pretty("bench", term::color::CYAN)
self.write_pretty("bench", Color::Cyan)
}

pub fn write_short_result(
&mut self,
result: &str,
color: term::color::Color,
color: Color,
) -> io::Result<()> {
self.write_pretty(result, color)?;
self.write_plain("\n")
Expand All @@ -62,12 +63,15 @@ impl<T: Write> PrettyFormatter<T> {
pub fn write_pretty(
&mut self,
word: &str,
color: term::color::Color,
color: Color,
) -> io::Result<()> {
use termcolor::WriteColor;
match self.out {
OutputLocation::Pretty(ref mut term) => {
if self.use_color {
term.fg(color)?;
term.set_color(
termcolor::ColorSpec::new().set_fg(Some(color)),
)?;
}
term.write_all(word.as_bytes())?;
if self.use_color {
Expand Down Expand Up @@ -223,9 +227,9 @@ impl<T: Write> OutputFormatter for PrettyFormatter<T> {

if success {
// There's no parallelism at this point so it's safe to use color
self.write_pretty("ok", term::color::GREEN)?;
self.write_pretty("ok", Color::Green)?;
} else {
self.write_pretty("FAILED", term::color::RED)?;
self.write_pretty("FAILED", Color::Red)?;
}

let s = if state.allowed_fail > 0 {
Expand Down
Loading