integration_tests/env.rs
1// Copyright (c) The nextest Contributors
2// SPDX-License-Identifier: MIT OR Apache-2.0
3
4#[track_caller]
5pub fn set_env_vars() {
6 // SAFETY:
7 // https://nexte.st/docs/configuration/env-vars/#altering-the-environment-within-tests
8 unsafe {
9 // The dynamic library tests require this flag.
10 std::env::set_var("RUSTFLAGS", "-C prefer-dynamic");
11
12 // Set CARGO_TERM_COLOR to never to ensure that ANSI color codes don't
13 // interfere with the output.
14 std::env::set_var("CARGO_TERM_COLOR", "never");
15
16 // This environment variable is required to test the #[bench] fixture.
17 // Note that THIS IS FOR TEST CODE ONLY. NEVER USE THIS IN PRODUCTION.
18 std::env::set_var("RUSTC_BOOTSTRAP", "1");
19
20 // Disable the tests which check for environment variables being set in
21 // `config.toml`, as they won't be in the search path when running
22 // integration tests.
23 std::env::set_var("__NEXTEST_NO_CHECK_CARGO_ENV_VARS", "1");
24
25 // Disable the tests which check for environment variables being set in
26 // `config.toml`, as they won't be in the search path when running
27 // integration tests.
28 std::env::set_var("__NEXTEST_NO_CHECK_CARGO_ENV_VARS", "1");
29
30 // Display empty STDOUT and STDERR lines in the output of failed tests.
31 // This allows tests which make sure outputs are being displayed to
32 // work.
33 std::env::set_var("__NEXTEST_DISPLAY_EMPTY_OUTPUTS", "1");
34
35 // Unset NEXTEST_PROFILE because we don't want to let it interfere with
36 // the tests. But ensure that it's set first.
37 std::env::var("NEXTEST_PROFILE").expect("NEXTEST_PROFILE should be set");
38 std::env::remove_var("NEXTEST_PROFILE");
39
40 // Remove OUT_DIR from the environment, as it interferes with tests
41 // (some of them expect that OUT_DIR isn't set.)
42 std::env::remove_var("OUT_DIR");
43 }
44}