Skip to content

Commit

Permalink
Expose 'trust_ci' as a feature flag under CI
Browse files Browse the repository at this point in the history
$CI was chosen instead of $TRAVIS and the ! -z check was done such that
this can work on all CI platforms (at least GitLab CI, Travis CI, AppVeyor,
and Circle CI).
  • Loading branch information
Bryant Mairs committed Oct 27, 2017
1 parent 09b7ec6 commit 7dcf4a8
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ sudo: required

env:
global:
# TODO Change this to passthrough additional environment variables. Additional items
# can be appended with a space as a delimiter. The default of "RUSTFLAGS" allows the
# "trust_ci" feature to be passed-through to be compiled by Rust. See the Cross
# README for more details.
- CROSS_BUILD_ENV_PASSTHROUGH=RUSTFLAGS
# TODO Update this to match the name of your project.
- CRATE_NAME=trust

Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ This is an overview of what must / can be changed:

- the "package phase". Tweak what goes into the release tarball / zipfile.

### Managing test failures

Some tests will fail when run in the `qemu` emulated environment even though
they succeed on the actual hardware. In this case the `trust_ci` feature flag
has been exposed to the build, test, and run stages. You can therefore disable
some tests by putting `#[cfg_attr(trust_ci, ignore)]` before them. These tests
will show up as 'ignored' in the test output.

### Generate binary releases

You only need to push an **annotated** tag to kick off the build process.
Expand Down
5 changes: 5 additions & 0 deletions ci/script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ set -ex

# TODO This is the "test phase", tweak it as you see fit
main() {
# Add a cfg spec to allow disabling specific tests under CI.
if [ ! -z $CI ]; then
export RUSTFLAGS+=" --cfg=trust_ci"
fi

cross build --target $TARGET
cross build --target $TARGET --release

Expand Down
6 changes: 6 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,10 @@ pub fn hello() {
mod tests {
#[test]
fn it_works() {}

#[test]
#[cfg_attr(trust_ci, ignore)]
fn ignore_in_ci() {
assert!(false);
}
}

0 comments on commit 7dcf4a8

Please sign in to comment.