mirror of
https://github.com/davidallendj/gdpm.git
synced 2025-12-20 03:27:02 -07:00
Fixed bugs and issues with linking tests
This commit is contained in:
parent
65be8090d3
commit
d4b1ea90c6
11 changed files with 27 additions and 21 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
|
@ -3,7 +3,8 @@ builds/**
|
||||||
bin/gdpm
|
bin/gdpm
|
||||||
bin/gdpm-tests
|
bin/gdpm-tests
|
||||||
cache/**
|
cache/**
|
||||||
tests
|
tests/*
|
||||||
|
!tests/*.cpp
|
||||||
*/tmp/**
|
*/tmp/**
|
||||||
vgcore.*
|
vgcore.*
|
||||||
.cache
|
.cache
|
||||||
|
|
|
||||||
|
|
@ -61,7 +61,7 @@ target_include_directories(${PROJECT_NAME}-tests PRIVATE ${INCLUDE_DIRS})
|
||||||
target_link_libraries(${PROJECT_NAME} PRIVATE ${PROJECT_NAME}-shared ${LINK_LIBS})
|
target_link_libraries(${PROJECT_NAME} PRIVATE ${PROJECT_NAME}-shared ${LINK_LIBS})
|
||||||
target_link_libraries(${PROJECT_NAME}-shared PRIVATE ${LINK_LIBS})
|
target_link_libraries(${PROJECT_NAME}-shared PRIVATE ${LINK_LIBS})
|
||||||
target_link_libraries(${PROJECT_NAME}-static PRIVATE ${LINK_LIBS})
|
target_link_libraries(${PROJECT_NAME}-static PRIVATE ${LINK_LIBS})
|
||||||
target_link_libraries(${PROJECT_NAME}-tests PRIVATE ${LINK_LIBS})
|
target_link_libraries(${PROJECT_NAME}-tests PRIVATE ${PROJECT_NAME}-shared ${LINK_LIBS})
|
||||||
|
|
||||||
# Add project unit tests
|
# Add project unit tests
|
||||||
# add_custom_target("${PROJECT_NAME}-tests" SOURCE ${TESTS})
|
# add_custom_target("${PROJECT_NAME}-tests" SOURCE ${TESTS})
|
||||||
|
|
|
||||||
|
|
@ -12,5 +12,6 @@ cmake -B build -S . -DCMAKE_EXPORT_COMPILE_COMMANDS=1 -G Ninja
|
||||||
ninja -C build
|
ninja -C build
|
||||||
|
|
||||||
# Create symlinks to executables in build folder if necessary
|
# Create symlinks to executables in build folder if necessary
|
||||||
|
rm bin/gdpm bin/gdpm-tests
|
||||||
ln -s ../build/gdpm bin/gdpm
|
ln -s ../build/gdpm bin/gdpm
|
||||||
ln -s ../build/gdpm-tests bin/gdpm-tests
|
ln -s ../build/gdpm-tests bin/gdpm-tests
|
||||||
|
|
@ -1,2 +1,4 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
# Call this from project root
|
# Call this from project root
|
||||||
wc -l include/*.hpp src/*.cpp
|
wc -l include/*.hpp src/*.cpp
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
#!/bin/bash
|
||||||
command=build/gdpm
|
command=build/gdpm
|
||||||
|
|
||||||
# Install packages using install command and specifying each package name or file
|
# Install packages using install command and specifying each package name or file
|
||||||
|
|
|
||||||
|
|
@ -26,8 +26,7 @@ namespace gdpm::config{
|
||||||
int verbose;
|
int verbose;
|
||||||
};
|
};
|
||||||
std::string to_json(const context& params);
|
std::string to_json(const context& params);
|
||||||
context load(std::filesystem::path path, int verbose = 0);
|
gdpm::error load(std::filesystem::path path, context& config, int verbose = 0);
|
||||||
gdpm::error load(std::filesystem:: path, context& config, int verbose = 0);
|
|
||||||
gdpm::error save(std::filesystem::path path, const context& config, int verbose = 0);
|
gdpm::error save(std::filesystem::path path, const context& config, int verbose = 0);
|
||||||
context make_context(const std::string& username = GDPM_CONFIG_USERNAME, const std::string& password = GDPM_CONFIG_PASSWORD, const std::string& path = GDPM_CONFIG_PATH, const std::string& token = GDPM_CONFIG_TOKEN, const std::string& godot_version = GDPM_CONFIG_GODOT_VERSION, const std::string& packages_dir = GDPM_CONFIG_LOCAL_PACKAGES_DIR, const std::string& tmp_dir = GDPM_CONFIG_LOCAL_TMP_DIR, const std::set<std::string>& remote_sources = {GDPM_CONFIG_REMOTE_SOURCES}, size_t threads = GDPM_CONFIG_THREADS, size_t timeout = 0, bool enable_sync = GDPM_CONFIG_ENABLE_SYNC, bool enable_file_logging = GDPM_CONFIG_ENABLE_FILE_LOGGING, int verbose = GDPM_CONFIG_VERBOSE);
|
context make_context(const std::string& username = GDPM_CONFIG_USERNAME, const std::string& password = GDPM_CONFIG_PASSWORD, const std::string& path = GDPM_CONFIG_PATH, const std::string& token = GDPM_CONFIG_TOKEN, const std::string& godot_version = GDPM_CONFIG_GODOT_VERSION, const std::string& packages_dir = GDPM_CONFIG_LOCAL_PACKAGES_DIR, const std::string& tmp_dir = GDPM_CONFIG_LOCAL_TMP_DIR, const std::set<std::string>& remote_sources = {GDPM_CONFIG_REMOTE_SOURCES}, size_t threads = GDPM_CONFIG_THREADS, size_t timeout = 0, bool enable_sync = GDPM_CONFIG_ENABLE_SYNC, bool enable_file_logging = GDPM_CONFIG_ENABLE_FILE_LOGGING, int verbose = GDPM_CONFIG_VERBOSE);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
namespace gdpm::constants{
|
namespace gdpm::constants{
|
||||||
const std::string HomePath(std::string(std::getenv("HOME")) + "/");
|
const std::string HomePath(std::string(std::getenv("HOME")) + "/");
|
||||||
const std::string TestPath(HomePath + ".config/gdpm/tests")
|
const std::string TestPath(HomePath + ".config/gdpm/tests");
|
||||||
const std::string ConfigPath(HomePath + ".config/gdpm/config.json");
|
const std::string ConfigPath(HomePath + ".config/gdpm/config.json");
|
||||||
const std::string LockfilePath(HomePath + ".config/gdpm/gdpm.lck");
|
const std::string LockfilePath(HomePath + ".config/gdpm/gdpm.lck");
|
||||||
const std::string LocalPackagesDir(HomePath + ".config/gdpm/packages");
|
const std::string LocalPackagesDir(HomePath + ".config/gdpm/packages");
|
||||||
|
|
|
||||||
|
|
@ -5,12 +5,12 @@
|
||||||
namespace gdpm{
|
namespace gdpm{
|
||||||
class error{
|
class error{
|
||||||
public:
|
public:
|
||||||
error(int code, const std::string& message):
|
error(int code = 0, const std::string& message = ""):
|
||||||
m_code(code), m_message(message)
|
m_code(code), m_message(message)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int m_code;
|
int m_code;
|
||||||
std::string m_message;
|
std::string m_message;
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
|
|
@ -58,15 +58,17 @@ namespace gdpm::config{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
context load(std::filesystem::path path, int verbose){
|
gdpm::error load(std::filesystem::path path, context& config, int verbose){
|
||||||
std::fstream file;
|
std::fstream file;
|
||||||
|
gdpm::error error;
|
||||||
file.open(path, std::ios::in);
|
file.open(path, std::ios::in);
|
||||||
if(!file){
|
if(!file){
|
||||||
if(verbose){
|
if(verbose){
|
||||||
log::info("No configuration file found. Creating a new one.");
|
log::info("No configuration file found. Creating a new one.");
|
||||||
save(make_context(), verbose);
|
config = make_context();
|
||||||
|
save(config.path, config, verbose);
|
||||||
}
|
}
|
||||||
return config;
|
return error;
|
||||||
}
|
}
|
||||||
else if(file.is_open()){
|
else if(file.is_open()){
|
||||||
/*
|
/*
|
||||||
|
|
@ -89,7 +91,7 @@ namespace gdpm::config{
|
||||||
|
|
||||||
if(!doc.IsObject()){
|
if(!doc.IsObject()){
|
||||||
log::error("Could not load config file.");
|
log::error("Could not load config file.");
|
||||||
return config;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(doc.IsObject());
|
assert(doc.IsObject());
|
||||||
|
|
@ -139,11 +141,11 @@ namespace gdpm::config{
|
||||||
config.enable_sync = _get_value_int(doc, "enable_sync");
|
config.enable_sync = _get_value_int(doc, "enable_sync");
|
||||||
config.enable_file_logging = _get_value_int(doc, "enable_file_logging");
|
config.enable_file_logging = _get_value_int(doc, "enable_file_logging");
|
||||||
}
|
}
|
||||||
return config;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int save(std::filesystem::path path, const context& config, int verbose){
|
gdpm::error save(std::filesystem::path path, const context& config, int verbose){
|
||||||
using namespace rapidjson;
|
using namespace rapidjson;
|
||||||
|
|
||||||
/* Build a JSON string to pass to document */
|
/* Build a JSON string to pass to document */
|
||||||
|
|
@ -160,7 +162,7 @@ namespace gdpm::config{
|
||||||
PrettyWriter<OStreamWrapper> writer(osw);
|
PrettyWriter<OStreamWrapper> writer(osw);
|
||||||
doc.Accept(writer);
|
doc.Accept(writer);
|
||||||
|
|
||||||
return 0;
|
return gdpm::error();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -52,9 +52,9 @@ namespace gdpm::package_manager{
|
||||||
|
|
||||||
/* Check for config and create if not exists */
|
/* Check for config and create if not exists */
|
||||||
if(!std::filesystem::exists(config.path)){
|
if(!std::filesystem::exists(config.path)){
|
||||||
config::save(config);
|
config::save(config.path, config);
|
||||||
}
|
}
|
||||||
config = config::load(config.path);
|
config::load(config.path, config);
|
||||||
config.enable_sync = true;
|
config.enable_sync = true;
|
||||||
std::string json = to_json(config);
|
std::string json = to_json(config);
|
||||||
|
|
||||||
|
|
@ -78,7 +78,7 @@ namespace gdpm::package_manager{
|
||||||
|
|
||||||
void finalize(){
|
void finalize(){
|
||||||
curl_easy_cleanup(curl);
|
curl_easy_cleanup(curl);
|
||||||
config::save(config);
|
config::save(config.path, config);
|
||||||
// curl_global_cleanup();
|
// curl_global_cleanup();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -622,7 +622,7 @@ namespace gdpm::package_manager{
|
||||||
/* Set option variables first to be used in functions below. */
|
/* Set option variables first to be used in functions below. */
|
||||||
if(result.count("config")){
|
if(result.count("config")){
|
||||||
config.path = result["config"].as<std::string>();
|
config.path = result["config"].as<std::string>();
|
||||||
config = config::load(config.path);
|
config::load(config.path, config);
|
||||||
log::info("Config: {}", config.path);
|
log::info("Config: {}", config.path);
|
||||||
}
|
}
|
||||||
if(result.count("add-remote")){
|
if(result.count("add-remote")){
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ TEST_CASE("Confirm doctest unit testing"){
|
||||||
|
|
||||||
|
|
||||||
TEST_CASE("Test cache database functions"){
|
TEST_CASE("Test cache database functions"){
|
||||||
gdpm::cache::create_package_database()
|
gdpm::cache::create_package_database();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -24,6 +24,6 @@ TEST_CASE("Test configuration functions"){
|
||||||
config.path = gdpm::constants::TestPath + "/";
|
config.path = gdpm::constants::TestPath + "/";
|
||||||
|
|
||||||
std::string json = gdpm::config::to_json(config);
|
std::string json = gdpm::config::to_json(config);
|
||||||
int status = gdpm::config::save(config);
|
gdpm::error error_save = gdpm::config::save(config.path, config);
|
||||||
gdpm::config::context new_config = gdpm::config::load(config.path, config)
|
gdpm::error error_load = gdpm::config::load(config.path, config);
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue