mirror of
https://github.com/LemmyNet/lemmy
synced 2024-11-10 06:54:12 +00:00
Add test case to ensure all errors are in use
This commit is contained in:
parent
dea6ee462c
commit
bd2c97542f
2 changed files with 29 additions and 10 deletions
|
@ -1,6 +1,6 @@
|
|||
use cfg_if::cfg_if;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::{backtrace::Backtrace, fmt::Debug};
|
||||
use std::fmt::Debug;
|
||||
use strum::{Display, EnumIter};
|
||||
|
||||
#[derive(Display, Debug, Serialize, Deserialize, Clone, PartialEq, Eq, EnumIter, Hash)]
|
||||
|
@ -23,19 +23,14 @@ pub enum LemmyErrorType {
|
|||
CouldntUpdateComment,
|
||||
CouldntUpdatePrivateMessage,
|
||||
CannotLeaveAdmin,
|
||||
NoLinesInHtml,
|
||||
SiteMetadataPageIsNotDoctypeHtml,
|
||||
PictrsResponseError(String),
|
||||
PictrsPurgeResponseError(String),
|
||||
PictrsCachingDisabled,
|
||||
ImageUrlMissingPathSegments,
|
||||
ImageUrlMissingLastPathSegment,
|
||||
PictrsApiKeyNotProvided,
|
||||
NoContentTypeHeader,
|
||||
NotAnImageType,
|
||||
NotAModOrAdmin,
|
||||
NoAdmins,
|
||||
NotTopAdmin,
|
||||
NotTopMod,
|
||||
NotLoggedIn,
|
||||
NotHigherMod,
|
||||
|
@ -84,18 +79,15 @@ pub enum LemmyErrorType {
|
|||
RegistrationClosed,
|
||||
RegistrationApplicationAnswerRequired,
|
||||
EmailAlreadyExists,
|
||||
FederationForbiddenByStrictAllowList,
|
||||
PersonIsBannedFromCommunity,
|
||||
ObjectIsNotPublic,
|
||||
InvalidCommunity,
|
||||
CannotCreatePostOrCommentInDeletedOrRemovedCommunity,
|
||||
CannotReceivePage,
|
||||
NewPostCannotBeLocked,
|
||||
OnlyLocalAdminCanRemoveCommunity,
|
||||
OnlyLocalAdminCanRestoreCommunity,
|
||||
NoIdGiven,
|
||||
IncorrectLogin,
|
||||
InvalidQuery,
|
||||
ObjectNotLocal,
|
||||
PostIsLocked,
|
||||
PersonIsBannedFromSite(String),
|
||||
|
@ -138,7 +130,6 @@ pub enum LemmyErrorType {
|
|||
CouldntUpdateCommunity,
|
||||
CouldntUpdateReplies,
|
||||
CouldntUpdatePersonMentions,
|
||||
PostTitleTooLong,
|
||||
CouldntCreatePost,
|
||||
CouldntCreatePrivateMessage,
|
||||
CouldntUpdatePrivate,
|
||||
|
|
28
crates/utils/tests/test_errors_used.rs
Normal file
28
crates/utils/tests/test_errors_used.rs
Normal 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);
|
||||
}
|
Loading…
Reference in a new issue