Manager+Util: Switch to custom assert macro
This commit is contained in:
+2
-2
@@ -4,7 +4,6 @@
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
#include <cassert> // assert
|
||||
#include <csignal> // raise
|
||||
#include <cstdio> // fprintf
|
||||
#include <filesystem> // current_path, recursive_directory
|
||||
@@ -14,6 +13,7 @@
|
||||
|
||||
#include "config.h"
|
||||
#include "util/json/json.h"
|
||||
#include "util/meta/assert.h"
|
||||
|
||||
Config::Config(s)
|
||||
: m_workingDirectory(std::filesystem::current_path())
|
||||
@@ -82,7 +82,7 @@ void toJson(Util::Json& json, const Settings& settings)
|
||||
|
||||
void fromJson(const Util::Json& json, Settings& settings)
|
||||
{
|
||||
assert(json.type() == Util::Json::Type::Object);
|
||||
VERIFY(json.type() == Util::Json::Type::Object);
|
||||
|
||||
if (json.exists("ignorePatterns")) {
|
||||
json.at("ignorePatterns").getTo(settings.ignorePatterns);
|
||||
|
||||
+2
-2
@@ -4,7 +4,6 @@
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
#include <cassert> // assert
|
||||
#include <cctype> // tolower
|
||||
#include <cstddef> // size_t
|
||||
#include <cstdio> // fprintf, printf, stderr
|
||||
@@ -20,6 +19,7 @@
|
||||
#include "dotfile.h"
|
||||
#include "machine.h"
|
||||
#include "util/file.h"
|
||||
#include "util/meta/assert.h"
|
||||
|
||||
Dotfile::Dotfile(s)
|
||||
{
|
||||
@@ -107,7 +107,7 @@ void Dotfile::push(const std::vector<std::string>& targets)
|
||||
|
||||
bool Dotfile::match(const std::string& path, const std::vector<std::string>& patterns)
|
||||
{
|
||||
assert(path.front() == '/');
|
||||
VERIFY(path.front() == '/', "path is not absolute: '{}'", path);
|
||||
|
||||
// Cut off working directory
|
||||
size_t cutFrom = path.find(Config::the().workingDirectory()) == 0 ? Config::the().workingDirectorySize() : 0;
|
||||
|
||||
+4
-4
@@ -4,7 +4,6 @@
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
#include <cassert> // assert
|
||||
#include <cstdint> // int32_t
|
||||
#include <filesystem>
|
||||
#include <fstream> // ifstream, ios, ofstream
|
||||
@@ -12,6 +11,7 @@
|
||||
#include <string>
|
||||
|
||||
#include "util/file.h"
|
||||
#include "util/meta/assert.h"
|
||||
|
||||
namespace Util {
|
||||
|
||||
@@ -20,13 +20,13 @@ File::File(const std::string& path)
|
||||
{
|
||||
// Create input stream object and open file
|
||||
std::ifstream file(path, std::ios::in);
|
||||
assert(file.is_open());
|
||||
VERIFY(file.is_open(), "failed to open file: '{}'", path);
|
||||
|
||||
// Get length of the file
|
||||
file.seekg(0, std::ios::end);
|
||||
int32_t size = file.tellg();
|
||||
file.seekg(0, std::ios::beg);
|
||||
assert(size != -1);
|
||||
VERIFY(size != -1, "failed to read file length: '{}', path");
|
||||
|
||||
// Allocate memory filled with zeros
|
||||
auto buffer = std::make_unique<char[]>(size);
|
||||
@@ -78,7 +78,7 @@ File& File::flush()
|
||||
{
|
||||
// Create output stream object and open file
|
||||
std::ofstream file(m_path, std::ios::out | std::ios::trunc);
|
||||
assert(file.is_open());
|
||||
VERIFY(file.is_open(), "failed to open file: '{}'", m_path);
|
||||
|
||||
// Write data to disk
|
||||
file.write(m_data.c_str(), m_data.size());
|
||||
|
||||
@@ -5,13 +5,13 @@
|
||||
*/
|
||||
|
||||
#include <algorithm> // replace
|
||||
#include <cassert> // assert
|
||||
#include <cstddef> // size_t
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
||||
#include "util/format/builder.h"
|
||||
#include "util/format/parser.h"
|
||||
#include "util/meta/assert.h"
|
||||
|
||||
namespace Util::Format {
|
||||
|
||||
@@ -32,8 +32,7 @@ void Parser::checkFormatParameterConsistency()
|
||||
{
|
||||
size_t length = m_input.length();
|
||||
|
||||
// Format string does not reference all passed parameters
|
||||
assert(length >= m_parameterCount * 2);
|
||||
VERIFY(length >= m_parameterCount * 2, "format string does not reference all parameters");
|
||||
|
||||
size_t braceOpen = 0;
|
||||
size_t braceClose = 0;
|
||||
@@ -54,8 +53,7 @@ void Parser::checkFormatParameterConsistency()
|
||||
if (peek0 == '{') {
|
||||
braceOpen++;
|
||||
|
||||
// Only empty references {} or specified references {:} are valid
|
||||
assert(peek1 == '}' || peek1 == ':');
|
||||
VERIFY(peek1 == '}' || peek1 == ':', "invalid parameter reference");
|
||||
}
|
||||
if (peek0 == '}') {
|
||||
braceClose++;
|
||||
@@ -65,17 +63,13 @@ void Parser::checkFormatParameterConsistency()
|
||||
}
|
||||
m_index = 0;
|
||||
|
||||
// Extra open braces in format string
|
||||
assert(!(braceOpen < braceClose));
|
||||
VERIFY(!(braceOpen < braceClose), "extra open braces in format string");
|
||||
|
||||
// Extra closing braces in format string
|
||||
assert(!(braceOpen > braceClose));
|
||||
VERIFY(!(braceOpen > braceClose), "extra closing braces in format string");
|
||||
|
||||
// Format string does not reference all passed parameters
|
||||
assert(!(braceOpen < m_parameterCount));
|
||||
VERIFY(!(braceOpen < m_parameterCount), "format string does not reference all passed parameters");
|
||||
|
||||
// Format string references nonexistent parameter
|
||||
assert(!(braceOpen > m_parameterCount));
|
||||
VERIFY(!(braceOpen > m_parameterCount), "format string references nonexistent parameter");
|
||||
}
|
||||
|
||||
std::string_view Parser::consumeLiteral()
|
||||
@@ -114,7 +108,7 @@ bool Parser::consumeSpecifier(std::string_view& specifier)
|
||||
}
|
||||
|
||||
if (!consumeSpecific(':')) {
|
||||
assert(consumeSpecific('}'));
|
||||
VERIFY(consumeSpecific('}'), "invalid parameter reference");
|
||||
specifier = "";
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include <algorithm> // max, min
|
||||
|
||||
#include "util/genericlexer.h"
|
||||
#include "util/meta/assert.h"
|
||||
|
||||
namespace Util {
|
||||
|
||||
@@ -53,7 +54,7 @@ void GenericLexer::retreat(size_t count)
|
||||
|
||||
char GenericLexer::consume()
|
||||
{
|
||||
assert(!isEOF());
|
||||
VERIFY(!isEOF());
|
||||
return m_input[m_index++];
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cassert> // assert
|
||||
#include <cstddef> // size_t
|
||||
#include <string_view>
|
||||
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <algorithm> // transform
|
||||
#include <cassert> // assert
|
||||
#include <cstddef> // nullptr_t
|
||||
#include <map>
|
||||
#include <string>
|
||||
@@ -17,6 +16,7 @@
|
||||
|
||||
#include "util/json/array.h"
|
||||
#include "util/json/object.h"
|
||||
#include "util/meta/assert.h"
|
||||
#include "util/meta/odr.h"
|
||||
|
||||
namespace Util::JSON {
|
||||
@@ -33,42 +33,42 @@ void fromJson(const Json& json, Json& value)
|
||||
template<typename Json>
|
||||
void fromJson(const Json& json, std::nullptr_t& null)
|
||||
{
|
||||
assert(json.type() == Json::Type::Null);
|
||||
VERIFY(json.type() == Json::Type::Null);
|
||||
null = nullptr;
|
||||
}
|
||||
|
||||
template<typename Json>
|
||||
void fromJson(const Json& json, bool& boolean)
|
||||
{
|
||||
assert(json.type() == Json::Type::Bool);
|
||||
VERIFY(json.type() == Json::Type::Bool);
|
||||
boolean = json.asBool();
|
||||
}
|
||||
|
||||
template<typename Json>
|
||||
void fromJson(const Json& json, int& number)
|
||||
{
|
||||
assert(json.type() == Json::Type::Number);
|
||||
VERIFY(json.type() == Json::Type::Number);
|
||||
number = (int)json.asDouble();
|
||||
}
|
||||
|
||||
template<typename Json>
|
||||
void fromJson(const Json& json, double& number)
|
||||
{
|
||||
assert(json.type() == Json::Type::Number);
|
||||
VERIFY(json.type() == Json::Type::Number);
|
||||
number = json.asDouble();
|
||||
}
|
||||
|
||||
template<typename Json>
|
||||
void fromJson(const Json& json, std::string& string)
|
||||
{
|
||||
assert(json.type() == Json::Type::String);
|
||||
VERIFY(json.type() == Json::Type::String);
|
||||
string = json.asString();
|
||||
}
|
||||
|
||||
template<typename Json, typename T>
|
||||
void fromJson(const Json& json, std::vector<T>& array)
|
||||
{
|
||||
assert(json.type() == Json::Type::Array);
|
||||
VERIFY(json.type() == Json::Type::Array);
|
||||
array.resize(json.size());
|
||||
std::transform(
|
||||
json.asArray().elements().begin(),
|
||||
@@ -82,7 +82,7 @@ void fromJson(const Json& json, std::vector<T>& array)
|
||||
template<typename Json, typename T>
|
||||
void fromJson(const Json& json, std::map<std::string, T>& object)
|
||||
{
|
||||
assert(json.type() == Json::Type::Object);
|
||||
VERIFY(json.type() == Json::Type::Object);
|
||||
object.clear();
|
||||
for (const auto& [name, value] : json.asObject().members()) {
|
||||
object.emplace(name, value.template get<T>());
|
||||
@@ -92,7 +92,7 @@ void fromJson(const Json& json, std::map<std::string, T>& object)
|
||||
template<typename Json, typename T>
|
||||
void fromJson(const Json& json, std::unordered_map<std::string, T>& object)
|
||||
{
|
||||
assert(json.type() == Json::Type::Object);
|
||||
VERIFY(json.type() == Json::Type::Object);
|
||||
object.clear();
|
||||
for (const auto& [name, value] : json.asObject().members()) {
|
||||
object.emplace(name, value.template get<T>());
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
#include "util/json/object.h"
|
||||
#include "util/json/parser.h"
|
||||
#include "util/json/value.h"
|
||||
#include "util/meta/assert.h"
|
||||
|
||||
namespace Util::JSON {
|
||||
|
||||
@@ -88,13 +89,13 @@ bool Parser::isEOF()
|
||||
|
||||
Token Parser::peek()
|
||||
{
|
||||
assert(!isEOF());
|
||||
VERIFY(!isEOF());
|
||||
return (*m_tokens)[m_index];
|
||||
}
|
||||
|
||||
Token Parser::consume()
|
||||
{
|
||||
assert(!isEOF());
|
||||
VERIFY(!isEOF());
|
||||
return (*m_tokens)[m_index++];
|
||||
}
|
||||
|
||||
|
||||
+12
-12
@@ -5,7 +5,6 @@
|
||||
*/
|
||||
|
||||
#include <algorithm> // all_of
|
||||
#include <cassert> // assert
|
||||
#include <cstdint> // uint32_t
|
||||
#include <fstream> // >>
|
||||
#include <iostream> // istream, ostream
|
||||
@@ -18,6 +17,7 @@
|
||||
#include "util/json/object.h"
|
||||
#include "util/json/serializer.h"
|
||||
#include "util/json/value.h"
|
||||
#include "util/meta/assert.h"
|
||||
|
||||
namespace Util::JSON {
|
||||
|
||||
@@ -180,7 +180,7 @@ void Value::emplace_back(Value value)
|
||||
m_value.array = new Array;
|
||||
}
|
||||
|
||||
assert(m_type == Type::Array);
|
||||
VERIFY(m_type == Type::Array);
|
||||
m_value.array->emplace_back(value);
|
||||
}
|
||||
|
||||
@@ -192,7 +192,7 @@ void Value::emplace(const std::string& key, Value value)
|
||||
m_value.object = new Object;
|
||||
}
|
||||
|
||||
assert(m_type == Type::Object);
|
||||
VERIFY(m_type == Type::Object);
|
||||
m_value.object->emplace(key, value);
|
||||
}
|
||||
|
||||
@@ -203,7 +203,7 @@ bool Value::exists(size_t index) const
|
||||
|
||||
bool Value::exists(const std::string& key) const
|
||||
{
|
||||
assert(m_type == Type::Object);
|
||||
VERIFY(m_type == Type::Object);
|
||||
return m_value.object->members().find(key) != m_value.object->members().end();
|
||||
}
|
||||
|
||||
@@ -217,7 +217,7 @@ Value& Value::operator[](size_t index)
|
||||
m_value.array = new Array;
|
||||
}
|
||||
|
||||
assert(m_type == Type::Array);
|
||||
VERIFY(m_type == Type::Array);
|
||||
return (*m_value.array)[index];
|
||||
}
|
||||
|
||||
@@ -229,43 +229,43 @@ Value& Value::operator[](const std::string& key)
|
||||
m_value.object = new Object;
|
||||
}
|
||||
|
||||
assert(m_type == Type::Object);
|
||||
VERIFY(m_type == Type::Object);
|
||||
return (*m_value.object)[key];
|
||||
}
|
||||
|
||||
const Value& Value::operator[](size_t index) const
|
||||
{
|
||||
assert(m_type == Type::Array);
|
||||
VERIFY(m_type == Type::Array);
|
||||
return (*m_value.array)[index];
|
||||
}
|
||||
|
||||
const Value& Value::operator[](const std::string& key) const
|
||||
{
|
||||
assert(m_type == Type::Object);
|
||||
VERIFY(m_type == Type::Object);
|
||||
return (*m_value.object)[key];
|
||||
}
|
||||
|
||||
Value& Value::at(size_t index)
|
||||
{
|
||||
assert(m_type == Type::Array);
|
||||
VERIFY(m_type == Type::Array);
|
||||
return m_value.array->at(index);
|
||||
}
|
||||
|
||||
Value& Value::at(const std::string& key)
|
||||
{
|
||||
assert(m_type == Type::Object);
|
||||
VERIFY(m_type == Type::Object);
|
||||
return m_value.object->at(key);
|
||||
}
|
||||
|
||||
const Value& Value::at(size_t index) const
|
||||
{
|
||||
assert(m_type == Type::Array);
|
||||
VERIFY(m_type == Type::Array);
|
||||
return m_value.array->at(index);
|
||||
}
|
||||
|
||||
const Value& Value::at(const std::string& key) const
|
||||
{
|
||||
assert(m_type == Type::Object);
|
||||
VERIFY(m_type == Type::Object);
|
||||
return m_value.object->at(key);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user