Super simple assert for now.
Some checks failed
Dropshell Test / Build_and_Test (push) Has been cancelled

This commit is contained in:
Your Name 2025-05-13 21:46:04 +12:00
parent 972d5f4db7
commit 4b4b99634c
14 changed files with 35 additions and 35 deletions

View File

@ -49,21 +49,10 @@ target_include_directories(dropshell PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/src/commands
)
include(FetchContent)
FetchContent_Declare(
libassert
GIT_REPOSITORY https://github.com/jeremy-rifkin/libassert.git
GIT_TAG v2.1.5 # <HASH or TAG>
)
FetchContent_MakeAvailable(libassert)
target_link_libraries(dropshell libassert::assert)
# On windows copy libassert.dll to the same directory as the executable for your_target
if(WIN32)
add_custom_command(
TARGET dropshell POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
$<TARGET_FILE:libassert::assert>
$<TARGET_FILE_DIR:dropshell>
)
endif()

View File

@ -5,7 +5,7 @@
#include "services.hpp"
#include "servers.hpp"
#include <libassert/assert.hpp>
#include <assert.hpp>
#include <algorithm>
#include <iostream>
@ -36,7 +36,7 @@ bool autocomplete(const std::vector<std::string> &args)
return true;
}
ASSERT(args.size() >= 3);
ASSERT(args.size() >= 3, "Invalid number of arguments");
std::string cmd = args[2];
// std::cout<<" cmd = ["<<cmd<<"]"<<std::endl;

View File

