Skip to content

Tests fail due to missing CARGO_PKG_NAME when running without cargo #14

@konstin

Description

@konstin

When running test binaries directly, trybuild tests fail because CARGO_PKG_NAME is missing. This is e.g. the case when collecting coverage data (example travis build: https://travis-ci.org/PyO3/pyo3/jobs/541071250).

Line that requires CARGO_PKG_NAME:

let crate_name = env::var("CARGO_PKG_NAME").map_err(Error::PkgName)?;

Full backtrace
$ RUST_BACKTRACE=1 target/debug/deps/test_compile_error-8cb93379bda46ad2

running 1 test
ERROR: failed to detect CARGO_PKG_NAME: environment variable not found

test test_compile_errors ... FAILED

failures:

---- test_compile_errors stdout ----
thread 'test_compile_errors' panicked at 'tests failed', /home/konsti/.cargo/registry/src/github.com-1ecc6299db9ec823/trybuild-1.0.4/src/run.rs:37:13
stack backtrace:
   0: backtrace::backtrace::libunwind::trace
             at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.25/src/backtrace/libunwind.rs:97
   1: backtrace::backtrace::trace_unsynchronized
             at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.25/src/backtrace/mod.rs:66
   2: std::sys_common::backtrace::_print
             at src/libstd/sys_common/backtrace.rs:47
   3: std::sys_common::backtrace::print
             at src/libstd/sys_common/backtrace.rs:36
   4: std::panicking::default_hook::{{closure}}
             at src/libstd/panicking.rs:197
   5: std::panicking::default_hook
             at src/libstd/panicking.rs:208
   6: std::panicking::rust_panic_with_hook
             at src/libstd/panicking.rs:474
   7: std::panicking::begin_panic
             at /rustc/5d8f59f4b1473217c2de7e02330b5aaae70a1668/src/libstd/panicking.rs:408
   8: trybuild::run::<impl trybuild::Runner>::run::{{closure}}
             at /home/konsti/.cargo/registry/src/github.com-1ecc6299db9ec823/trybuild-1.0.4/src/run.rs:37
   9: core::result::Result<T,E>::unwrap_or_else
             at /rustc/5d8f59f4b1473217c2de7e02330b5aaae70a1668/src/libcore/result.rs:766
  10: trybuild::run::<impl trybuild::Runner>::run
             at /home/konsti/.cargo/registry/src/github.com-1ecc6299db9ec823/trybuild-1.0.4/src/run.rs:35
  11: <trybuild::TestCases as core::ops::drop::Drop>::drop
             at /home/konsti/.cargo/registry/src/github.com-1ecc6299db9ec823/trybuild-1.0.4/src/lib.rs:272
  12: core::ptr::real_drop_in_place
             at /rustc/5d8f59f4b1473217c2de7e02330b5aaae70a1668/src/libcore/ptr/mod.rs:197
  13: test_compile_error::test_compile_errors
             at tests/test_compile_error.rs:5
  14: test_compile_error::test_compile_errors::{{closure}}
             at tests/test_compile_error.rs:2
  15: core::ops::function::FnOnce::call_once
             at /rustc/5d8f59f4b1473217c2de7e02330b5aaae70a1668/src/libcore/ops/function.rs:231
  16: <alloc::boxed::Box<F> as core::ops::function::FnOnce<A>>::call_once
             at /rustc/5d8f59f4b1473217c2de7e02330b5aaae70a1668/src/liballoc/boxed.rs:746
  17: __rust_maybe_catch_panic
             at src/libpanic_unwind/lib.rs:85
  18: std::panicking::try
             at /rustc/5d8f59f4b1473217c2de7e02330b5aaae70a1668/src/libstd/panicking.rs:272
  19: std::panic::catch_unwind
             at /rustc/5d8f59f4b1473217c2de7e02330b5aaae70a1668/src/libstd/panic.rs:388
  20: test::run_test::run_test_inner::{{closure}}
             at src/libtest/lib.rs:1466
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.


failures:
    test_compile_errors

test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions