Add test case to find errors that are only used for federation

This commit is contained in:
Felix Ableitner 2024-09-13 22:55:24 +02:00
parent bd2c97542f
commit c422b88cf8
2 changed files with 20 additions and 5 deletions

View file

@ -23,6 +23,7 @@ pub enum LemmyErrorType {
CouldntUpdateComment, CouldntUpdateComment,
CouldntUpdatePrivateMessage, CouldntUpdatePrivateMessage,
CannotLeaveAdmin, CannotLeaveAdmin,
// TODO: also remove the translations of unused errors
PictrsResponseError(String), PictrsResponseError(String),
PictrsPurgeResponseError(String), PictrsPurgeResponseError(String),
ImageUrlMissingPathSegments, ImageUrlMissingPathSegments,

View file

@ -9,20 +9,34 @@ fn test_errors_used() {
current_dir.pop(); current_dir.pop();
current_dir.pop(); current_dir.pop();
for error in LemmyErrorType::iter() { for error in LemmyErrorType::iter() {
let mut command = Command::new("grep"); let mut grep_all = Command::new("grep");
let command = command let grep_all = grep_all
.current_dir(current_dir.clone()) .current_dir(current_dir.clone())
.arg("-R") .arg("-R")
.arg("--exclude=error.rs") .arg("--exclude=error.rs")
.arg(error.to_string()) .arg(error.to_string())
.arg("crates/") .arg("crates/")
.arg("src/"); .arg("src/");
let output = command.output().unwrap(); let output = grep_all.output().unwrap();
let stdout = std::str::from_utf8(&output.stdout).unwrap(); let grep_all_out = std::str::from_utf8(&output.stdout).unwrap();
if stdout.len() == 0 {
let mut grep_apub = Command::new("grep");
let grep_apub = grep_apub
.current_dir(current_dir.clone())
.arg("-R")
.arg(error.to_string())
.arg("crates/apub/");
let output = grep_apub.output().unwrap();
let grep_apub_out = std::str::from_utf8(&output.stdout).unwrap();
if grep_all_out.len() == 0 {
println!("LemmyErrorType::{} is unused", error); println!("LemmyErrorType::{} is unused", error);
unused_error_found = true; unused_error_found = true;
} }
if grep_all_out == grep_apub_out {
println!("LemmyErrorType::{} is only used for federation", error);
unused_error_found = true;
}
} }
assert!(unused_error_found == false); assert!(unused_error_found == false);
} }