fix unit test for spawn_pipe

This commit is contained in:
mykola2312 2024-03-31 19:29:31 +03:00
parent 1b9770235d
commit 48f8d93516

View file

@ -98,22 +98,26 @@ pub async fn spawn_pipe(
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use std::fs;
use crate::dl::spawn::{spawn_pipe, SpawnError}; use crate::dl::spawn::{spawn_pipe, SpawnError};
use crate::dl::tmpfile::TmpFile; use crate::dl::tmpfile::TmpFile;
#[tokio::test] #[tokio::test]
async fn test_spawn_pipe() { async fn test_spawn_pipe() {
let stdout = TmpFile::new("stdout.test").unwrap(); let stdout_file = TmpFile::new("stdout.test").unwrap();
let result = spawn_pipe( let result = spawn_pipe(
"python", "python",
&[ &[
"-c", "-c",
"import sys; print(file=sys.stderr, 'stderr test'); sys.exit(1)", "import sys; print('stdout test', end=''); print('stderr test', file=sys.stderr, end=''); sys.exit(1)",
], ],
&stdout, &stdout_file,
) )
.await; .await;
let stdout = fs::read_to_string(&stdout_file.path).unwrap();
assert_eq!("stdout test", stdout);
assert_eq!(true, result.is_err()); assert_eq!(true, result.is_err());
if let Err(e) = result { if let Err(e) = result {
match e { match e {