mirror of
https://github.com/nushell/nushell
synced 2024-12-25 12:33:17 +00:00
Fix unit tests on Android (#10224)
# Description * The path to the binaries for tests is slightly incorrect. It is missing the build target when it is set with the `CARGO_BUILD_TARGET` environment variable. For example, when `CARGO_BUILD_TARGET` is set to `aarch64-linux-android`, the path to the `nu` binary is: `./target/aarch64-linux-android/debug/nu` rather than `./target/debug/nu` This is common on Termux since the default target that rustc detects can cause problems on some projects, such as [python's `cryptography` package](https://github.com/pyca/cryptography/issues/7248). This technically isn't a problem specific to Android, but is more likely to happen on Android due to the latter. * Additionally, the existing variable named `NUSHELL_CARGO_TARGET` is in fact the profile, not the build target, so this was renamed to `NUSHELL_CARGO_PROFILE`. This change is included because without the rename, the build system would be using `CARGO_BUILD_TARGET` for the build target and `NUSHELL_CARGO_TARGET` for the build profile, which is confusing. * `std path add` tests were missing `android` test # User-Facing Changes For those who would like to build nushell on Termux, the unit tests will pass now.
This commit is contained in:
parent
eca9f461da
commit
9a4dad6ca1
7 changed files with 25 additions and 16 deletions
2
.github/workflows/ci.yml
vendored
2
.github/workflows/ci.yml
vendored
|
@ -7,7 +7,7 @@ on:
|
||||||
name: continuous-integration
|
name: continuous-integration
|
||||||
|
|
||||||
env:
|
env:
|
||||||
NUSHELL_CARGO_TARGET: ci
|
NUSHELL_CARGO_PROFILE: ci
|
||||||
NU_LOG_LEVEL: DEBUG
|
NU_LOG_LEVEL: DEBUG
|
||||||
CLIPPY_OPTIONS: "-D warnings -D clippy::unwrap_used"
|
CLIPPY_OPTIONS: "-D warnings -D clippy::unwrap_used"
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,13 @@ def path_add [] {
|
||||||
assert equal (get_path) ["fooooo", "foo", "bar", "baz"]
|
assert equal (get_path) ["fooooo", "foo", "bar", "baz"]
|
||||||
|
|
||||||
load-env {$path_name: []}
|
load-env {$path_name: []}
|
||||||
let target_paths = {linux: "foo", windows: "bar", macos: "baz"}
|
|
||||||
|
let target_paths = {
|
||||||
|
linux: "foo",
|
||||||
|
windows: "bar",
|
||||||
|
macos: "baz",
|
||||||
|
android: "quux",
|
||||||
|
}
|
||||||
|
|
||||||
std path add $target_paths
|
std path add $target_paths
|
||||||
assert equal (get_path) [($target_paths | get $nu.os-info.name)]
|
assert equal (get_path) [($target_paths | get $nu.os-info.name)]
|
||||||
|
|
|
@ -23,7 +23,7 @@ pub fn ensure_plugins_built() {
|
||||||
let cargo_path = env!("CARGO");
|
let cargo_path = env!("CARGO");
|
||||||
let mut arguments = vec!["build", "--package", "nu_plugin_*", "--quiet"];
|
let mut arguments = vec!["build", "--package", "nu_plugin_*", "--quiet"];
|
||||||
|
|
||||||
let profile = std::env::var("NUSHELL_CARGO_TARGET");
|
let profile = std::env::var("NUSHELL_CARGO_PROFILE");
|
||||||
if let Ok(profile) = &profile {
|
if let Ok(profile) = &profile {
|
||||||
arguments.push("--profile");
|
arguments.push("--profile");
|
||||||
arguments.push(profile);
|
arguments.push(profile);
|
||||||
|
|
|
@ -233,18 +233,21 @@ pub fn root() -> PathBuf {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn binaries() -> PathBuf {
|
pub fn binaries() -> PathBuf {
|
||||||
let mut build_type = "debug".to_string();
|
let build_target = std::env::var("CARGO_BUILD_TARGET").unwrap_or(String::new());
|
||||||
if !cfg!(debug_assertions) {
|
|
||||||
build_type = "release".to_string()
|
let profile = if let Ok(env_profile) = std::env::var("NUSHELL_CARGO_PROFILE") {
|
||||||
}
|
env_profile
|
||||||
if let Ok(target) = std::env::var("NUSHELL_CARGO_TARGET") {
|
} else if cfg!(debug_assertions) {
|
||||||
build_type = target;
|
"debug".into()
|
||||||
}
|
} else {
|
||||||
|
"release".into()
|
||||||
|
};
|
||||||
|
|
||||||
std::env::var("CARGO_TARGET_DIR")
|
std::env::var("CARGO_TARGET_DIR")
|
||||||
.ok()
|
.map(PathBuf::from)
|
||||||
.map(|target_dir| PathBuf::from(target_dir).join(&build_type))
|
.unwrap_or_else(|_| root().join("target"))
|
||||||
.unwrap_or_else(|| root().join(format!("target/{}", &build_type)))
|
.join(build_target)
|
||||||
|
.join(profile)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn fixtures() -> PathBuf {
|
pub fn fixtures() -> PathBuf {
|
||||||
|
|
|
@ -45,7 +45,7 @@ let start = (date now)
|
||||||
# Some of the internal tests rely on the exact cargo profile
|
# Some of the internal tests rely on the exact cargo profile
|
||||||
# (This is somewhat criminal itself)
|
# (This is somewhat criminal itself)
|
||||||
# but we have to signal to the tests that we use the `ci` `--profile`
|
# but we have to signal to the tests that we use the `ci` `--profile`
|
||||||
$env.NUSHELL_CARGO_TARGET = "ci"
|
$env.NUSHELL_CARGO_PROFILE = "ci"
|
||||||
|
|
||||||
# Manual gathering of coverage to catch invocation of the `nu` binary.
|
# Manual gathering of coverage to catch invocation of the `nu` binary.
|
||||||
# This is relevant for tests using the `nu!` macro from `nu-test-support`
|
# This is relevant for tests using the `nu!` macro from `nu-test-support`
|
||||||
|
|
|
@ -17,7 +17,7 @@ REPO_ROOT=$(dirname $DIR)
|
||||||
# Some of the internal tests rely on the exact cargo profile
|
# Some of the internal tests rely on the exact cargo profile
|
||||||
# (This is somewhat criminal itself)
|
# (This is somewhat criminal itself)
|
||||||
# but we have to signal to the tests that we use the `ci` `--profile`
|
# but we have to signal to the tests that we use the `ci` `--profile`
|
||||||
export NUSHELL_CARGO_TARGET=ci
|
export NUSHELL_CARGO_PROFILE=ci
|
||||||
|
|
||||||
# Manual gathering of coverage to catch invocation of the `nu` binary.
|
# Manual gathering of coverage to catch invocation of the `nu` binary.
|
||||||
# This is relevant for tests using the `nu!` macro from `nu-test-support`
|
# This is relevant for tests using the `nu!` macro from `nu-test-support`
|
||||||
|
|
|
@ -436,7 +436,7 @@ def compute-coverage [] {
|
||||||
# - https://github.com/andythigpen/nvim-coverage (probably needs some additional config)
|
# - https://github.com/andythigpen/nvim-coverage (probably needs some additional config)
|
||||||
export def cov [] {
|
export def cov [] {
|
||||||
let start = (date now)
|
let start = (date now)
|
||||||
$env.NUSHELL_CARGO_TARGET = "ci"
|
$env.NUSHELL_CARGO_PROFILE = "ci"
|
||||||
|
|
||||||
compute-coverage
|
compute-coverage
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue