Tests
This commit is contained in:
parent
08eccd2a35
commit
4dbd55fbed
5
.gitignore
vendored
5
.gitignore
vendored
@ -4,6 +4,9 @@
|
|||||||
# Output binaries and folders
|
# Output binaries and folders
|
||||||
/output/
|
/output/
|
||||||
|
|
||||||
|
# test folder
|
||||||
|
/test/
|
||||||
|
|
||||||
# CMake files
|
# CMake files
|
||||||
CMakeFiles/
|
CMakeFiles/
|
||||||
CMakeCache.txt
|
CMakeCache.txt
|
||||||
@ -26,4 +29,4 @@ Makefile
|
|||||||
*.out
|
*.out
|
||||||
|
|
||||||
# Generated recreator files (optional, if you want to ignore them)
|
# Generated recreator files (optional, if you want to ignore them)
|
||||||
_*.[ch]pp
|
_*.[ch]pp
|
||||||
|
Binary file not shown.
@ -118,7 +118,28 @@ void generate_folder_code(const std::string& source, const std::string& destfold
|
|||||||
walk_dir(src, [&](const fs::path& p) { files.push_back(p); });
|
walk_dir(src, [&](const fs::path& p) { files.push_back(p); });
|
||||||
// Write HPP
|
// Write HPP
|
||||||
std::ofstream hpp(dest / hppname);
|
std::ofstream hpp(dest / hppname);
|
||||||
hpp << "#pragma once\n#include <string>\nnamespace " << ns << " {\nbool recreate_tree(std::string destination_folder);\n}\n";
|
|
||||||
|
// -------------------------------------------------------------------------
|
||||||
|
// Generate HPP
|
||||||
|
hpp << R"hpp(
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
|
THIS FILE IS AUTO-GENERATED BY DEHYDRATE.
|
||||||
|
DO NOT EDIT THIS FILE.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
namespace )hpp" << ns << R"hpp( {
|
||||||
|
bool recreate_tree(std::string destination_folder);
|
||||||
|
}
|
||||||
|
)hpp";
|
||||||
|
|
||||||
|
|
||||||
|
// -------------------------------------------------------------------------
|
||||||
// Write CPP
|
// Write CPP
|
||||||
std::ofstream cpp(dest / cppname);
|
std::ofstream cpp(dest / cppname);
|
||||||
cpp << R"cpp(#include <fstream>
|
cpp << R"cpp(#include <fstream>
|
||||||
@ -126,9 +147,34 @@ void generate_folder_code(const std::string& source, const std::string& destfold
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
|
THIS FILE IS AUTO-GENERATED BY DEHYDRATE.
|
||||||
|
DO NOT EDIT THIS FILE.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
)cpp";
|
)cpp";
|
||||||
cpp << "#include \"" << hppname << "\"\n";
|
cpp << "#include \"" << hppname << "\"\n";
|
||||||
cpp << "namespace " << ns << " {\n";
|
cpp << "namespace " << ns << " {\n";
|
||||||
|
|
||||||
|
cpp << R"cpp(
|
||||||
|
|
||||||
|
// Tiny dependency-free FNV-1a 64-bit hash
|
||||||
|
static uint64_t fnv1a_64(const void* data, size_t len) {
|
||||||
|
const uint8_t* p = static_cast<const uint8_t*>(data);
|
||||||
|
uint64_t h = 0xcbf29ce484222325ULL;
|
||||||
|
for (size_t i = 0; i < len; ++i)
|
||||||
|
h = (h ^ p[i]) * 0x100000001b3ULL;
|
||||||
|
return h;
|
||||||
|
}
|
||||||
|
|
||||||
|
)cpp";
|
||||||
|
|
||||||
// Embed all files
|
// Embed all files
|
||||||
for (const auto& file : files) {
|
for (const auto& file : files) {
|
||||||
std::ifstream in(file, std::ios::binary);
|
std::ifstream in(file, std::ios::binary);
|
||||||
|
34
test.sh
Executable file
34
test.sh
Executable file
@ -0,0 +1,34 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
set -e
|
||||||
|
|
||||||
|
SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
|
||||||
|
|
||||||
|
TEST_DIR="$SCRIPT_DIR/test"
|
||||||
|
|
||||||
|
rm -rf $TEST_DIR
|
||||||
|
mkdir $TEST_DIR
|
||||||
|
|
||||||
|
#"$SCRIPT_DIR/build.sh"
|
||||||
|
|
||||||
|
"$SCRIPT_DIR/output/dehydrate.amd64" src $TEST_DIR
|
||||||
|
|
||||||
|
cat <<EOF > test/main.cpp
|
||||||
|
#include "_src.hpp"
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <filesystem>
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
// get the current path to this executable
|
||||||
|
std::filesystem::path exepath= std::filesystem::canonical("/proc/self/exe");
|
||||||
|
recreate_src::recreate_tree(exepath.parent_path().string()+"/temp");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
EOF
|
||||||
|
|
||||||
|
g++ -std=c++17 -I $TEST_DIR -o $TEST_DIR/testexe $TEST_DIR/main.cpp $TEST_DIR/_src.cpp
|
||||||
|
|
||||||
|
$TEST_DIR/testexe
|
||||||
|
|
||||||
|
$TEST_DIR/testexe
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user