<commit_before>// Copyright (C) 2016 xaizek <<EMAIL>>
//
// This file is part of uncov.
//
// uncov is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// uncov is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with uncov.  If not, see <http://www.gnu.org/licenses/>.

#include "TestUtils.hpp"

#include <boost/filesystem/operations.hpp>

#include "Settings.hpp"

namespace fs = boost::filesystem;

static void copyDir(const fs::path &src, const fs::path &dst);

TempDirCopy::TempDirCopy(const std::string &from, const std::string &to,
                         bool force)
    : to(to)
{
    if (force) {
        fs::remove_all(to);
    }
    copyDir(from, to);
}

static void
copyDir(const fs::path &src, const fs::path &dst)
{
    fs::create_directory(dst);
    for (fs::directory_entry &e : fs::directory_iterator(src)) {
        fs::path path = e.path();
        if (fs::is_directory(path)) {
            copyDir(path, dst/path.filename());
        } else {
            fs::copy_file(path, dst/path.filename());
        }
    }
}

TempDirCopy::~TempDirCopy()
{
    try {
        fs::remove_all(to);
    } catch (...) {
        // Don't throw from the destructor.
    }
}

FileRestorer::FileRestorer(const std::string &from, const std::string &to)<commit_msg>Fix compiling tests against Boost 1.55<commit_after>// Copyright (C) 2016 xaizek <<EMAIL>>
//
// This file is part of uncov.
//
// uncov is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// uncov is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with uncov.  If not, see <http://www.gnu.org/licenses/>.

#include "TestUtils.hpp"

#include <boost/filesystem/operations.hpp>
#include <boost/range.hpp>

#include "Settings.hpp"

namespace fs = boost::filesystem;

static void copyDir(const fs::path &src, const fs::path &dst);

TempDirCopy::TempDirCopy(const std::string &from, const std::string &to,
                         bool force)
    : to(to)
{
    if (force) {
        fs::remove_all(to);
    }
    copyDir(from, to);
}

static void
copyDir(const fs::path &src, const fs::path &dst)
{
    using it = fs::directory_iterator;

    fs::create_directory(dst);
    for (fs::directory_entry &e : boost::make_iterator_range(it(src), it())) {
        fs::path path = e.path();
        if (fs::is_directory(path)) {
            copyDir(path, dst/path.filename());
        } else {
            fs::copy_file(path, dst/path.filename());
        }
    }
}

TempDirCopy::~TempDirCopy()
{
    try {
        fs::remove_all(to);
    } catch (...) {
        // Don't throw from the destructor.
    }
}

FileRestorer::FileRestorer(const std::string &from, const std::string &to)
{'fraction_non_alphanumeric': 0.12864349775784753, 'fraction_numerical': 0.0036434977578475337, 'mean_word_length': 3.005611672278339, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1735424', 'n_tokens_mistral': 1092, 'n_tokens_neox': 1071, 'n_words': 370}