mirror of
https://github.com/nushell/nushell.git
synced 2025-06-30 22:50:14 +02:00
Allow int
type as a valid limit value (#11346)
# Description This PR allows `int` type as a valid limit value for `ulimit`, so there is no need to use `into string` to convert limit values in the tests. # User-Facing Changes N/A # Tests + Formatting Make sure you've run and fixed any issues with these commands: - [x] add `commands::ulimit::limit_set_invalid3` - [x] add `commands::ulimit::limit_set_invalid4` - [x] add `commands::ulimit::limit_set_invalid5` - [x] `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - [x] `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used` to check that you're using the standard code style - [x] `cargo test --workspace` to check that all tests pass (on Windows make sure to [enable developer mode](https://learn.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging)) - [x] `cargo run -- -c "use std testing; testing run-tests --path crates/nu-std"` to run the tests for the standard library
This commit is contained in:
@ -7,9 +7,9 @@ fn limit_set_soft1() {
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
"
|
||||
let soft = (ulimit -s | first | get soft | into string);
|
||||
let soft = (ulimit -s | first | get soft);
|
||||
ulimit -s -H $soft;
|
||||
let hard = (ulimit -s | first | get hard | into string);
|
||||
let hard = (ulimit -s | first | get hard);
|
||||
$soft == $hard
|
||||
"
|
||||
));
|
||||
@ -24,9 +24,9 @@ fn limit_set_soft2() {
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
"
|
||||
let soft = (ulimit -s | first | get soft | into string);
|
||||
let soft = (ulimit -s | first | get soft);
|
||||
ulimit -s -H soft;
|
||||
let hard = (ulimit -s | first | get hard | into string);
|
||||
let hard = (ulimit -s | first | get hard);
|
||||
$soft == $hard
|
||||
"
|
||||
));
|
||||
@ -41,9 +41,9 @@ fn limit_set_hard1() {
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
"
|
||||
let hard = (ulimit -s | first | get hard | into string);
|
||||
let hard = (ulimit -s | first | get hard);
|
||||
ulimit -s $hard;
|
||||
let soft = (ulimit -s | first | get soft | into string);
|
||||
let soft = (ulimit -s | first | get soft);
|
||||
$soft == $hard
|
||||
"
|
||||
));
|
||||
@ -58,9 +58,9 @@ fn limit_set_hard2() {
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
"
|
||||
let hard = (ulimit -s | first | get hard | into string);
|
||||
let hard = (ulimit -s | first | get hard);
|
||||
ulimit -s hard;
|
||||
let soft = (ulimit -s | first | get soft | into string);
|
||||
let soft = (ulimit -s | first | get soft);
|
||||
$soft == $hard
|
||||
"
|
||||
));
|
||||
@ -79,7 +79,7 @@ fn limit_set_invalid1() {
|
||||
match $hard {
|
||||
\"unlimited\" => { echo \"unlimited\" },
|
||||
$x => {
|
||||
let new = ($x + 1 | into string);
|
||||
let new = $x + 1;
|
||||
ulimit -s $new
|
||||
}
|
||||
}
|
||||
@ -96,6 +96,21 @@ fn limit_set_invalid1() {
|
||||
#[test]
|
||||
fn limit_set_invalid2() {
|
||||
Playground::setup("limit_set_invalid2", |dirs, _sandbox| {
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(),
|
||||
"
|
||||
let val = -100;
|
||||
ulimit -c $val
|
||||
"
|
||||
);
|
||||
|
||||
assert!(actual.err.contains("can't convert i64 to rlim_t"));
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn limit_set_invalid3() {
|
||||
Playground::setup("limit_set_invalid3", |dirs, _sandbox| {
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(),
|
||||
"
|
||||
@ -103,6 +118,53 @@ fn limit_set_invalid2() {
|
||||
"
|
||||
);
|
||||
|
||||
assert!(actual.err.contains("Can't convert to rlim_t."));
|
||||
assert!(actual
|
||||
.err
|
||||
.contains("Only unlimited, soft and hard are supported for strings"));
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn limit_set_invalid4() {
|
||||
Playground::setup("limit_set_invalid4", |dirs, _sandbox| {
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(),
|
||||
"
|
||||
ulimit -c 100.0
|
||||
"
|
||||
);
|
||||
|
||||
assert!(actual.err.contains("string or int required"));
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn limit_set_invalid5() {
|
||||
use nix::sys::resource::rlim_t;
|
||||
|
||||
let max = (rlim_t::MAX / 1024) + 1;
|
||||
|
||||
Playground::setup("limit_set_invalid5", |dirs, _sandbox| {
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
format!(
|
||||
"
|
||||
let hard = (ulimit -c | first | get hard);
|
||||
match $hard {{
|
||||
\"unlimited\" => {{
|
||||
ulimit -c -S 0;
|
||||
ulimit -c {max};
|
||||
ulimit -c
|
||||
| first
|
||||
| get soft
|
||||
}},
|
||||
_ => {{
|
||||
echo \"unlimited\"
|
||||
}}
|
||||
}}
|
||||
").as_str()
|
||||
));
|
||||
|
||||
assert!(actual.out.eq("unlimited"));
|
||||
});
|
||||
}
|
||||
|
Reference in New Issue
Block a user