mirror of
https://github.com/fish-shell/fish-shell
synced 2024-11-15 01:17:45 +00:00
Double the speed of cargo test
, actually run test
- Parallelize the slow tests if possible. - `test_convert_ascii` was missing a `#[test]` annotation
This commit is contained in:
parent
47f1dbe56c
commit
7b0f9fd5f8
3 changed files with 48 additions and 35 deletions
|
@ -1,4 +1,3 @@
|
|||
#[allow(unused_imports)]
|
||||
use crate::common::{scoped_push, ScopeGuard, ScopeGuarding};
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
#[cfg(test)]
|
||||
mod common;
|
||||
mod fd_monitor;
|
||||
#[cfg(test)]
|
||||
mod string_escape;
|
||||
|
|
|
@ -1,11 +1,9 @@
|
|||
#![allow(unused_imports)]
|
||||
use crate::common::{
|
||||
escape_string, str2wcstring, unescape_string, wcs2string, EscapeFlags, EscapeStringStyle,
|
||||
UnescapeStringStyle, ENCODE_DIRECT_BASE, ENCODE_DIRECT_END,
|
||||
};
|
||||
use crate::wchar::{widestrs, wstr, WString};
|
||||
use crate::wutil::encoding::{wcrtomb, zero_mbstate, AT_LEAST_MB_LEN_MAX};
|
||||
use rand::SeedableRng;
|
||||
use rand::{Rng, RngCore};
|
||||
use rand_pcg::Pcg64Mcg;
|
||||
|
||||
|
@ -99,9 +97,8 @@ fn test_escape_var() {
|
|||
}
|
||||
}
|
||||
|
||||
#[widestrs]
|
||||
#[test]
|
||||
fn test_escape_random() {
|
||||
macro_rules! escape_test {
|
||||
($escape_style:expr, $unescape_style:expr) => {
|
||||
setlocale();
|
||||
let seed: u128 = 92348567983274852905629743984572;
|
||||
let mut rng = Pcg64Mcg::new(seed);
|
||||
|
@ -116,23 +113,37 @@ fn test_escape_random() {
|
|||
.push(char::from_u32((rng.next_u32() % ESCAPE_TEST_CHAR as u32) + 1).unwrap());
|
||||
}
|
||||
|
||||
for (escape_style, unescape_style) in [
|
||||
(EscapeStringStyle::default(), UnescapeStringStyle::default()),
|
||||
(EscapeStringStyle::Var, UnescapeStringStyle::Var),
|
||||
(EscapeStringStyle::Url, UnescapeStringStyle::Url),
|
||||
] {
|
||||
escaped_string = escape_string(&random_string, escape_style);
|
||||
let Some(unescaped_string) = unescape_string(&escaped_string, unescape_style) else {
|
||||
escaped_string = escape_string(&random_string, $escape_style);
|
||||
let Some(unescaped_string) = unescape_string(&escaped_string, $unescape_style) else {
|
||||
let slice = escaped_string.as_char_slice();
|
||||
panic!("Failed to unescape string {slice:?} using style {unescape_style:?}");
|
||||
panic!("Failed to unescape string {slice:?}");
|
||||
};
|
||||
assert_eq!(random_string, unescaped_string, "Escaped and then unescaped string {random_string:?}, but got back a different string {unescaped_string:?}. The intermediate escape looked like {escaped_string:?}. Using escape style {escape_style:?}");
|
||||
}
|
||||
assert_eq!(random_string, unescaped_string, "Escaped and then unescaped string {random_string:?}, but got back a different string {unescaped_string:?}. The intermediate escape looked like {escaped_string:?}.");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_escape_random_script() {
|
||||
escape_test!(EscapeStringStyle::default(), UnescapeStringStyle::default());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_escape_random_var() {
|
||||
escape_test!(EscapeStringStyle::Var, UnescapeStringStyle::Var);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_escape_random_url() {
|
||||
escape_test!(EscapeStringStyle::Url, UnescapeStringStyle::Url);
|
||||
}
|
||||
|
||||
#[widestrs]
|
||||
#[test]
|
||||
fn test_escape_no_printables() {
|
||||
// Verify that ESCAPE_NO_PRINTABLES also escapes backslashes so we don't regress on issue #3892.
|
||||
random_string = "line 1\\n\nline 2"L.to_owned();
|
||||
escaped_string = escape_string(
|
||||
let random_string = "line 1\\n\nline 2"L.to_owned();
|
||||
let escaped_string = escape_string(
|
||||
&random_string,
|
||||
EscapeStringStyle::Script(EscapeFlags::NO_PRINTABLES | EscapeFlags::NO_QUOTED),
|
||||
);
|
||||
|
@ -192,7 +203,8 @@ fn test_convert() {
|
|||
}
|
||||
|
||||
/// Verify that ASCII narrow->wide conversions are correct.
|
||||
pub fn test_convert_ascii() {
|
||||
#[test]
|
||||
fn test_convert_ascii() {
|
||||
let mut s = vec![b'\0'; 4096];
|
||||
for (i, c) in s.iter_mut().enumerate() {
|
||||
*c = u8::try_from(i % 10).unwrap() + b'0';
|
||||
|
|
Loading…
Reference in a new issue