nushell/crates/nu-command/tests/commands/error_make.rs

42 lines
948 B
Rust
Raw Normal View History

use nu_test_support::nu;
#[test]
fn error_label_works() {
let actual = nu!("error make {msg:foo label:{text:unseen}}");
assert!(actual.err.contains("unseen"));
assert!(actual.err.contains("╰──"));
}
#[test]
fn no_span_if_unspanned() {
let actual = nu!("error make -u {msg:foo label:{text:unseen}}");
assert!(!actual.err.contains("unseen"));
}
FIX: do not allow *start > end* in `error make` spans (#8570) This should close #8567. # Description this PR throws an error when `start > end` in the most complete branch of `ErrorMake::run`, i.e. when `$.msg`, `$.label.text`, `$.label.start` and `$.label.end` are defined. i've also added a `error_start_bigger_than_end_should_fail` test to check that it does indeed return the right error. # User-Facing Changes no more crash when manipulating span bounds and a clear error, e.g. ```bash >_ error make {msg: "msg" label: {text: "text" start: 1010 end: 1000}} Error: × invalid error format. ╭─[entry #3:1:1] 1 │ error make {msg: "msg" label: {text: "text" start: 1010 end: 1000}} · ──────────────────┬───────────────── · ╰── `$.label.start` is stricly bigger than `$.label.end` ╰──── help: 1010 > 1000 ``` or ```bash >_ error make { ::: msg: "msg" ::: label: { ::: text: "text" ::: start: ($nu.scope.engine_state.source_bytes - 90) ::: end: ($nu.scope.engine_state.source_bytes - 100) ::: } ::: } Error: × invalid error format. ╭─[entry #4:2:1] 2 │ msg: "msg" 3 │ ╭─▶ label: { 4 │ │ text: "text" 5 │ │ start: ($nu.scope.engine_state.source_bytes - 90) 6 │ │ end: ($nu.scope.engine_state.source_bytes - 100) 7 │ ├─▶ } · ╰──── `$.label.start` is stricly bigger than `$.label.end` 8 │ } ╰──── help: 204525 > 204515 ``` # Tests + Formatting - :green_circle: `toolkit fmt` - :green_circle: `toolkit clippy` - :red_circle: `toolkit test` # After Submitting ``` $nothing ```
2023-03-23 20:31:06 +01:00
#[test]
fn error_start_bigger_than_end_should_fail() {
let actual = nu!("
error make {
msg: foo
label: {
text: bar
span: {start: 456 end: 123}
}
}
");
FIX: do not allow *start > end* in `error make` spans (#8570) This should close #8567. # Description this PR throws an error when `start > end` in the most complete branch of `ErrorMake::run`, i.e. when `$.msg`, `$.label.text`, `$.label.start` and `$.label.end` are defined. i've also added a `error_start_bigger_than_end_should_fail` test to check that it does indeed return the right error. # User-Facing Changes no more crash when manipulating span bounds and a clear error, e.g. ```bash >_ error make {msg: "msg" label: {text: "text" start: 1010 end: 1000}} Error: × invalid error format. ╭─[entry #3:1:1] 1 │ error make {msg: "msg" label: {text: "text" start: 1010 end: 1000}} · ──────────────────┬───────────────── · ╰── `$.label.start` is stricly bigger than `$.label.end` ╰──── help: 1010 > 1000 ``` or ```bash >_ error make { ::: msg: "msg" ::: label: { ::: text: "text" ::: start: ($nu.scope.engine_state.source_bytes - 90) ::: end: ($nu.scope.engine_state.source_bytes - 100) ::: } ::: } Error: × invalid error format. ╭─[entry #4:2:1] 2 │ msg: "msg" 3 │ ╭─▶ label: { 4 │ │ text: "text" 5 │ │ start: ($nu.scope.engine_state.source_bytes - 90) 6 │ │ end: ($nu.scope.engine_state.source_bytes - 100) 7 │ ├─▶ } · ╰──── `$.label.start` is stricly bigger than `$.label.end` 8 │ } ╰──── help: 204525 > 204515 ``` # Tests + Formatting - :green_circle: `toolkit fmt` - :green_circle: `toolkit clippy` - :red_circle: `toolkit test` # After Submitting ``` $nothing ```
2023-03-23 20:31:06 +01:00
assert!(!actual.err.contains("invalid error format"));
assert!(!actual
.err
.contains("`$.label.start` should be smaller than `$.label.end`"));
}
#[test]
fn check_help_line() {
let actual = nu!("error make {msg:foo help: `Custom help line`}");
assert!(actual.err.contains("Custom help line"));
}