Skip to content

Commit 7c11da0

Browse files
committed
test(gencat): add tests for gencat empty file
1 parent 271aaa2 commit 7c11da0

9 files changed

+69
-1
lines changed

i18n/gencat.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -773,7 +773,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
773773
match MessageCatalog::parse(&args.msgfile, catfile_catalog) {
774774
Ok(catalog) => {
775775
let mut buffer = Cursor::new(Vec::new());
776-
catalog.write_catfile_another(&mut buffer)?;
776+
catalog.write_catfile(&mut buffer)?;
777777

778778
if catfile_path_str == "-" {
779779
io::stdout().write_all(&buffer.get_ref())?;

i18n/tests/gencat/empty_message_file.msg

Whitespace-only changes.
36 Bytes
Binary file not shown.
32 Bytes
Binary file not shown.

i18n/tests/gencat/mod.rs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
//
2+
// Copyright (c) 2024 Jeff Garzik
3+
//
4+
// This file is part of the posixutils-rs project covered under
5+
// the MIT License. For the full license text, please see the LICENSE
6+
// file in the root directory of this project.
7+
// SPDX-License-Identifier: MIT
8+
//
9+
10+
use plib::{run_test_u8, TestPlanU8};
11+
use std::env;
12+
use std::path::PathBuf;
13+
use std::{fs::File, io::Read};
14+
15+
fn gencat_test(args: &[&str], expected_output: Vec<u8>, expected_error: Vec<u8>) {
16+
let str_args: Vec<String> = args.iter().map(|s| String::from(*s)).collect();
17+
run_test_u8(TestPlanU8 {
18+
cmd: String::from("gencat"),
19+
args: str_args,
20+
stdin_data: Vec::new(),
21+
expected_out: expected_output,
22+
expected_err: expected_error,
23+
expected_exit_code: 0,
24+
})
25+
}
26+
27+
#[test]
28+
fn gencat_empty_message_file() {
29+
let cargo_manifest_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap());
30+
let msg_file = cargo_manifest_dir.join("tests/gencat/empty_message_file.msg");
31+
32+
#[cfg(not(target_os = "macos"))]
33+
let expected_cat_file =
34+
cargo_manifest_dir.join("tests/gencat/empty_message_file_gnu_catfile.cat");
35+
36+
#[cfg(target_os = "macos")]
37+
let expected_cat_file =
38+
cargo_manifest_dir.join("tests/gencat/empty_message_file_osx_catfile.cat");
39+
40+
// let encoded_file = cargo_manifest_dir.join("tests/uucode/sample_historical_encoded.txt");
41+
let mut expected_output: Vec<u8> = Vec::new();
42+
File::open(&expected_cat_file)
43+
.unwrap()
44+
.read_to_end(&mut expected_output)
45+
.unwrap();
46+
47+
gencat_test(
48+
&["-", msg_file.to_str().unwrap()],
49+
expected_output,
50+
Vec::new(),
51+
);
52+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
$set 1
2+
1 This is first message
3+
2 This is second message
4+
$set 2
5+
1 This is third message
6+
2 This is fourth message
198 Bytes
Binary file not shown.
266 Bytes
Binary file not shown.

i18n/tests/i18n-tests.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
//
2+
// Copyright (c) 2024 Jeff Garzik
3+
//
4+
// This file is part of the posixutils-rs project covered under
5+
// the MIT License. For the full license text, please see the LICENSE
6+
// file in the root directory of this project.
7+
// SPDX-License-Identifier: MIT
8+
//
9+
10+
mod gencat;

0 commit comments

Comments
 (0)