<commit_before>#include "blob_mock.hpp"
#include "dlsys_mock.hpp"
#include "fs.hpp"
#include "manager_mock.hpp"
#include "utils.hpp"

#include <filesystem>
#include <memory>
#include <string>
#include <vector>

#include <gtest/gtest.h>

namespace fs = std::filesystem;

namespace blobs
{
using ::testing::_;
using ::testing::Return;
using ::testing::StrEq;
using ::testing::StrictMock;

std::vector<std::string>* returnList = nullptr;

std::vector<std::string> getLibraryList(const std::string& path,
                                        PathMatcher check)
{
    return (returnList) ? *returnList : std::vector<std::string>();
}

std::unique_ptr<GenericBlobInterface> factoryReturn;

std::unique_ptr<GenericBlobInterface> fakeFactory()
{
    return std::move(factoryReturn);
}

TEST(UtilLoadLibraryTest, NoFilesFound)
{
    /* Verify nothing special happens when there are no files found. */

    StrictMock<internal::InternalDlSysMock> dlsys;
    StrictMock<ManagerMock> manager;

    loadLibraries(&manager, "", &dlsys);
}

TEST(UtilLoadLibraryTest, OneFileFoundIsLibrary)
{
    /* Verify if it finds a library, and everything works, it'll regsiter it.
     */

    std::vector<std::string> files = {"this.fake"};
    returnList = &files;

    StrictMock<internal::InternalDlSysMock> dlsys;
    StrictMock<ManagerMock> manager;
    void* handle = reinterpret_cast<void*>(0x01);
    auto blobMock = std::make_unique<BlobMock>();
<commit_msg>test/utils: stop using local variable with global return<commit_after>#include "blob_mock.hpp"
#include "dlsys_mock.hpp"
#include "fs.hpp"
#include "manager_mock.hpp"
#include "utils.hpp"

#include <filesystem>
#include <memory>
#include <string>
#include <vector>

#include <gmock/gmock.h>
#include <gtest/gtest.h>

namespace fs = std::filesystem;

namespace blobs
{
using ::testing::_;
using ::testing::Return;
using ::testing::StrEq;
using ::testing::StrictMock;

std::vector<std::string> returnList;

std::vector<std::string> getLibraryList(const std::string& path,
                                        PathMatcher check)
{
    return returnList;
}

std::unique_ptr<GenericBlobInterface> factoryReturn;

std::unique_ptr<GenericBlobInterface> fakeFactory()
{
    return std::move(factoryReturn);
}

class UtilLoadLibraryTest : public ::testing::Test
{
  protected:
    UtilLoadLibraryTest()
    {
        returnList = {};
    }
};

TEST_F(UtilLoadLibraryTest, NoFilesFound)
{
    /* Verify nothing special happens when there are no files found. */

    StrictMock<internal::InternalDlSysMock> dlsys;
    StrictMock<ManagerMock> manager;

    loadLibraries(&manager, "", &dlsys);
}

TEST_F(UtilLoadLibraryTest, OneFileFoundIsLibrary)
{
    /* Verify if it finds a library, and everything works, it'll regsiter it.
     */

    returnList = {"this.fake"};

    StrictMock<internal::InternalDlSysMock> dlsys;
    StrictMock<ManagerMock> manager;
    void* handle = reinterpret_cast<void*>(0x01);
    auto blobMock = std::make_unique<BlobMock>();

{'fraction_non_alphanumeric': 0.13293253173012692, 'fraction_numerical': 0.002004008016032064, 'mean_word_length': 4.693916349809886, 'pattern_counts': {'":': 0, '<': 36, '<?xml version=': 0, '>': 36, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '627044', 'n_tokens_mistral': 957, 'n_tokens_neox': 946, 'n_words': 208}