@ -9,7 +9,7 @@
#include <iostream>
#include <sstream>
#include <filesystem>
#include <libassert/assert.hpp>
#include "utils/assert.hpp"
namespace dropshell {

View File

@ -10,7 +10,7 @@
#include <iostream>
#include <sstream>
#include <filesystem>
#include <libassert/assert.hpp>
#include "utils/assert.hpp"
namespace dropshell {

View File

@ -11,7 +11,7 @@
#include <iostream>
#include <sstream>
#include <filesystem>
#include <libassert/assert.hpp>
#include "utils/assert.hpp"
namespace dropshell
{
@ -59,7 +59,7 @@ namespace dropshell
server_env_manager &server_env,
bool silent)
{
ASSERT(!local_path.empty() && !remote_path.empty());
ASSERT(!local_path.empty() && !remote_path.empty(), "Local or remote path not specified. Can't rsync.");
std::string rsync_cmd = "rsync --delete --mkpath -zrpc -e 'ssh -p " + server_env.get_SSH_PORT() + "' " +
quote(local_path + "/") + " " +

View File

@ -12,7 +12,7 @@
#include <iostream>
#include <sstream>
#include <filesystem>
#include <libassert/assert.hpp>
#include "utils/assert.hpp"
namespace dropshell {

View File

@ -7,7 +7,7 @@
#include "servers.hpp"
#include "templates.hpp"
#include <libassert/assert.hpp>
#include "utils/assert.hpp"
#pragma TODO("Fix issues with Nuke below.")

View File

@ -4,7 +4,7 @@
#include "servers.hpp"
#include "services.hpp"
#include <libassert/assert.hpp>
#include "utils/assert.hpp"
namespace dropshell {

View File

@ -3,7 +3,7 @@
#include "shared_commands.hpp"
#include "templates.hpp"
#include <libassert/assert.hpp>
#include "utils/assert.hpp"
namespace dropshell
{

View File

@ -16,7 +16,7 @@
#include <vector>
#include <iomanip>
#include <chrono>
#include <libassert/assert.hpp>
#include <assert.hpp>
#include <sstream>
#include <algorithm>
namespace dropshell {

View File

@ -7,7 +7,7 @@
#include <iomanip>
#include <filesystem>
#include <unistd.h>
#include <libassert/assert.hpp>
#include "utils/assert.hpp"
#include "config.hpp"
#include "service_runner.hpp"
@ -457,7 +457,7 @@ bool service_runner::backup(bool silent) {
std::string local_backup_file_path = (std::filesystem::path(local_backups_dir) / backup_filename).string();
// assert that the backup filename is valid - -_- appears exactly 3 times in local_backup_file_path.
ASSERT(3 == count_substring(magic_string, local_backup_file_path));
ASSERT(3 == count_substring(magic_string, local_backup_file_path), "Invalid backup filename");
{ // Run backup script
cRemoteTempFolder remote_temp_folder(mServerEnv);

View File

@ -6,7 +6,7 @@
#include <algorithm>
#include <iomanip>
#include <map>
#include <libassert/assert.hpp>
#include "utils/assert.hpp"
#include "utils/envmanager.hpp"
#include "utils/directories.hpp"
@ -105,7 +105,7 @@
// ------------------------------------------------------------------------------------------------
void template_manager::list_templates() const {
ASSERT(mLoaded && mSources.size() > 0);
ASSERT(mLoaded && mSources.size() > 0, "Template manager not loaded, or no template sources found.");
auto templates = get_template_list();
if (templates.empty()) {
@ -128,7 +128,7 @@
std::set<std::string> template_manager::get_template_list() const
{
ASSERT(mLoaded && mSources.size() > 0);
ASSERT(mLoaded && mSources.size() > 0, "Template manager not loaded, or no template sources found.");
std::set<std::string> templates;
for (const auto& source : mSources) {
auto source_templates = source->get_template_list();
@ -139,7 +139,7 @@
bool template_manager::has_template(const std::string &template_name) const
{
ASSERT(mLoaded && mSources.size() > 0);
ASSERT(mLoaded && mSources.size() > 0, "Template manager not loaded, or no template sources found.");
template_source_interface* source = get_source(template_name);
if (!source)
return false;
@ -148,7 +148,7 @@
template_info template_manager::get_template_info(const std::string &template_name) const
{
ASSERT(mLoaded && mSources.size() > 0);
ASSERT(mLoaded && mSources.size() > 0, "Template manager not loaded, or no template sources found.");
template_source_interface* source = get_source(template_name);
if (source)
return source->get_template_info(template_name);
@ -159,7 +159,7 @@
bool template_manager::template_command_exists(const std::string &template_name, const std::string &command) const
{
ASSERT(mLoaded && mSources.size() > 0);
ASSERT(mLoaded && mSources.size() > 0, "Template manager not loaded, or no template sources found.");
template_source_interface* source = get_source(template_name);
if (!source) {
std::cerr << "Error: Template '" << template_name << "' not found" << std::endl;
@ -249,9 +249,9 @@
void template_manager::load_sources()
{
ASSERT(mSources.empty());
ASSERT(gConfig().is_config_set());
ASSERT(!mLoaded);
ASSERT(mSources.empty(), "Template manager already loaded (sources are not empty).");
ASSERT(gConfig().is_config_set(), "Config not set.");
ASSERT(!mLoaded, "Template manager already loaded.");
auto local_template_paths = gConfig().get_template_local_paths();
if (local_template_paths.empty())
return;
@ -285,7 +285,7 @@
template_source_interface *template_manager::get_source(const std::string &template_name) const
{
ASSERT(mLoaded && mSources.size() > 0);
ASSERT(mLoaded && mSources.size() > 0, "Template manager not loaded, or no template sources found.");
for (const auto& source : mSources) {
if (source->has_template(template_name)) {
return source.get();

11
src/utils/assert.hpp Normal file
View File

@ -0,0 +1,11 @@
#ifndef ASSERT_HPP
#define ASSERT_HPP
#define ASSERT(condition, message) \
if (!(condition)) { \
std::cerr << "Assertion failed: " << message << std::endl; \
std::exit(1); \
}
#endif // ASSERT_HPP

View File

@ -6,7 +6,7 @@
#include <string>
#include <cstdlib>
#include <sstream>
#include <libassert/assert.hpp>
#include "utils/assert.hpp"
#include "execute.hpp"
#include "utils/utils.hpp"