Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions calc/tests/bc-tests.rs → calc/tests/bc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,17 @@ fn test_bc_with_math_library(program: &str, expected_output: &str) {
macro_rules! test_bc {
($test_name:ident) => {
test_bc(
include_str!(concat!("bc/", stringify!($test_name), ".bc")),
include_str!(concat!("bc/", stringify!($test_name), ".out")),
include_str!(concat!("./", stringify!($test_name), ".bc")),
include_str!(concat!("./", stringify!($test_name), ".out")),
)
};
}

macro_rules! test_bc_l {
($test_name:ident) => {
test_bc_with_math_library(
include_str!(concat!("bc/", stringify!($test_name), ".bc")),
include_str!(concat!("bc/", stringify!($test_name), ".out")),
include_str!(concat!("./", stringify!($test_name), ".bc")),
include_str!(concat!("./", stringify!($test_name), ".out")),
)
};
}
Expand Down
5 changes: 3 additions & 2 deletions tree/tests/ls-tests.rs → calc/tests/calc-tests.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
//
// Copyright (c) 2024 Hemi Labs, Inc.
// Copyright (c) 2024 Jeff Garzik
//
// This file is part of the posixutils-rs project covered under
// the MIT License. For the full license text, please see the LICENSE
// file in the root directory of this project.
// SPDX-License-Identifier: MIT
//

mod ls;
mod bc;
mod expr;
File renamed without changes.
File renamed without changes.
5 changes: 3 additions & 2 deletions tree/tests/mv-tests.rs → display/tests/display-tests.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
//
// Copyright (c) 2024 Hemi Labs, Inc.
// Copyright (c) 2024 Jeff Garzik
//
// This file is part of the posixutils-rs project covered under
// the MIT License. For the full license text, please see the LICENSE
// file in the root directory of this project.
// SPDX-License-Identifier: MIT
//

mod mv;
mod echo;
mod printf;
File renamed without changes.
File renamed without changes.
114 changes: 114 additions & 0 deletions file/tests/cmp/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
//
// Copyright (c) 2024 Jeff Garzik
//
// This file is part of the posixutils-rs project covered under
// the MIT License. For the full license text, please see the LICENSE
// file in the root directory of this project.
// SPDX-License-Identifier: MIT
//

use plib::{run_test, TestPlan};

fn run_test_helper(
args: &[&str],
expected_output: &str,
expected_error: &str,
expected_exit_code: i32,
) {
let str_args: Vec<String> = args.iter().map(|s| String::from(*s)).collect();

run_test(TestPlan {
cmd: String::from("cmp"),
args: str_args,
stdin_data: String::new(),
expected_out: String::from(expected_output),
expected_err: String::from(expected_error),
expected_exit_code,
});
}

#[test]
fn cmp_same() {
let mut files = vec![String::from("tests/cmp/lorem_ipsum.txt")];
let indices = [0, 45, 90, 135, 180, 225, 270, 315, 360, 405, 450];
for i in indices {
files.push(format!("tests/cmp/lorem_ipsum_{i}.txt"));
}

for file in &files {
run_test_helper(&[file, file], "", "", 0);
}
}

#[test]
fn cmp_different() {
let original = "tests/cmp/lorem_ipsum.txt";

let indices = [0, 45, 90, 135, 180, 225, 270, 315, 360, 405, 450];
let bytes = [1, 46, 91, 136, 181, 226, 271, 316, 361, 406, 451];
let lines = [1, 1, 2, 2, 3, 4, 4, 5, 5, 6, 7];

for i in 0..indices.len() {
let modified = format!("tests/cmp/lorem_ipsum_{}.txt", indices[i]);
run_test_helper(
&[original, &modified],
&format!(
"{original} {modified} differ: char {}, line {}\n",
bytes[i], lines[i]
),
"",
1,
);
}
}

#[test]
fn cmp_different_silent() {
let original = "tests/cmp/lorem_ipsum.txt";

let indices = [0, 45, 90, 135, 180, 225, 270, 315, 360, 405, 450];

for i in 0..indices.len() {
let modified = format!("tests/cmp/lorem_ipsum_{}.txt", indices[i]);
run_test_helper(&["-s", original, &modified], "", "", 1);
}
}

#[test]
fn cmp_different_less_verbose() {
let original = "tests/cmp/lorem_ipsum.txt";

let indices = [0, 45, 90, 135, 180, 225, 270, 315, 360, 405, 450];
let bytes = [1, 46, 91, 136, 181, 226, 271, 316, 361, 406, 451];
let chars_original = ['L', 's', ' ', ' ', 'a', 'o', 'r', ' ', 'a', ' ', '.'];

for i in 0..indices.len() {
let modified = format!("tests/cmp/lorem_ipsum_{}.txt", indices[i]);
run_test_helper(
&["-l", original, &modified],
&format!(
"{} {:o} {:o}\n",
bytes[i], chars_original[i] as u8, '?' as u8
),
"",
1,
);
}
}

#[test]
fn cmp_eof() {
let original = "tests/cmp/lorem_ipsum.txt";
let truncated = "tests/cmp/lorem_ipsum_trunc.txt";

// Status code must be 1. From the specification:
//
// "...this includes the case where one file is identical to the first part
// of the other."
run_test_helper(
&[original, truncated],
"",
&format!("cmp: EOF on {truncated}\n"),
1,
);
}
File renamed without changes.
13 changes: 13 additions & 0 deletions file/tests/file-tests.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// Copyright (c) 2024 Jeff Garzik
//
// This file is part of the posixutils-rs project covered under
// the MIT License. For the full license text, please see the LICENSE
// file in the root directory of this project.
// SPDX-License-Identifier: MIT
//

mod cmp;
mod dd;
mod file;
mod od;
Loading