Add test case to ensure all errors are in use

This commit is contained in:
Felix Ableitner 2024-09-13 22:50:11 +02:00
parent dea6ee462c
commit bd2c97542f
2 changed files with 29 additions and 10 deletions

View file

@ -1,6 +1,6 @@
use cfg_if::cfg_if; use cfg_if::cfg_if;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::{backtrace::Backtrace, fmt::Debug}; use std::fmt::Debug;
use strum::{Display, EnumIter}; use strum::{Display, EnumIter};
#[derive(Display, Debug, Serialize, Deserialize, Clone, PartialEq, Eq, EnumIter, Hash)] #[derive(Display, Debug, Serialize, Deserialize, Clone, PartialEq, Eq, EnumIter, Hash)]
@ -23,19 +23,14 @@ pub enum LemmyErrorType {
CouldntUpdateComment, CouldntUpdateComment,
CouldntUpdatePrivateMessage, CouldntUpdatePrivateMessage,
CannotLeaveAdmin, CannotLeaveAdmin,
NoLinesInHtml,
SiteMetadataPageIsNotDoctypeHtml,
PictrsResponseError(String), PictrsResponseError(String),
PictrsPurgeResponseError(String), PictrsPurgeResponseError(String),
PictrsCachingDisabled,
ImageUrlMissingPathSegments, ImageUrlMissingPathSegments,
ImageUrlMissingLastPathSegment, ImageUrlMissingLastPathSegment,
PictrsApiKeyNotProvided, PictrsApiKeyNotProvided,
NoContentTypeHeader, NoContentTypeHeader,
NotAnImageType, NotAnImageType,
NotAModOrAdmin, NotAModOrAdmin,
NoAdmins,
NotTopAdmin,
NotTopMod, NotTopMod,
NotLoggedIn, NotLoggedIn,
NotHigherMod, NotHigherMod,
@ -84,18 +79,15 @@ pub enum LemmyErrorType {
RegistrationClosed, RegistrationClosed,
RegistrationApplicationAnswerRequired, RegistrationApplicationAnswerRequired,
EmailAlreadyExists, EmailAlreadyExists,
FederationForbiddenByStrictAllowList,
PersonIsBannedFromCommunity, PersonIsBannedFromCommunity,
ObjectIsNotPublic, ObjectIsNotPublic,
InvalidCommunity, InvalidCommunity,
CannotCreatePostOrCommentInDeletedOrRemovedCommunity, CannotCreatePostOrCommentInDeletedOrRemovedCommunity,
CannotReceivePage, CannotReceivePage,
NewPostCannotBeLocked,
OnlyLocalAdminCanRemoveCommunity, OnlyLocalAdminCanRemoveCommunity,
OnlyLocalAdminCanRestoreCommunity, OnlyLocalAdminCanRestoreCommunity,
NoIdGiven, NoIdGiven,
IncorrectLogin, IncorrectLogin,
InvalidQuery,
ObjectNotLocal, ObjectNotLocal,
PostIsLocked, PostIsLocked,
PersonIsBannedFromSite(String), PersonIsBannedFromSite(String),
@ -138,7 +130,6 @@ pub enum LemmyErrorType {
CouldntUpdateCommunity, CouldntUpdateCommunity,
CouldntUpdateReplies, CouldntUpdateReplies,
CouldntUpdatePersonMentions, CouldntUpdatePersonMentions,
PostTitleTooLong,
CouldntCreatePost, CouldntCreatePost,
CouldntCreatePrivateMessage, CouldntCreatePrivateMessage,
CouldntUpdatePrivate, CouldntUpdatePrivate,

View file

@ -0,0 +1,28 @@
use lemmy_utils::LemmyErrorType;
use std::{env::current_dir, process::Command};
use strum::IntoEnumIterator;
#[test]
fn test_errors_used() {
let mut unused_error_found = false;
let mut current_dir = current_dir().unwrap();
current_dir.pop();
current_dir.pop();
for error in LemmyErrorType::iter() {
let mut command = Command::new("grep");
let command = command
.current_dir(current_dir.clone())
.arg("-R")
.arg("--exclude=error.rs")
.arg(error.to_string())
.arg("crates/")
.arg("src/");
let output = command.output().unwrap();
let stdout = std::str::from_utf8(&output.stdout).unwrap();
if stdout.len() == 0 {
println!("LemmyErrorType::{} is unused", error);
unused_error_found = true;
}
}
assert!(unused_error_found == false);
}