| 1 |
// This file is part of the uutils coreutils package. |
| 2 |
// |
| 3 |
// For the full copyright and license information, please view the LICENSE |
| 4 |
// file that was distributed with this source code. |
| 5 |
|
| 6 |
// spell-checker:ignore parenb parmrk ixany iuclc onlcr ofdel icanon noflsh econl igpar ispeed ospeed NCCS nonhex gstty notachar cbreak evenp oddp CSIZE |
| 7 |
|
| 8 |
#![cfg(unix)] |
| 9 |
|
| 10 |
use uutests::util::{expected_result, pty_path}; |
| 11 |
use uutests::{at_and_ts, new_ucmd, unwrap_or_return}; |
| 12 |
|
| 13 |
/// Normalize stderr by replacing the full binary path with just the utility name |
| 14 |
/// This allows comparison between GNU (which shows "stty" or "gstty") and ours (which shows full path) |
| 15 |
fn normalize_stderr(stderr: &str) -> String { |
| 16 |
// Replace patterns like "Try 'gstty --help'" or "Try '/path/to/stty --help'" with "Try 'stty --help'" |
| 17 |
let re = regex::Regex::new(r"Try '[^']*(?:g)?stty --help'").unwrap(); |
| 18 |
re.replace_all(stderr, "Try 'stty --help'").to_string() |
| 19 |
} |
| 20 |
|
| 21 |
#[test] |
| 22 |
fn test_invalid_arg() { |
| 23 |
new_ucmd!() |
| 24 |
.arg("--definitely-invalid") |
| 25 |
.fails_with_code(1) |
| 26 |
.stderr_contains("invalid argument") |
| 27 |
.stderr_contains("--definitely-invalid"); |
| 28 |
} |
| 29 |
|
| 30 |
#[test] |
| 31 |
fn test_basic() { |
| 32 |
let (path, _controller, _replica) = pty_path(); |
| 33 |
new_ucmd!() |
| 34 |
.args(&["--file", &path]) |
| 35 |
.succeeds() |
| 36 |
.stdout_contains("speed"); |
| 37 |
} |
| 38 |
|
| 39 |
#[test] |
| 40 |
fn test_all_flag() { |
| 41 |
let (path, _controller, _replica) = pty_path(); |
| 42 |
let result = new_ucmd!().args(&["--all", "--file", &path]).succeeds(); |
| 43 |
|
| 44 |
for flag in ["parenb", "parmrk", "ixany", "onlcr", "icanon", "noflsh"] { |
| 45 |
result.stdout_contains(flag); |
| 46 |
} |
| 47 |
} |
| 48 |
|
| 49 |
#[test] |
| 50 |
fn test_sane() { |
| 51 |
let (path, _controller, _replica) = pty_path(); |
| 52 |
|
| 53 |
new_ucmd!() |
| 54 |
.args(&["--file", &path, "intr", "^A"]) |
| 55 |
.succeeds(); |
| 56 |
new_ucmd!() |
| 57 |
.args(&["--file", &path]) |
| 58 |
.succeeds() |
| 59 |
.stdout_contains("intr = ^A"); |
| 60 |
new_ucmd!().args(&["--file", &path, "sane"]).succeeds(); |
| 61 |
new_ucmd!() |
| 62 |
.args(&["--file", &path]) |
| 63 |
.succeeds() |
| 64 |
.stdout_str_check(|s| !s.contains("intr = ^A")); |
| 65 |
} |
| 66 |
|
| 67 |
#[test] |
| 68 |
fn save_and_setting() { |
| 69 |
new_ucmd!() |
| 70 |
.args(&["--save", "nl0"]) |
| 71 |
.fails() |
| 72 |
.stderr_contains("when specifying an output style, modes may not be set"); |
| 73 |
} |
| 74 |
|
| 75 |
#[test] |
| 76 |
fn all_and_setting() { |
| 77 |
new_ucmd!() |
| 78 |
.args(&["--all", "nl0"]) |
| 79 |
.fails() |
| 80 |
.stderr_contains("when specifying an output style, modes may not be set"); |
| 81 |
} |
| 82 |
|
| 83 |
#[test] |
| 84 |
fn all_and_print_setting() { |
| 85 |
new_ucmd!() |
| 86 |
.args(&["--all", "size"]) |
| 87 |
.fails() |
| 88 |
.stderr_contains("when specifying an output style, modes may not be set"); |
| 89 |
} |
| 90 |
|
| 91 |
#[test] |
| 92 |
fn save_and_all() { |
| 93 |
new_ucmd!() |
| 94 |
.args(&["--save", "--all"]) |
| 95 |
.fails() |
| 96 |
.stderr_contains( |
| 97 |
"the options for verbose and stty-readable output styles are mutually exclusive", |
| 98 |
); |
| 99 |
|
| 100 |
new_ucmd!() |
| 101 |
.args(&["--all", "--save"]) |
| 102 |
.fails() |
| 103 |
.stderr_contains( |
| 104 |
"the options for verbose and stty-readable output styles are mutually exclusive", |
| 105 |
); |
| 106 |
} |
| 107 |
|
| 108 |
#[test] |
| 109 |
fn no_mapping() { |
| 110 |
new_ucmd!() |
| 111 |
.args(&["intr"]) |
| 112 |
.fails() |
| 113 |
.stderr_contains("missing argument to 'intr'"); |
| 114 |
} |
| 115 |
|
| 116 |
#[test] |
| 117 |
fn invalid_mapping() { |
| 118 |
new_ucmd!() |
| 119 |
.args(&["intr", "cc"]) |
| 120 |
.fails() |
| 121 |
.stderr_contains("invalid integer argument: 'cc'"); |
| 122 |
|
| 123 |
new_ucmd!() |
| 124 |
.args(&["intr", "256"]) |
| 125 |
.fails() |
| 126 |
.stderr_contains("invalid integer argument: '256': Value too large for defined data type"); |
| 127 |
|
| 128 |
new_ucmd!() |
| 129 |
.args(&["intr", "0x100"]) |
| 130 |
.fails() |
| 131 |
.stderr_contains( |
| 132 |
"invalid integer argument: '0x100': Value too large for defined data type", |
| 133 |
); |
| 134 |
|
| 135 |
new_ucmd!() |
| 136 |
.args(&["intr", "0400"]) |
| 137 |
.fails() |
| 138 |
.stderr_contains("invalid integer argument: '0400': Value too large for defined data type"); |
| 139 |
} |
| 140 |
|
| 141 |
#[test] |
| 142 |
fn invalid_setting() { |
| 143 |
new_ucmd!() |
| 144 |
.args(&["-econl"]) |
| 145 |
.fails() |
| 146 |
.stderr_contains("invalid argument '-econl'"); |
| 147 |
|
| 148 |
new_ucmd!() |
| 149 |
.args(&["igpar"]) |
| 150 |
.fails() |
| 151 |
.stderr_contains("invalid argument 'igpar'"); |
| 152 |
} |
| 153 |
|
| 154 |
#[test] |
| 155 |
fn invalid_baud_setting() { |
| 156 |
#[cfg(not(any( |
| 157 |
target_vendor = "apple", |
| 158 |
target_os = "freebsd", |
| 159 |
target_os = "dragonfly", |
| 160 |
target_os = "netbsd", |
| 161 |
target_os = "openbsd" |
| 162 |
)))] |
| 163 |
new_ucmd!() |
| 164 |
.args(&["100"]) |
| 165 |
.fails() |
| 166 |
.stderr_contains("invalid argument '100'"); |
| 167 |
|
| 168 |
new_ucmd!() |
| 169 |
.args(&["-1"]) |
| 170 |
.fails() |
| 171 |
.stderr_contains("invalid argument '-1'"); |
| 172 |
|
| 173 |
new_ucmd!() |
| 174 |
.args(&["ispeed"]) |
| 175 |
.fails() |
| 176 |
.stderr_contains("missing argument to 'ispeed'"); |
| 177 |
|
| 178 |
new_ucmd!() |
| 179 |
.args(&["ospeed"]) |
| 180 |
.fails() |
| 181 |
.stderr_contains("missing argument to 'ospeed'"); |
| 182 |
|
| 183 |
#[cfg(not(any( |
| 184 |
target_vendor = "apple", |
| 185 |
target_os = "freebsd", |
| 186 |
target_os = "dragonfly", |
| 187 |
target_os = "netbsd", |
| 188 |
target_os = "openbsd" |
| 189 |
)))] |
| 190 |
new_ucmd!() |
| 191 |
.args(&["ispeed", "995"]) |
| 192 |
.fails() |
| 193 |
.stderr_contains("invalid ispeed '995'"); |
| 194 |
|
| 195 |
#[cfg(not(any( |
| 196 |
target_vendor = "apple", |
| 197 |
target_os = "freebsd", |
| 198 |
target_os = "dragonfly", |
| 199 |
target_os = "netbsd", |
| 200 |
target_os = "openbsd" |
| 201 |
)))] |
| 202 |
new_ucmd!() |
| 203 |
.args(&["ospeed", "995"]) |
| 204 |
.fails() |
| 205 |
.stderr_contains("invalid ospeed '995'"); |
| 206 |
|
| 207 |
for speed in &[ |
| 208 |
"9599..", "9600..", "9600.5.", "9600.50.", "9600.0.", "++9600", "0x2580", "96E2", "9600,0", |
| 209 |
"9600.0 ", |
| 210 |
] { |
| 211 |
new_ucmd!().args(&["ispeed", speed]).fails(); |
| 212 |
} |
| 213 |
} |
| 214 |
|
| 215 |
#[test] |
| 216 |
fn valid_baud_formats() { |
| 217 |
let (path, _controller, _replica) = pty_path(); |
| 218 |
for speed in &[" +9600", "9600.49", "9600.50", "9599.51", " 9600."] { |
| 219 |
new_ucmd!() |
| 220 |
.args(&["--file", &path, "ispeed", speed]) |
| 221 |
.succeeds(); |
| 222 |
} |
| 223 |
} |
| 224 |
|
| 225 |
#[test] |
| 226 |
#[ignore = "Fails because cargo test does not run in a tty"] |
| 227 |
fn set_mapping() { |
| 228 |
new_ucmd!().args(&["intr", "'"]).succeeds(); |
| 229 |
new_ucmd!() |
| 230 |
.args(&["--all"]) |
| 231 |
.succeeds() |
| 232 |
.stdout_contains("intr = '"); |
| 233 |
|
| 234 |
new_ucmd!().args(&["intr", "undef"]).succeeds(); |
| 235 |
new_ucmd!() |
| 236 |
.args(&["--all"]) |
| 237 |
.succeeds() |
| 238 |
.stdout_contains("intr = <undef>"); |
| 239 |
|
| 240 |
new_ucmd!().args(&["intr", "^-"]).succeeds(); |
| 241 |
new_ucmd!() |
| 242 |
.args(&["--all"]) |
| 243 |
.succeeds() |
| 244 |
.stdout_contains("intr = <undef>"); |
| 245 |
|
| 246 |
new_ucmd!().args(&["intr", ""]).succeeds(); |
| 247 |
new_ucmd!() |
| 248 |
.args(&["--all"]) |
| 249 |
.succeeds() |
| 250 |
.stdout_contains("intr = <undef>"); |
| 251 |
|
| 252 |
new_ucmd!().args(&["intr", "^C"]).succeeds(); |
| 253 |
new_ucmd!() |
| 254 |
.args(&["--all"]) |
| 255 |
.succeeds() |
| 256 |
.stdout_contains("intr = ^C"); |
| 257 |
} |
| 258 |
|
| 259 |
#[test] |
| 260 |
fn row_column_sizes() { |
| 261 |
new_ucmd!() |
| 262 |
.args(&["rows", "-1"]) |
| 263 |
.fails() |
| 264 |
.stderr_contains("invalid integer argument: '-1'"); |
| 265 |
|
| 266 |
new_ucmd!() |
| 267 |
.args(&["columns", "-1"]) |
| 268 |
.fails() |
| 269 |
.stderr_contains("invalid integer argument: '-1'"); |
| 270 |
|
| 271 |
// overflow the u32 used for row/col counts |
| 272 |
new_ucmd!() |
| 273 |
.args(&["cols", "4294967296"]) |
| 274 |
.fails() |
| 275 |
.stderr_contains("invalid integer argument: '4294967296'"); |
| 276 |
|
| 277 |
new_ucmd!() |
| 278 |
.args(&["rows", ""]) |
| 279 |
.fails() |
| 280 |
.stderr_contains("invalid integer argument: ''"); |
| 281 |
|
| 282 |
new_ucmd!() |
| 283 |
.args(&["columns"]) |
| 284 |
.fails() |
| 285 |
.stderr_contains("missing argument to 'columns'"); |
| 286 |
|
| 287 |
new_ucmd!() |
| 288 |
.args(&["rows"]) |
| 289 |
.fails() |
| 290 |
.stderr_contains("missing argument to 'rows'"); |
| 291 |
} |
| 292 |
|
| 293 |
#[test] |
| 294 |
fn test_row_column_hex_octal() { |
| 295 |
let (path, _controller, _replica) = pty_path(); |
| 296 |
let (_at, ts) = at_and_ts!(); |
| 297 |
|
| 298 |
// Test various numeric formats: hex (0x1E), octal (036), uppercase hex (0X1E), decimal (30), and zero |
| 299 |
let test_cases = [ |
| 300 |
("rows", "0x1E"), // hexadecimal = 30 |
| 301 |
("rows", "0x1e"), // lowercase hexadecimal = 30 |
| 302 |
("rows", "0X1e"), // upper and lowercase hexadecimal = 30 |
| 303 |
("rows", "036"), // octal = 30 |
| 304 |
("cols", "0X1E"), // uppercase hex = 30 |
| 305 |
("columns", "30"), // decimal = 30 |
| 306 |
("rows", "0"), // zero (not octal prefix) |
| 307 |
]; |
| 308 |
|
| 309 |
for (setting, value) in test_cases { |
| 310 |
let result = ts.ucmd().args(&["--file", &path, setting, value]).run(); |
| 311 |
let exp_result = |
| 312 |
unwrap_or_return!(expected_result(&ts, &["--file", &path, setting, value])); |
| 313 |
let normalized_stderr = normalize_stderr(result.stderr_str()); |
| 314 |
|
| 315 |
result |
| 316 |
.stdout_is(exp_result.stdout_str()) |
| 317 |
.code_is(exp_result.code()); |
| 318 |
assert_eq!(normalized_stderr, exp_result.stderr_str()); |
| 319 |
} |
| 320 |
} |
| 321 |
|
| 322 |
#[test] |
| 323 |
#[cfg(any(target_os = "linux", target_os = "android"))] |
| 324 |
fn line() { |
| 325 |
new_ucmd!() |
| 326 |
.args(&["line"]) |
| 327 |
.fails() |
| 328 |
.stderr_contains("missing argument to 'line'"); |
| 329 |
|
| 330 |
new_ucmd!() |
| 331 |
.args(&["line", "-1"]) |
| 332 |
.fails() |
| 333 |
.stderr_contains("invalid integer argument: '-1'"); |
| 334 |
|
| 335 |
new_ucmd!() |
| 336 |
.args(&["line", "256"]) |
| 337 |
.fails() |
| 338 |
.stderr_contains("invalid integer argument: '256'"); |
| 339 |
} |
| 340 |
|
| 341 |
#[test] |
| 342 |
fn min_and_time() { |
| 343 |
new_ucmd!() |
| 344 |
.args(&["min"]) |
| 345 |
.fails() |
| 346 |
.stderr_contains("missing argument to 'min'"); |
| 347 |
|
| 348 |
new_ucmd!() |
| 349 |
.args(&["time"]) |
| 350 |
.fails() |
| 351 |
.stderr_contains("missing argument to 'time'"); |
| 352 |
|
| 353 |
new_ucmd!() |
| 354 |
.args(&["min", "-1"]) |
| 355 |
.fails() |
| 356 |
.stderr_contains("invalid integer argument: '-1'"); |
| 357 |
|
| 358 |
new_ucmd!() |
| 359 |
.args(&["time", "-1"]) |
| 360 |
.fails() |
| 361 |
.stderr_contains("invalid integer argument: '-1'"); |
| 362 |
|
| 363 |
new_ucmd!() |
| 364 |
.args(&["min", "256"]) |
| 365 |
.fails() |
| 366 |
.stderr_contains("invalid integer argument: '256': Value too large for defined data type"); |
| 367 |
|
| 368 |
new_ucmd!() |
| 369 |
.args(&["time", "256"]) |
| 370 |
.fails() |
| 371 |
.stderr_contains("invalid integer argument: '256': Value too large for defined data type"); |
| 372 |
} |
| 373 |
|
| 374 |
#[test] |
| 375 |
fn non_negatable_combo() { |
| 376 |
new_ucmd!() |
| 377 |
.args(&["-dec"]) |
| 378 |
.fails() |
| 379 |
.stderr_contains("invalid argument '-dec'"); |
| 380 |
new_ucmd!() |
| 381 |
.args(&["-crt"]) |
| 382 |
.fails() |
| 383 |
.stderr_contains("invalid argument '-crt'"); |
| 384 |
new_ucmd!() |
| 385 |
.args(&["-ek"]) |
| 386 |
.fails() |
| 387 |
.stderr_contains("invalid argument '-ek'"); |
| 388 |
} |
| 389 |
|
| 390 |
#[test] |
| 391 |
fn help_output() { |
| 392 |
new_ucmd!() |
| 393 |
.arg("--help") |
| 394 |
.succeeds() |
| 395 |
.stdout_contains("Usage:") |
| 396 |
.stdout_contains("stty"); |
| 397 |
} |
| 398 |
|
| 399 |
#[test] |
| 400 |
fn version_output() { |
| 401 |
new_ucmd!() |
| 402 |
.arg("--version") |
| 403 |
.succeeds() |
| 404 |
.stdout_contains("stty"); |
| 405 |
} |
| 406 |
|
| 407 |
#[test] |
| 408 |
fn invalid_control_char_names() { |
| 409 |
// Test invalid control character names |
| 410 |
new_ucmd!() |
| 411 |
.args(&["notachar", "^C"]) |
| 412 |
.fails() |
| 413 |
.stderr_contains("invalid argument 'notachar'"); |
| 414 |
} |
| 415 |
|
| 416 |
#[test] |
| 417 |
fn control_char_overflow_hex() { |
| 418 |
// Test hex overflow for control characters |
| 419 |
new_ucmd!() |
| 420 |
.args(&["erase", "0xFFF"]) |
| 421 |
.fails() |
| 422 |
.stderr_contains("Value too large for defined data type"); |
| 423 |
} |
| 424 |
|
| 425 |
#[test] |
| 426 |
fn control_char_overflow_octal() { |
| 427 |
// Test octal overflow for control characters |
| 428 |
new_ucmd!() |
| 429 |
.args(&["kill", "0777"]) |
| 430 |
.fails() |
| 431 |
.stderr_contains("Value too large for defined data type"); |
| 432 |
} |
| 433 |
|
| 434 |
#[test] |
| 435 |
fn multiple_invalid_args() { |
| 436 |
// Test multiple invalid arguments |
| 437 |
new_ucmd!() |
| 438 |
.args(&["invalid1", "invalid2"]) |
| 439 |
.fails() |
| 440 |
.stderr_contains("invalid argument"); |
| 441 |
} |
| 442 |
|
| 443 |
#[test] |
| 444 |
#[ignore = "Fails because cargo test does not run in a tty"] |
| 445 |
fn negatable_combo_settings() { |
| 446 |
// These should fail without TTY but validate the argument parsing |
| 447 |
// Testing that negatable combos are recognized (even if they fail later) |
| 448 |
new_ucmd!().args(&["-cbreak"]).fails(); |
| 449 |
|
| 450 |
new_ucmd!().args(&["-evenp"]).fails(); |
| 451 |
|
| 452 |
new_ucmd!().args(&["-oddp"]).fails(); |
| 453 |
} |
| 454 |
|
| 455 |
#[test] |
| 456 |
fn grouped_flag_removal() { |
| 457 |
// Test that removing a grouped flag is invalid |
| 458 |
// cs7 is part of CSIZE group, removing it should fail |
| 459 |
new_ucmd!() |
| 460 |
.args(&["-cs7"]) |
| 461 |
.fails() |
| 462 |
.stderr_contains("invalid argument '-cs7'"); |
| 463 |
|
| 464 |
new_ucmd!() |
| 465 |
.args(&["-cs8"]) |
| 466 |
.fails() |
| 467 |
.stderr_contains("invalid argument '-cs8'"); |
| 468 |
} |
| 469 |
|
| 470 |
#[test] |
| 471 |
#[ignore = "Fails because cargo test does not run in a tty"] |
| 472 |
fn baud_rate_validation() { |
| 473 |
// Test various baud rate formats |
| 474 |
#[cfg(any( |
| 475 |
target_vendor = "apple", |
| 476 |
target_os = "freebsd", |
| 477 |
target_os = "dragonfly", |
| 478 |
target_os = "netbsd", |
| 479 |
target_os = "openbsd" |
| 480 |
))] |
| 481 |
{ |
| 482 |
// BSD accepts numeric baud rates |
| 483 |
new_ucmd!().args(&["9600"]).fails(); // Fails due to no TTY, but validates parsing |
| 484 |
} |
| 485 |
|
| 486 |
// Test ispeed/ospeed with valid baud rates |
| 487 |
new_ucmd!().args(&["ispeed", "9600"]).fails(); // Fails due to no TTY |
| 488 |
new_ucmd!().args(&["ospeed", "115200"]).fails(); // Fails due to no TTY |
| 489 |
} |
| 490 |
|
| 491 |
#[test] |
| 492 |
#[ignore = "Fails because cargo test does not run in a tty"] |
| 493 |
fn combination_setting_validation() { |
| 494 |
// Test that combination settings are recognized |
| 495 |
new_ucmd!().args(&["sane"]).fails(); // Fails due to no TTY, but validates parsing |
| 496 |
new_ucmd!().args(&["raw"]).fails(); |
| 497 |
new_ucmd!().args(&["cooked"]).fails(); |
| 498 |
new_ucmd!().args(&["cbreak"]).fails(); |
| 499 |
} |
| 500 |
|
| 501 |
#[test] |
| 502 |
#[ignore = "Fails because cargo test does not run in a tty"] |
| 503 |
fn control_char_hat_notation() { |
| 504 |
// Test various hat notation formats |
| 505 |
new_ucmd!().args(&["intr", "^?"]).fails(); // Fails due to no TTY |
| 506 |
new_ucmd!().args(&["quit", "^\\"]).fails(); |
| 507 |
new_ucmd!().args(&["erase", "^H"]).fails(); |
| 508 |
} |
| 509 |
|
| 510 |
#[test] |
| 511 |
#[ignore = "Fails because cargo test does not run in a tty"] |
| 512 |
fn special_settings() { |
| 513 |
// Test special settings that require arguments |
| 514 |
new_ucmd!().args(&["speed"]).fails(); // Fails due to no TTY but validates it's recognized |
| 515 |
|
| 516 |
new_ucmd!().args(&["size"]).fails(); // Fails due to no TTY but validates it's recognized |
| 517 |
} |
| 518 |
|
| 519 |
#[test] |
| 520 |
fn file_argument() { |
| 521 |
// Test --file argument with non-existent file |
| 522 |
new_ucmd!() |
| 523 |
.args(&["--file", "/nonexistent/device"]) |
| 524 |
.fails() |
| 525 |
.stderr_contains("No such file or directory"); |
| 526 |
} |
| 527 |
|
| 528 |
#[test] |
| 529 |
fn conflicting_print_modes() { |
| 530 |
// Test more conflicting option combinations |
| 531 |
new_ucmd!() |
| 532 |
.args(&["--save", "speed"]) |
| 533 |
.fails() |
| 534 |
.stderr_contains("when specifying an output style, modes may not be set"); |
| 535 |
|
| 536 |
new_ucmd!() |
| 537 |
.args(&["--all", "speed"]) |
| 538 |
.fails() |
| 539 |
.stderr_contains("when specifying an output style, modes may not be set"); |
| 540 |
} |
| 541 |
|
| 542 |
// Additional integration tests to increase coverage |
| 543 |
|
| 544 |
#[test] |
| 545 |
#[ignore = "Fails because cargo test does not run in a tty"] |
| 546 |
fn test_save_format() { |
| 547 |
// Test --save flag outputs settings in save format |
| 548 |
let result = new_ucmd!() |
| 549 |
.terminal_simulation(true) |
| 550 |
.args(&["--save"]) |
| 551 |
.succeeds(); |
| 552 |
// Save format should contain colon-separated fields |
| 553 |
result.stdout_contains(":"); |
| 554 |
// Should contain speed information |
| 555 |
let stdout = result.stdout_str(); |
| 556 |
assert!( |
| 557 |
stdout.split(':').count() > 1, |
| 558 |
"Save format should have multiple colon-separated fields" |
| 559 |
); |
| 560 |
} |
| 561 |
|
| 562 |
#[test] |
| 563 |
#[ignore = "Fails because cargo test does not run in a tty"] |
| 564 |
fn test_set_control_flags() { |
| 565 |
// Test setting parenb flag and verify it's set |
| 566 |
new_ucmd!() |
| 567 |
.terminal_simulation(true) |
| 568 |
.args(&["parenb"]) |
| 569 |
.succeeds(); |
| 570 |
new_ucmd!() |
| 571 |
.terminal_simulation(true) |
| 572 |
.args(&["--all"]) |
| 573 |
.succeeds() |
| 574 |
.stdout_contains("parenb"); |
| 575 |
|
| 576 |
// Test unsetting parenb flag and verify it's unset |
| 577 |
new_ucmd!() |
| 578 |
.terminal_simulation(true) |
| 579 |
.args(&["-parenb"]) |
| 580 |
.succeeds(); |
| 581 |
new_ucmd!() |
| 582 |
.terminal_simulation(true) |
| 583 |
.args(&["--all"]) |
| 584 |
.succeeds() |
| 585 |
.stdout_contains("-parenb"); |
| 586 |
|
| 587 |
// Test setting parodd flag |
| 588 |
new_ucmd!() |
| 589 |
.terminal_simulation(true) |
| 590 |
.args(&["parodd"]) |
| 591 |
.succeeds(); |
| 592 |
new_ucmd!() |
| 593 |
.terminal_simulation(true) |
| 594 |
.args(&["--all"]) |
| 595 |
.succeeds() |
| 596 |
.stdout_contains("parodd"); |
| 597 |
|
| 598 |
// Test setting cstopb flag |
| 599 |
new_ucmd!() |
| 600 |
.terminal_simulation(true) |
| 601 |
.args(&["cstopb"]) |
| 602 |
.succeeds(); |
| 603 |
new_ucmd!() |
| 604 |
.terminal_simulation(true) |
| 605 |
.args(&["--all"]) |
| 606 |
.succeeds() |
| 607 |
.stdout_contains("cstopb"); |
| 608 |
} |
| 609 |
|
| 610 |
// Tests for saved state parsing and restoration |
| 611 |
#[test] |
| 612 |
fn test_save_and_restore() { |
| 613 |
let (path, _controller, _replica) = pty_path(); |
| 614 |
let saved = new_ucmd!() |
| 615 |
.args(&["--save", "--file", &path]) |
| 616 |
.succeeds() |
| 617 |
.stdout_move_str(); |
| 618 |
|
| 619 |
let saved = saved.trim(); |
| 620 |
assert!(saved.contains(':')); |
| 621 |
|
| 622 |
new_ucmd!().args(&["--file", &path, saved]).succeeds(); |
| 623 |
} |
| 624 |
|
| 625 |
#[test] |
| 626 |
#[ignore = "Fails because cargo test does not run in a tty"] |
| 627 |
fn test_set_input_flags() { |
| 628 |
// Test setting ignbrk flag and verify |
| 629 |
new_ucmd!() |
| 630 |
.terminal_simulation(true) |
| 631 |
.args(&["ignbrk"]) |
| 632 |
.succeeds(); |
| 633 |
new_ucmd!() |
| 634 |
.terminal_simulation(true) |
| 635 |
.args(&["--all"]) |
| 636 |
.succeeds() |
| 637 |
.stdout_contains("ignbrk"); |
| 638 |
|
| 639 |
// Test setting brkint flag and verify |
| 640 |
new_ucmd!() |
| 641 |
.terminal_simulation(true) |
| 642 |
.args(&["brkint"]) |
| 643 |
.succeeds(); |
| 644 |
new_ucmd!() |
| 645 |
.terminal_simulation(true) |
| 646 |
.args(&["--all"]) |
| 647 |
.succeeds() |
| 648 |
.stdout_contains("brkint"); |
| 649 |
|
| 650 |
// Test setting ignpar flag and verify |
| 651 |
new_ucmd!() |
| 652 |
.terminal_simulation(true) |
| 653 |
.args(&["ignpar"]) |
| 654 |
.succeeds(); |
| 655 |
new_ucmd!() |
| 656 |
.terminal_simulation(true) |
| 657 |
.args(&["--all"]) |
| 658 |
.succeeds() |
| 659 |
.stdout_contains("ignpar"); |
| 660 |
} |
| 661 |
|
| 662 |
#[test] |
| 663 |
fn test_save_with_g_flag() { |
| 664 |
let (path, _controller, _replica) = pty_path(); |
| 665 |
let saved = new_ucmd!() |
| 666 |
.args(&["-g", "--file", &path]) |
| 667 |
.succeeds() |
| 668 |
.stdout_move_str(); |
| 669 |
|
| 670 |
let saved = saved.trim(); |
| 671 |
assert!(saved.contains(':')); |
| 672 |
|
| 673 |
new_ucmd!().args(&["--file", &path, saved]).succeeds(); |
| 674 |
} |
| 675 |
|
| 676 |
#[test] |
| 677 |
#[ignore = "Fails because cargo test does not run in a tty"] |
| 678 |
fn test_set_output_flags() { |
| 679 |
// Test setting opost flag and verify |
| 680 |
new_ucmd!() |
| 681 |
.terminal_simulation(true) |
| 682 |
.args(&["opost"]) |
| 683 |
.succeeds(); |
| 684 |
new_ucmd!() |
| 685 |
.terminal_simulation(true) |
| 686 |
.args(&["--all"]) |
| 687 |
.succeeds() |
| 688 |
.stdout_contains("opost"); |
| 689 |
|
| 690 |
// Test unsetting opost flag and verify |
| 691 |
new_ucmd!() |
| 692 |
.terminal_simulation(true) |
| 693 |
.args(&["-opost"]) |
| 694 |
.succeeds(); |
| 695 |
new_ucmd!() |
| 696 |
.terminal_simulation(true) |
| 697 |
.args(&["--all"]) |
| 698 |
.succeeds() |
| 699 |
.stdout_contains("-opost"); |
| 700 |
|
| 701 |
// Test setting onlcr flag and verify |
| 702 |
new_ucmd!() |
| 703 |
.terminal_simulation(true) |
| 704 |
.args(&["onlcr"]) |
| 705 |
.succeeds(); |
| 706 |
new_ucmd!() |
| 707 |
.terminal_simulation(true) |
| 708 |
.args(&["--all"]) |
| 709 |
.succeeds() |
| 710 |
.stdout_contains("onlcr"); |
| 711 |
} |
| 712 |
|
| 713 |
#[test] |
| 714 |
#[ignore = "Fails because cargo test does not run in a tty"] |
| 715 |
fn test_set_local_flags() { |
| 716 |
// Test setting isig flag and verify |
| 717 |
new_ucmd!() |
| 718 |
.terminal_simulation(true) |
| 719 |
.args(&["isig"]) |
| 720 |
.succeeds(); |
| 721 |
new_ucmd!() |
| 722 |
.terminal_simulation(true) |
| 723 |
.args(&["--all"]) |
| 724 |
.succeeds() |
| 725 |
.stdout_contains("isig"); |
| 726 |
|
| 727 |
// Test setting icanon flag and verify |
| 728 |
new_ucmd!() |
| 729 |
.terminal_simulation(true) |
| 730 |
.args(&["icanon"]) |
| 731 |
.succeeds(); |
| 732 |
new_ucmd!() |
| 733 |
.terminal_simulation(true) |
| 734 |
.args(&["--all"]) |
| 735 |
.succeeds() |
| 736 |
.stdout_contains("icanon"); |
| 737 |
|
| 738 |
// Test setting echo flag and verify |
| 739 |
new_ucmd!() |
| 740 |
.terminal_simulation(true) |
| 741 |
.args(&["echo"]) |
| 742 |
.succeeds(); |
| 743 |
new_ucmd!() |
| 744 |
.terminal_simulation(true) |
| 745 |
.args(&["--all"]) |
| 746 |
.succeeds() |
| 747 |
.stdout_contains("echo"); |
| 748 |
} |
| 749 |
|
| 750 |
#[test] |
| 751 |
#[ignore = "Fails because cargo test does not run in a tty"] |
| 752 |
fn test_combo_cbreak() { |
| 753 |
// Test cbreak combination setting - should disable icanon |
| 754 |
new_ucmd!() |
| 755 |
.terminal_simulation(true) |
| 756 |
.args(&["cbreak"]) |
| 757 |
.succeeds(); |
| 758 |
new_ucmd!() |
| 759 |
.terminal_simulation(true) |
| 760 |
.args(&["--all"]) |
| 761 |
.succeeds() |
| 762 |
.stdout_contains("-icanon"); |
| 763 |
|
| 764 |
// Test -cbreak should enable icanon |
| 765 |
new_ucmd!() |
| 766 |
.terminal_simulation(true) |
| 767 |
.args(&["-cbreak"]) |
| 768 |
.succeeds(); |
| 769 |
new_ucmd!() |
| 770 |
.terminal_simulation(true) |
| 771 |
.args(&["--all"]) |
| 772 |
.succeeds() |
| 773 |
.stdout_contains("icanon"); |
| 774 |
} |
| 775 |
|
| 776 |
#[test] |
| 777 |
#[ignore = "Fails because cargo test does not run in a tty"] |
| 778 |
fn test_combo_nl() { |
| 779 |
// Test nl combination setting - should disable icrnl and onlcr |
| 780 |
new_ucmd!() |
| 781 |
.terminal_simulation(true) |
| 782 |
.args(&["nl"]) |
| 783 |
.succeeds(); |
| 784 |
let result = new_ucmd!() |
| 785 |
.terminal_simulation(true) |
| 786 |
.args(&["--all"]) |
| 787 |
.succeeds(); |
| 788 |
result.stdout_contains("-icrnl"); |
| 789 |
result.stdout_contains("-onlcr"); |
| 790 |
} |
| 791 |
|
| 792 |
#[test] |
| 793 |
#[ignore = "Fails because cargo test does not run in a tty"] |
| 794 |
fn test_combo_ek() { |
| 795 |
// Test ek combination setting (erase and kill) - should set erase and kill to defaults |
| 796 |
new_ucmd!() |
| 797 |
.terminal_simulation(true) |
| 798 |
.args(&["ek"]) |
| 799 |
.succeeds(); |
| 800 |
let result = new_ucmd!().terminal_simulation(true).succeeds(); |
| 801 |
// Should show erase and kill characters |
| 802 |
result.stdout_contains("erase"); |
| 803 |
result.stdout_contains("kill"); |
| 804 |
} |
| 805 |
|
| 806 |
#[test] |
| 807 |
#[ignore = "Fails because cargo test does not run in a tty"] |
| 808 |
fn test_combo_litout() { |
| 809 |
// Test litout combination setting - should disable parenb, istrip, opost |
| 810 |
new_ucmd!() |
| 811 |
.terminal_simulation(true) |
| 812 |
.args(&["litout"]) |
| 813 |
.succeeds(); |
| 814 |
let result = new_ucmd!() |
| 815 |
.terminal_simulation(true) |
| 816 |
.args(&["--all"]) |
| 817 |
.succeeds(); |
| 818 |
result.stdout_contains("-parenb"); |
| 819 |
result.stdout_contains("-istrip"); |
| 820 |
result.stdout_contains("-opost"); |
| 821 |
} |
| 822 |
|
| 823 |
#[test] |
| 824 |
#[ignore = "Fails because cargo test does not run in a tty"] |
| 825 |
fn test_combo_pass8() { |
| 826 |
// Test pass8 combination setting - should disable parenb, istrip, set cs8 |
| 827 |
new_ucmd!() |
| 828 |
.terminal_simulation(true) |
| 829 |
.args(&["pass8"]) |
| 830 |
.succeeds(); |
| 831 |
let result = new_ucmd!() |
| 832 |
.terminal_simulation(true) |
| 833 |
.args(&["--all"]) |
| 834 |
.succeeds(); |
| 835 |
result.stdout_contains("-parenb"); |
| 836 |
result.stdout_contains("-istrip"); |
| 837 |
result.stdout_contains("cs8"); |
| 838 |
} |
| 839 |
|
| 840 |
#[test] |
| 841 |
fn test_save_restore_after_change() { |
| 842 |
let (path, _controller, _replica) = pty_path(); |
| 843 |
let saved = new_ucmd!() |
| 844 |
.args(&["--save", "--file", &path]) |
| 845 |
.succeeds() |
| 846 |
.stdout_move_str(); |
| 847 |
|
| 848 |
let saved = saved.trim(); |
| 849 |
|
| 850 |
new_ucmd!() |
| 851 |
.args(&["--file", &path, "intr", "^A"]) |
| 852 |
.succeeds(); |
| 853 |
|
| 854 |
new_ucmd!().args(&["--file", &path, saved]).succeeds(); |
| 855 |
|
| 856 |
new_ucmd!() |
| 857 |
.args(&["--file", &path]) |
| 858 |
.succeeds() |
| 859 |
.stdout_str_check(|s| !s.contains("intr = ^A")); |
| 860 |
} |
| 861 |
|
| 862 |
// These tests both validate what we expect each input to return and their error codes |
| 863 |
// and also use the GNU coreutils results to validate our results match expectations |
| 864 |
#[test] |
| 865 |
fn test_saved_state_valid_formats() { |
| 866 |
let (path, _controller, _replica) = pty_path(); |
| 867 |
let (_at, ts) = at_and_ts!(); |
| 868 |
|
| 869 |
// Generate valid saved state from the actual terminal |
| 870 |
let saved = unwrap_or_return!(expected_result(&ts, &["-g", "--file", &path])).stdout_move_str(); |
| 871 |
let saved = saved.trim(); |
| 872 |
|
| 873 |
let result = ts.ucmd().args(&["--file", &path, saved]).run(); |
| 874 |
|
| 875 |
result.success().no_stderr(); |
| 876 |
|
| 877 |
let exp_result = unwrap_or_return!(expected_result(&ts, &["--file", &path, saved])); |
| 878 |
let normalized_stderr = normalize_stderr(result.stderr_str()); |
| 879 |
result |
| 880 |
.stdout_is(exp_result.stdout_str()) |
| 881 |
.code_is(exp_result.code()); |
| 882 |
assert_eq!(normalized_stderr, exp_result.stderr_str()); |
| 883 |
} |
| 884 |
|
| 885 |
#[test] |
| 886 |
#[ignore = "Fails because cargo test does not run in a tty"] |
| 887 |
fn test_combo_decctlq() { |
| 888 |
// Test decctlq combination setting - should enable ixany |
| 889 |
new_ucmd!() |
| 890 |
.terminal_simulation(true) |
| 891 |
.args(&["decctlq"]) |
| 892 |
.succeeds(); |
| 893 |
new_ucmd!() |
| 894 |
.terminal_simulation(true) |
| 895 |
.args(&["--all"]) |
| 896 |
.succeeds() |
| 897 |
.stdout_contains("ixany"); |
| 898 |
} |
| 899 |
|
| 900 |
#[test] |
| 901 |
#[ignore = "Fails because cargo test does not run in a tty"] |
| 902 |
fn test_combo_dec() { |
| 903 |
// Test dec combination setting - should set multiple flags |
| 904 |
new_ucmd!() |
| 905 |
.terminal_simulation(true) |
| 906 |
.args(&["dec"]) |
| 907 |
.succeeds(); |
| 908 |
let result = new_ucmd!() |
| 909 |
.terminal_simulation(true) |
| 910 |
.args(&["--all"]) |
| 911 |
.succeeds(); |
| 912 |
// dec sets echoe, echoctl, echoke |
| 913 |
result.stdout_contains("echoe"); |
| 914 |
} |
| 915 |
|
| 916 |
#[test] |
| 917 |
#[ignore = "Fails because cargo test does not run in a tty"] |
| 918 |
fn test_combo_crt() { |
| 919 |
// Test crt combination setting - should set echoe |
| 920 |
new_ucmd!() |
| 921 |
.terminal_simulation(true) |
| 922 |
.args(&["crt"]) |
| 923 |
.succeeds(); |
| 924 |
new_ucmd!() |
| 925 |
.terminal_simulation(true) |
| 926 |
.args(&["--all"]) |
| 927 |
.succeeds() |
| 928 |
.stdout_contains("echoe"); |
| 929 |
} |
| 930 |
|
| 931 |
#[test] |
| 932 |
#[cfg(target_os = "linux")] |
| 933 |
fn test_combo_tabs() { |
| 934 |
// Test tabs combination setting - tabs is an alias for tab0, -tabs for tab3 |
| 935 |
new_ucmd!() |
| 936 |
.terminal_simulation(true) |
| 937 |
.args(&["tabs"]) |
| 938 |
.succeeds() |
| 939 |
.no_stderr(); |
| 940 |
|
| 941 |
new_ucmd!() |
| 942 |
.terminal_simulation(true) |
| 943 |
.args(&["-tabs"]) |
| 944 |
.succeeds() |
| 945 |
.no_stderr(); |
| 946 |
} |
| 947 |
|
| 948 |
#[test] |
| 949 |
#[ignore = "Fails because cargo test does not run in a tty"] |
| 950 |
fn test_multiple_settings() { |
| 951 |
// Test setting multiple flags at once and verify all are set |
| 952 |
new_ucmd!() |
| 953 |
.terminal_simulation(true) |
| 954 |
.args(&["parenb", "parodd", "cs7"]) |
| 955 |
.succeeds(); |
| 956 |
let result = new_ucmd!() |
| 957 |
.terminal_simulation(true) |
| 958 |
.args(&["--all"]) |
| 959 |
.succeeds(); |
| 960 |
result.stdout_contains("parenb"); |
| 961 |
result.stdout_contains("parodd"); |
| 962 |
result.stdout_contains("cs7"); |
| 963 |
} |
| 964 |
|
| 965 |
#[test] |
| 966 |
#[ignore = "Fails because cargo test does not run in a tty"] |
| 967 |
fn test_set_all_control_chars() { |
| 968 |
// Test setting intr control character and verify |
| 969 |
new_ucmd!() |
| 970 |
.terminal_simulation(true) |
| 971 |
.args(&["intr", "^C"]) |
| 972 |
.succeeds(); |
| 973 |
new_ucmd!() |
| 974 |
.terminal_simulation(true) |
| 975 |
.succeeds() |
| 976 |
.stdout_contains("intr = ^C"); |
| 977 |
|
| 978 |
// Test setting quit control character and verify |
| 979 |
new_ucmd!() |
| 980 |
.terminal_simulation(true) |
| 981 |
.args(&["quit", "^\\"]) |
| 982 |
.succeeds(); |
| 983 |
new_ucmd!() |
| 984 |
.terminal_simulation(true) |
| 985 |
.succeeds() |
| 986 |
.stdout_contains("quit = ^\\"); |
| 987 |
|
| 988 |
// Test setting erase control character and verify |
| 989 |
new_ucmd!() |
| 990 |
.terminal_simulation(true) |
| 991 |
.args(&["erase", "^?"]) |
| 992 |
.succeeds(); |
| 993 |
new_ucmd!() |
| 994 |
.terminal_simulation(true) |
| 995 |
.succeeds() |
| 996 |
.stdout_contains("erase = ^?"); |
| 997 |
|
| 998 |
// Test setting kill control character and verify |
| 999 |
new_ucmd!() |
| 1000 |
.terminal_simulation(true) |
| 1001 |
.args(&["kill", "^U"]) |
| 1002 |
.succeeds(); |
| 1003 |
new_ucmd!() |
| 1004 |
.terminal_simulation(true) |
| 1005 |
.succeeds() |
| 1006 |
.stdout_contains("kill = ^U"); |
| 1007 |
} |
| 1008 |
|
| 1009 |
#[test] |
| 1010 |
#[ignore = "Fails because cargo test does not run in a tty"] |
| 1011 |
fn test_print_size() { |
| 1012 |
// Test size print setting - should output "rows <num>; columns <num>;" |
| 1013 |
let result = new_ucmd!() |
| 1014 |
.terminal_simulation(true) |
| 1015 |
.args(&["size"]) |
| 1016 |
.succeeds(); |
| 1017 |
result.stdout_contains("rows"); |
| 1018 |
result.stdout_contains("columns"); |
| 1019 |
} |
| 1020 |
|
| 1021 |
#[test] |
| 1022 |
#[ignore = "Fails because cargo test does not run in a tty"] |
| 1023 |
fn test_print_speed() { |
| 1024 |
// Test speed print setting - should output a numeric speed |
| 1025 |
let result = new_ucmd!() |
| 1026 |
.terminal_simulation(true) |
| 1027 |
.args(&["speed"]) |
| 1028 |
.succeeds(); |
| 1029 |
// Speed should be a number (common speeds: 9600, 38400, 115200, etc.) |
| 1030 |
let stdout = result.stdout_str(); |
| 1031 |
assert!( |
| 1032 |
stdout.trim().parse::<u32>().is_ok(), |
| 1033 |
"Speed should be a numeric value" |
| 1034 |
); |
| 1035 |
} |
| 1036 |
|
| 1037 |
#[test] |
| 1038 |
#[ignore = "Fails because cargo test does not run in a tty"] |
| 1039 |
fn test_set_rows_cols() { |
| 1040 |
// Test setting rows and verify |
| 1041 |
new_ucmd!() |
| 1042 |
.terminal_simulation(true) |
| 1043 |
.args(&["rows", "24"]) |
| 1044 |
.succeeds(); |
| 1045 |
new_ucmd!() |
| 1046 |
.terminal_simulation(true) |
| 1047 |
.args(&["size"]) |
| 1048 |
.succeeds() |
| 1049 |
.stdout_contains("rows 24"); |
| 1050 |
|
| 1051 |
// Test setting cols and verify |
| 1052 |
new_ucmd!() |
| 1053 |
.terminal_simulation(true) |
| 1054 |
.args(&["cols", "80"]) |
| 1055 |
.succeeds(); |
| 1056 |
new_ucmd!() |
| 1057 |
.terminal_simulation(true) |
| 1058 |
.args(&["size"]) |
| 1059 |
.succeeds() |
| 1060 |
.stdout_contains("columns 80"); |
| 1061 |
|
| 1062 |
// Test setting both rows and cols together |
| 1063 |
new_ucmd!() |
| 1064 |
.terminal_simulation(true) |
| 1065 |
.args(&["rows", "50", "cols", "100"]) |
| 1066 |
.succeeds(); |
| 1067 |
let result = new_ucmd!() |
| 1068 |
.terminal_simulation(true) |
| 1069 |
.args(&["size"]) |
| 1070 |
.succeeds(); |
| 1071 |
result.stdout_contains("rows 50"); |
| 1072 |
result.stdout_contains("columns 100"); |
| 1073 |
} |
| 1074 |
|
| 1075 |
#[test] |
| 1076 |
#[ignore = "Fails because cargo test does not run in a tty"] |
| 1077 |
fn test_character_size_settings() { |
| 1078 |
// Test cs5 setting and verify |
| 1079 |
new_ucmd!() |
| 1080 |
.terminal_simulation(true) |
| 1081 |
.args(&["cs5"]) |
| 1082 |
.succeeds(); |
| 1083 |
new_ucmd!() |
| 1084 |
.terminal_simulation(true) |
| 1085 |
.args(&["--all"]) |
| 1086 |
.succeeds() |
| 1087 |
.stdout_contains("cs5"); |
| 1088 |
|
| 1089 |
// Test cs7 setting and verify |
| 1090 |
new_ucmd!() |
| 1091 |
.terminal_simulation(true) |
| 1092 |
.args(&["cs7"]) |
| 1093 |
.succeeds(); |
| 1094 |
new_ucmd!() |
| 1095 |
.terminal_simulation(true) |
| 1096 |
.args(&["--all"]) |
| 1097 |
.succeeds() |
| 1098 |
.stdout_contains("cs7"); |
| 1099 |
|
| 1100 |
// Test cs8 setting and verify |
| 1101 |
new_ucmd!() |
| 1102 |
.terminal_simulation(true) |
| 1103 |
.args(&["cs8"]) |
| 1104 |
.succeeds(); |
| 1105 |
new_ucmd!() |
| 1106 |
.terminal_simulation(true) |
| 1107 |
.args(&["--all"]) |
| 1108 |
.succeeds() |
| 1109 |
.stdout_contains("cs8"); |
| 1110 |
} |
| 1111 |
|
| 1112 |
#[test] |
| 1113 |
#[ignore = "Fails because cargo test does not run in a tty"] |
| 1114 |
fn test_baud_rate_settings() { |
| 1115 |
// Test setting ispeed and verify |
| 1116 |
new_ucmd!() |
| 1117 |
.terminal_simulation(true) |
| 1118 |
.args(&["ispeed", "9600"]) |
| 1119 |
.succeeds(); |
| 1120 |
new_ucmd!() |
| 1121 |
.terminal_simulation(true) |
| 1122 |
.args(&["speed"]) |
| 1123 |
.succeeds() |
| 1124 |
.stdout_contains("9600"); |
| 1125 |
|
| 1126 |
// Test setting both ispeed and ospeed |
| 1127 |
new_ucmd!() |
| 1128 |
.terminal_simulation(true) |
| 1129 |
.args(&["ispeed", "38400", "ospeed", "38400"]) |
| 1130 |
.succeeds(); |
| 1131 |
new_ucmd!() |
| 1132 |
.terminal_simulation(true) |
| 1133 |
.args(&["speed"]) |
| 1134 |
.succeeds() |
| 1135 |
.stdout_contains("38400"); |
| 1136 |
} |
| 1137 |
|
| 1138 |
#[test] |
| 1139 |
#[ignore = "Fails because cargo test does not run in a tty"] |
| 1140 |
fn test_min_time_settings() { |
| 1141 |
// Test min setting and verify |
| 1142 |
new_ucmd!() |
| 1143 |
.terminal_simulation(true) |
| 1144 |
.args(&["min", "1"]) |
| 1145 |
.succeeds(); |
| 1146 |
new_ucmd!() |
| 1147 |
.terminal_simulation(true) |
| 1148 |
.args(&["--all"]) |
| 1149 |
.succeeds() |
| 1150 |
.stdout_contains("min = 1"); |
| 1151 |
|
| 1152 |
// Test time setting and verify |
| 1153 |
new_ucmd!() |
| 1154 |
.terminal_simulation(true) |
| 1155 |
.args(&["time", "10"]) |
| 1156 |
.succeeds(); |
| 1157 |
new_ucmd!() |
| 1158 |
.terminal_simulation(true) |
| 1159 |
.args(&["--all"]) |
| 1160 |
.succeeds() |
| 1161 |
.stdout_contains("time = 10"); |
| 1162 |
} |
| 1163 |
|
| 1164 |
#[test] |
| 1165 |
#[ignore = "Fails because cargo test does not run in a tty"] |
| 1166 |
fn test_complex_scenario() { |
| 1167 |
// Test a complex scenario with multiple settings and verify all are applied |
| 1168 |
new_ucmd!() |
| 1169 |
.terminal_simulation(true) |
| 1170 |
.args(&["sane", "rows", "24", "cols", "80", "intr", "^C"]) |
| 1171 |
.succeeds(); |
| 1172 |
|
| 1173 |
// Verify all settings were applied |
| 1174 |
let size_result = new_ucmd!() |
| 1175 |
.terminal_simulation(true) |
| 1176 |
.args(&["size"]) |
| 1177 |
.succeeds(); |
| 1178 |
size_result.stdout_contains("rows 24"); |
| 1179 |
size_result.stdout_contains("columns 80"); |
| 1180 |
|
| 1181 |
let result = new_ucmd!().terminal_simulation(true).succeeds(); |
| 1182 |
result.stdout_contains("intr = ^C"); |
| 1183 |
} |
| 1184 |
|
| 1185 |
#[test] |
| 1186 |
#[ignore = "Fails because cargo test does not run in a tty"] |
| 1187 |
fn test_raw_mode() { |
| 1188 |
// Test raw mode setting |
| 1189 |
new_ucmd!() |
| 1190 |
.terminal_simulation(true) |
| 1191 |
.args(&["raw"]) |
| 1192 |
.succeeds(); |
| 1193 |
// Verify raw mode is set by checking output |
| 1194 |
let result = new_ucmd!() |
| 1195 |
.terminal_simulation(true) |
| 1196 |
.args(&["--all"]) |
| 1197 |
.succeeds(); |
| 1198 |
result.stdout_contains("-icanon"); |
| 1199 |
} |
| 1200 |
|
| 1201 |
#[test] |
| 1202 |
#[ignore = "Fails because cargo test does not run in a tty"] |
| 1203 |
fn test_cooked_mode() { |
| 1204 |
// Test cooked mode setting (opposite of raw) |
| 1205 |
new_ucmd!() |
| 1206 |
.terminal_simulation(true) |
| 1207 |
.args(&["cooked"]) |
| 1208 |
.succeeds(); |
| 1209 |
// Verify cooked mode is set |
| 1210 |
let result = new_ucmd!() |
| 1211 |
.terminal_simulation(true) |
| 1212 |
.args(&["--all"]) |
| 1213 |
.succeeds(); |
| 1214 |
result.stdout_contains("icanon"); |
| 1215 |
} |
| 1216 |
|
| 1217 |
#[test] |
| 1218 |
fn test_saved_state_invalid_formats() { |
| 1219 |
let (path, _controller, _replica) = pty_path(); |
| 1220 |
let (_at, ts) = at_and_ts!(); |
| 1221 |
|
| 1222 |
let num_cc = libc::NCCS; |
| 1223 |
|
| 1224 |
// Build test strings with platform-specific counts |
| 1225 |
let cc_zeros = vec!["0"; num_cc].join(":"); |
| 1226 |
let cc_with_invalid = if num_cc > 0 { |
| 1227 |
let mut parts = vec!["1c"; num_cc]; |
| 1228 |
parts[0] = "100"; // First control char > 255 |
| 1229 |
parts.join(":") |
| 1230 |
} else { |
| 1231 |
String::new() |
| 1232 |
}; |
| 1233 |
let cc_with_space = if num_cc > 0 { |
| 1234 |
let mut parts = vec!["1c"; num_cc]; |
| 1235 |
parts[0] = "1c "; // Space in hex |
| 1236 |
parts.join(":") |
| 1237 |
} else { |
| 1238 |
String::new() |
| 1239 |
}; |
| 1240 |
let cc_with_nonhex = if num_cc > 0 { |
| 1241 |
let mut parts = vec!["1c"; num_cc]; |
| 1242 |
parts[0] = "xyz"; // Non-hex |
| 1243 |
parts.join(":") |
| 1244 |
} else { |
| 1245 |
String::new() |
| 1246 |
}; |
| 1247 |
let cc_with_empty = if num_cc > 0 { |
| 1248 |
let mut parts = vec!["1c"; num_cc]; |
| 1249 |
parts[0] = ""; // Empty |
| 1250 |
parts.join(":") |
| 1251 |
} else { |
| 1252 |
String::new() |
| 1253 |
}; |
| 1254 |
|
| 1255 |
// Cannot test single value since it would be interpreted as baud rate |
| 1256 |
let invalid_states = vec![ |
| 1257 |
"500:5:4bf".to_string(), // fewer than expected parts |
| 1258 |
"500:5:4bf:8a3b".to_string(), // only 4 parts |
| 1259 |
format!("500:5:{}:8a3b:{}", cc_zeros, "extra"), // too many parts |
| 1260 |
format!("500::4bf:8a3b:{}", cc_zeros), // empty hex value in flags |
| 1261 |
format!("500:5:4bf:8a3b:{}", cc_with_empty), // empty hex value in cc |
| 1262 |
format!("500:5:4bf:8a3b:{}", cc_with_nonhex), // non-hex characters |
| 1263 |
format!("500:5:4bf:8a3b:{}", cc_with_space), // space in hex value |
| 1264 |
format!("500:5:4bf:8a3b:{}", cc_with_invalid), // control char > 255 |
| 1265 |
]; |
| 1266 |
|
| 1267 |
for state in &invalid_states { |
| 1268 |
let result = ts.ucmd().args(&["--file", &path, state]).run(); |
| 1269 |
|
| 1270 |
result.failure().stderr_contains("invalid argument"); |
| 1271 |
|
| 1272 |
let exp_result = unwrap_or_return!(expected_result(&ts, &["--file", &path, state])); |
| 1273 |
let normalized_stderr = normalize_stderr(result.stderr_str()); |
| 1274 |
let exp_normalized_stderr = normalize_stderr(exp_result.stderr_str()); |
| 1275 |
result |
| 1276 |
.stdout_is(exp_result.stdout_str()) |
| 1277 |
.code_is(exp_result.code()); |
| 1278 |
assert_eq!(normalized_stderr, exp_normalized_stderr); |
| 1279 |
} |
| 1280 |
} |
| 1281 |
|
| 1282 |
#[test] |
| 1283 |
#[ignore = "Fails because cargo test does not run in a tty"] |
| 1284 |
fn test_parity_settings() { |
| 1285 |
// Test evenp setting and verify (should set parenb and cs7) |
| 1286 |
new_ucmd!() |
| 1287 |
.terminal_simulation(true) |
| 1288 |
.args(&["evenp"]) |
| 1289 |
.succeeds(); |
| 1290 |
let result = new_ucmd!() |
| 1291 |
.terminal_simulation(true) |
| 1292 |
.args(&["--all"]) |
| 1293 |
.succeeds(); |
| 1294 |
result.stdout_contains("parenb"); |
| 1295 |
result.stdout_contains("cs7"); |
| 1296 |
|
| 1297 |
// Test oddp setting and verify (should set parenb, parodd, and cs7) |
| 1298 |
new_ucmd!() |
| 1299 |
.terminal_simulation(true) |
| 1300 |
.args(&["oddp"]) |
| 1301 |
.succeeds(); |
| 1302 |
let result = new_ucmd!() |
| 1303 |
.terminal_simulation(true) |
| 1304 |
.args(&["--all"]) |
| 1305 |
.succeeds(); |
| 1306 |
result.stdout_contains("parenb"); |
| 1307 |
result.stdout_contains("parodd"); |
| 1308 |
result.stdout_contains("cs7"); |
| 1309 |
} |
| 1310 |
|
| 1311 |
// Additional integration tests for missing coverage |
| 1312 |
|
| 1313 |
#[test] |
| 1314 |
fn missing_arg_ispeed() { |
| 1315 |
// Test missing argument for ispeed |
| 1316 |
new_ucmd!() |
| 1317 |
.args(&["ispeed"]) |
| 1318 |
.fails() |
| 1319 |
.stderr_contains("missing argument") |
| 1320 |
.stderr_contains("ispeed"); |
| 1321 |
} |
| 1322 |
|
| 1323 |
#[test] |
| 1324 |
fn missing_arg_ospeed() { |
| 1325 |
// Test missing argument for ospeed |
| 1326 |
new_ucmd!() |
| 1327 |
.args(&["ospeed"]) |
| 1328 |
.fails() |
| 1329 |
.stderr_contains("missing argument") |
| 1330 |
.stderr_contains("ospeed"); |
| 1331 |
} |
| 1332 |
|
| 1333 |
#[test] |
| 1334 |
fn missing_arg_line() { |
| 1335 |
// Test missing argument for line |
| 1336 |
new_ucmd!() |
| 1337 |
.args(&["line"]) |
| 1338 |
.fails() |
| 1339 |
.stderr_contains("missing argument") |
| 1340 |
.stderr_contains("line"); |
| 1341 |
} |
| 1342 |
|
| 1343 |
#[test] |
| 1344 |
fn missing_arg_min() { |
| 1345 |
// Test missing argument for min |
| 1346 |
new_ucmd!() |
| 1347 |
.args(&["min"]) |
| 1348 |
.fails() |
| 1349 |
.stderr_contains("missing argument") |
| 1350 |
.stderr_contains("min"); |
| 1351 |
} |
| 1352 |
|
| 1353 |
#[test] |
| 1354 |
fn missing_arg_time() { |
| 1355 |
// Test missing argument for time |
| 1356 |
new_ucmd!() |
| 1357 |
.args(&["time"]) |
| 1358 |
.fails() |
| 1359 |
.stderr_contains("missing argument") |
| 1360 |
.stderr_contains("time"); |
| 1361 |
} |
| 1362 |
|
| 1363 |
#[test] |
| 1364 |
fn missing_arg_rows() { |
| 1365 |
// Test missing argument for rows |
| 1366 |
new_ucmd!() |
| 1367 |
.args(&["rows"]) |
| 1368 |
.fails() |
| 1369 |
.stderr_contains("missing argument") |
| 1370 |
.stderr_contains("rows"); |
| 1371 |
} |
| 1372 |
|
| 1373 |
#[test] |
| 1374 |
fn missing_arg_cols() { |
| 1375 |
// Test missing argument for cols |
| 1376 |
new_ucmd!() |
| 1377 |
.args(&["cols"]) |
| 1378 |
.fails() |
| 1379 |
.stderr_contains("missing argument") |
| 1380 |
.stderr_contains("cols"); |
| 1381 |
} |
| 1382 |
|
| 1383 |
#[test] |
| 1384 |
fn missing_arg_columns() { |
| 1385 |
// Test missing argument for columns |
| 1386 |
new_ucmd!() |
| 1387 |
.args(&["columns"]) |
| 1388 |
.fails() |
| 1389 |
.stderr_contains("missing argument") |
| 1390 |
.stderr_contains("columns"); |
| 1391 |
} |
| 1392 |
|
| 1393 |
#[test] |
| 1394 |
fn missing_arg_control_char() { |
| 1395 |
// Test missing argument for control character |
| 1396 |
new_ucmd!() |
| 1397 |
.args(&["intr"]) |
| 1398 |
.fails() |
| 1399 |
.stderr_contains("missing argument") |
| 1400 |
.stderr_contains("intr"); |
| 1401 |
|
| 1402 |
new_ucmd!() |
| 1403 |
.args(&["erase"]) |
| 1404 |
.fails() |
| 1405 |
.stderr_contains("missing argument") |
| 1406 |
.stderr_contains("erase"); |
| 1407 |
} |
| 1408 |
|
| 1409 |
#[test] |
| 1410 |
fn invalid_integer_rows() { |
| 1411 |
// Test invalid integer for rows |
| 1412 |
new_ucmd!() |
| 1413 |
.args(&["rows", "abc"]) |
| 1414 |
.fails() |
| 1415 |
.stderr_contains("invalid integer argument"); |
| 1416 |
|
| 1417 |
new_ucmd!() |
| 1418 |
.args(&["rows", "-1"]) |
| 1419 |
.fails() |
| 1420 |
.stderr_contains("invalid integer argument"); |
| 1421 |
} |
| 1422 |
|
| 1423 |
#[test] |
| 1424 |
fn invalid_integer_cols() { |
| 1425 |
// Test invalid integer for cols |
| 1426 |
new_ucmd!() |
| 1427 |
.args(&["cols", "xyz"]) |
| 1428 |
.fails() |
| 1429 |
.stderr_contains("invalid integer argument"); |
| 1430 |
|
| 1431 |
new_ucmd!() |
| 1432 |
.args(&["columns", "12.5"]) |
| 1433 |
.fails() |
| 1434 |
.stderr_contains("invalid integer argument"); |
| 1435 |
} |
| 1436 |
|
| 1437 |
#[test] |
| 1438 |
fn invalid_min_value() { |
| 1439 |
// Test invalid min value |
| 1440 |
new_ucmd!() |
| 1441 |
.args(&["min", "256"]) |
| 1442 |
.fails() |
| 1443 |
.stderr_contains("Value too large"); |
| 1444 |
|
| 1445 |
new_ucmd!() |
| 1446 |
.args(&["min", "-1"]) |
| 1447 |
.fails() |
| 1448 |
.stderr_contains("invalid integer argument"); |
| 1449 |
} |
| 1450 |
|
| 1451 |
#[test] |
| 1452 |
fn invalid_time_value() { |
| 1453 |
// Test invalid time value |
| 1454 |
new_ucmd!() |
| 1455 |
.args(&["time", "1000"]) |
| 1456 |
.fails() |
| 1457 |
.stderr_contains("Value too large"); |
| 1458 |
|
| 1459 |
new_ucmd!() |
| 1460 |
.args(&["time", "abc"]) |
| 1461 |
.fails() |
| 1462 |
.stderr_contains("invalid integer argument"); |
| 1463 |
} |
| 1464 |
|
| 1465 |
#[test] |
| 1466 |
fn invalid_baud_rate() { |
| 1467 |
// Test invalid baud rate for ispeed (non-numeric string) |
| 1468 |
// spell-checker:ignore notabaud |
| 1469 |
new_ucmd!() |
| 1470 |
.args(&["ispeed", "notabaud"]) |
| 1471 |
.fails() |
| 1472 |
.stderr_contains("invalid ispeed"); |
| 1473 |
|
| 1474 |
// On non-BSD systems, test invalid numeric baud rate |
| 1475 |
// On BSD systems, any u32 is accepted, so we skip this test |
| 1476 |
#[cfg(not(any( |
| 1477 |
target_vendor = "apple", |
| 1478 |
target_os = "freebsd", |
| 1479 |
target_os = "dragonfly", |
| 1480 |
target_os = "netbsd", |
| 1481 |
target_os = "openbsd" |
| 1482 |
)))] |
| 1483 |
{ |
| 1484 |
new_ucmd!() |
| 1485 |
.args(&["ospeed", "999999999"]) |
| 1486 |
.fails() |
| 1487 |
.stderr_contains("invalid ospeed"); |
| 1488 |
} |
| 1489 |
} |
| 1490 |
|
| 1491 |
#[test] |
| 1492 |
fn control_char_multiple_chars_error() { |
| 1493 |
// Test that control characters with multiple chars fail |
| 1494 |
new_ucmd!() |
| 1495 |
.args(&["intr", "ABC"]) |
| 1496 |
.fails() |
| 1497 |
.stderr_contains("invalid integer argument"); |
| 1498 |
} |
| 1499 |
|
| 1500 |
#[test] |
| 1501 |
fn control_char_decimal_overflow() { |
| 1502 |
// Test decimal overflow for control characters |
| 1503 |
new_ucmd!() |
| 1504 |
.args(&["quit", "256"]) |
| 1505 |
.fails() |
| 1506 |
.stderr_contains("Value too large"); |
| 1507 |
|
| 1508 |
// spell-checker:ignore susp |
| 1509 |
new_ucmd!() |
| 1510 |
.args(&["susp", "1000"]) |
| 1511 |
.fails() |
| 1512 |
.stderr_contains("Value too large"); |
| 1513 |
} |
| 1514 |
|
| 1515 |
#[test] |
| 1516 |
#[ignore = "Fails because the implementation of print state is not correctly printing flags on certain platforms"] |
| 1517 |
fn test_saved_state_with_control_chars() { |
| 1518 |
let (path, _controller, _replica) = pty_path(); |
| 1519 |
let (_at, ts) = at_and_ts!(); |
| 1520 |
|
| 1521 |
// Build a valid saved state with platform-specific number of control characters |
| 1522 |
let num_cc = libc::NCCS; |
| 1523 |
let cc_values: Vec<String> = (1..=num_cc).map(|_| format!("{:x}", 0)).collect(); |
| 1524 |
let saved_state = format!("500:5:4bf:8a3b:{}", cc_values.join(":")); |
| 1525 |
|
| 1526 |
ts.ucmd().args(&["--file", &path, &saved_state]).succeeds(); |
| 1527 |
|
| 1528 |
let result = ts.ucmd().args(&["-g", "--file", &path]).run(); |
| 1529 |
|
| 1530 |
result.success().stdout_contains(":"); |
| 1531 |
|
| 1532 |
let exp_result = unwrap_or_return!(expected_result(&ts, &["-g", "--file", &path])); |
| 1533 |
result |
| 1534 |
.stdout_is(exp_result.stdout_str()) |
| 1535 |
.stderr_is(exp_result.stderr_str()) |
| 1536 |
.code_is(exp_result.code()); |
| 1537 |
} |
| 1538 |
|
| 1539 |
// Per POSIX, stty uses stdin for TTY operations. When stdin is a pipe, it should fail. |
| 1540 |
#[test] |
| 1541 |
fn test_stdin_not_tty_fails() { |
| 1542 |
// ENOTTY error message varies by platform/libc: |
| 1543 |
// - glibc: "Inappropriate ioctl for device" |
| 1544 |
// - musl: "Not a tty" |
| 1545 |
// - Android: "Not a typewriter" |
| 1546 |
#[cfg(target_os = "android")] |
| 1547 |
let expected_error = "standard input: Not a typewriter"; |
| 1548 |
#[cfg(all(not(target_os = "android"), target_env = "musl"))] |
| 1549 |
let expected_error = "standard input: Not a tty"; |
| 1550 |
#[cfg(all(not(target_os = "android"), not(target_env = "musl")))] |
| 1551 |
let expected_error = "standard input: Inappropriate ioctl for device"; |
| 1552 |
|
| 1553 |
new_ucmd!() |
| 1554 |
.pipe_in("") |
| 1555 |
.fails() |
| 1556 |
.stderr_contains(expected_error); |
| 1557 |
} |
| 1558 |
|
| 1559 |
// Test that stty uses stdin for TTY operations per POSIX. |
| 1560 |
// Verifies: output redirection (#8012), save/restore pattern (#8608), stdin redirection (#8848) |
| 1561 |
#[test] |
| 1562 |
fn test_stty_uses_stdin() { |
| 1563 |
use std::fs::File; |
| 1564 |
use std::process::Stdio; |
| 1565 |
|
| 1566 |
let (path, _controller, _replica) = pty_path(); |
| 1567 |
|
| 1568 |
// Output redirection: stty > file (stdin is still TTY) |
| 1569 |
let stdin = File::open(&path).unwrap(); |
| 1570 |
new_ucmd!() |
| 1571 |
.set_stdin(stdin) |
| 1572 |
.set_stdout(Stdio::piped()) |
| 1573 |
.succeeds() |
| 1574 |
.stdout_contains("speed"); |
| 1575 |
|
| 1576 |
// Save/restore: stty $(stty -g) pattern |
| 1577 |
let stdin = File::open(&path).unwrap(); |
| 1578 |
let saved = new_ucmd!() |
| 1579 |
.arg("-g") |
| 1580 |
.set_stdin(stdin) |
| 1581 |
.set_stdout(Stdio::piped()) |
| 1582 |
.succeeds() |
| 1583 |
.stdout_str() |
| 1584 |
.trim() |
| 1585 |
.to_string(); |
| 1586 |
assert!(saved.contains(':'), "Expected colon-separated saved state"); |
| 1587 |
|
| 1588 |
let stdin = File::open(&path).unwrap(); |
| 1589 |
new_ucmd!().arg(&saved).set_stdin(stdin).succeeds(); |
| 1590 |
|
| 1591 |
// Stdin redirection: stty rows 30 cols 100 < /dev/pts/N |
| 1592 |
let stdin = File::open(&path).unwrap(); |
| 1593 |
new_ucmd!() |
| 1594 |
.args(&["rows", "30", "cols", "100"]) |
| 1595 |
.set_stdin(stdin) |
| 1596 |
.succeeds(); |
| 1597 |
|
| 1598 |
let stdin = File::open(&path).unwrap(); |
| 1599 |
new_ucmd!() |
| 1600 |
.arg("--all") |
| 1601 |
.set_stdin(stdin) |
| 1602 |
.succeeds() |
| 1603 |
.stdout_contains("rows 30") |
| 1604 |
.stdout_contains("columns 100"); |
| 1605 |
} |
| 1606 |
|
| 1607 |
#[test] |
| 1608 |
fn test_ispeed_ospeed_valid_speeds() { |
| 1609 |
let (path, _controller, _replica) = pty_path(); |
| 1610 |
let (_at, ts) = at_and_ts!(); |
| 1611 |
|
| 1612 |
// Test various valid baud rates for both ispeed and ospeed |
| 1613 |
let test_cases = [ |
| 1614 |
("ispeed", "50"), |
| 1615 |
("ispeed", "9600"), |
| 1616 |
("ispeed", "19200"), |
| 1617 |
("ospeed", "1200"), |
| 1618 |
("ospeed", "9600"), |
| 1619 |
("ospeed", "38400"), |
| 1620 |
]; |
| 1621 |
|
| 1622 |
for (arg, speed) in test_cases { |
| 1623 |
let result = ts.ucmd().args(&["--file", &path, arg, speed]).run(); |
| 1624 |
let exp_result = unwrap_or_return!(expected_result(&ts, &["--file", &path, arg, speed])); |
| 1625 |
let normalized_stderr = normalize_stderr(result.stderr_str()); |
| 1626 |
|
| 1627 |
result |
| 1628 |
.stdout_is(exp_result.stdout_str()) |
| 1629 |
.code_is(exp_result.code()); |
| 1630 |
assert_eq!(normalized_stderr, exp_result.stderr_str()); |
| 1631 |
} |
| 1632 |
} |
| 1633 |
|
| 1634 |
#[test] |
| 1635 |
#[cfg(not(any( |
| 1636 |
target_vendor = "apple", |
| 1637 |
target_os = "freebsd", |
| 1638 |
target_os = "dragonfly", |
| 1639 |
target_os = "netbsd", |
| 1640 |
target_os = "openbsd" |
| 1641 |
)))] |
| 1642 |
#[ignore = "Issue: #9547"] |
| 1643 |
fn test_ispeed_ospeed_invalid_speeds() { |
| 1644 |
let (path, _controller, _replica) = pty_path(); |
| 1645 |
let (_at, ts) = at_and_ts!(); |
| 1646 |
|
| 1647 |
// Test invalid speed values (non-standard baud rates) |
| 1648 |
let test_cases = [ |
| 1649 |
("ispeed", "12345"), |
| 1650 |
("ospeed", "99999"), |
| 1651 |
("ispeed", "abc"), |
| 1652 |
("ospeed", "xyz"), |
| 1653 |
]; |
| 1654 |
|
| 1655 |
for (arg, speed) in test_cases { |
| 1656 |
let result = ts.ucmd().args(&["--file", &path, arg, speed]).run(); |
| 1657 |
let exp_result = unwrap_or_return!(expected_result(&ts, &["--file", &path, arg, speed])); |
| 1658 |
let normalized_stderr = normalize_stderr(result.stderr_str()); |
| 1659 |
|
| 1660 |
result |
| 1661 |
.stdout_is(exp_result.stdout_str()) |
| 1662 |
.code_is(exp_result.code()); |
| 1663 |
assert_eq!(normalized_stderr, exp_result.stderr_str()); |
| 1664 |
} |
| 1665 |
} |
| 1666 |
|
| 1667 |
#[test] |
| 1668 |
fn test_columns_env_wrapping() { |
| 1669 |
use std::process::Stdio; |
| 1670 |
let (path, _controller, _replica) = pty_path(); |
| 1671 |
|
| 1672 |
// Must pipe output so stty uses COLUMNS env instead of actual terminal size |
| 1673 |
for (columns, max_len) in [(20, 20), (40, 40), (50, 50)] { |
| 1674 |
let result = new_ucmd!() |
| 1675 |
.args(&["--all", "--file", &path]) |
| 1676 |
.env("COLUMNS", columns.to_string()) |
| 1677 |
.set_stdout(Stdio::piped()) |
| 1678 |
.succeeds(); |
| 1679 |
|
| 1680 |
for line in result.stdout_str().lines() { |
| 1681 |
assert!( |
| 1682 |
line.len() <= max_len, |
| 1683 |
"Line exceeds COLUMNS={columns}: '{line}'" |
| 1684 |
); |
| 1685 |
} |
| 1686 |
} |
| 1687 |
|
| 1688 |
// Wide columns should allow longer lines |
| 1689 |
let result = new_ucmd!() |
| 1690 |
.args(&["--all", "--file", &path]) |
| 1691 |
.env("COLUMNS", "200") |
| 1692 |
.set_stdout(Stdio::piped()) |
| 1693 |
.succeeds(); |
| 1694 |
let has_long_line = result.stdout_str().lines().any(|line| line.len() > 80); |
| 1695 |
assert!( |
| 1696 |
has_long_line, |
| 1697 |
"Expected at least one line longer than 80 chars with COLUMNS=200" |
| 1698 |
); |
| 1699 |
|
| 1700 |
// Invalid values should fall back to default |
| 1701 |
for invalid in ["invalid", "0", "-10"] { |
| 1702 |
new_ucmd!() |
| 1703 |
.args(&["--all", "--file", &path]) |
| 1704 |
.env("COLUMNS", invalid) |
| 1705 |
.set_stdout(Stdio::piped()) |
| 1706 |
.succeeds(); |
| 1707 |
} |
| 1708 |
|
| 1709 |
// Without --all flag |
| 1710 |
let result = new_ucmd!() |
| 1711 |
.args(&["--file", &path]) |
| 1712 |
.env("COLUMNS", "30") |
| 1713 |
.set_stdout(Stdio::piped()) |
| 1714 |
.succeeds(); |
| 1715 |
for line in result.stdout_str().lines() { |
| 1716 |
assert!( |
| 1717 |
line.len() <= 30, |
| 1718 |
"Line exceeds COLUMNS=30 without --all: '{line}'" |
| 1719 |
); |
| 1720 |
} |
| 1721 |
} |