aboutsummaryrefslogtreecommitdiff
path: root/tests/src/confTest/confTest.cpp
blob: e508e84efb3c5e24efc0d1f6cf79e21149d9cc5a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include "catch2/2.0.1/catch.hpp"
#include "../../../include/Conf.hpp"

using namespace sibs;

TEST_CASE("parse config")
{
	SibsConfig sibsConfig(Compiler::GCC, TINYDIR_STRING("tests/src/confTest"));
    Result<bool> result = Config::readFromFile(TINYDIR_STRING("tests/src/confTest/validProject.conf"), sibsConfig);
    if(result.isErr())
    {
        fprintf(stderr, "%s", result.getErrMsg().c_str());
        exit(1);
    }
    REQUIRE(sibsConfig.getPackageName() == "confTest");
    REQUIRE(sibsConfig.getPackageType() == PackageType::LIBRARY);
    
    REQUIRE(sibsConfig.getPlatforms().size() == 2);
    REQUIRE(containsPlatform(sibsConfig.getPlatforms(), PLATFORM_LINUX64));
    REQUIRE(containsPlatform(sibsConfig.getPlatforms(), PLATFORM_WIN64));
    
    REQUIRE(sibsConfig.getDependencies().size() == 2);
    const auto &xxhashDependency = sibsConfig.getDependencies()[0];
    REQUIRE(xxhashDependency.name == "xxhash");
    REQUIRE(xxhashDependency.version == "0.1.0");
    
    const auto &catch2Dependency = sibsConfig.getDependencies()[1];
    REQUIRE(catch2Dependency.name == "catch2");
    REQUIRE(catch2Dependency.version == "1.0.0");
    
    REQUIRE(sibsConfig.shouldUseCmake());
    
    REQUIRE(sibsConfig.getCmakeDir() == TINYDIR_STRING("tests/src/confTest/cmakeGlobal"));
    REQUIRE(sibsConfig.getCmakeArgs() == "\"-DCMAKE_BUILD_TYPE=Debug\" \"-DENTITYX_RUN_BENCHMARKS=0\"");
    
    REQUIRE(sibsConfig.getCmakeDirStatic() == TINYDIR_STRING("tests/src/confTest/cmakeStatic"));
    REQUIRE(sibsConfig.getCmakeArgsStatic() == "\"-DCMAKE_BUILD_TYPE=Debug\" \"-DENTITYX_RUN_BENCHMARKS=0\" \"-DENTITYX_BUILD_TESTING=0\"");
    
    REQUIRE(sibsConfig.getCmakeDirDynamic() == TINYDIR_STRING("tests/src/confTest/cmakeDynamic"));
    REQUIRE(sibsConfig.getCmakeArgsDynamic() == "\"-DCMAKE_BUILD_TYPE=Debug\" \"-DENTITYX_RUN_BENCHMARKS=0\" \"-DENTITYX_BUILD_TESTING=0\" \"-DENTITYX_BUILD_SHARED=1\"");
}

TEST_CASE("parse config - invalid object")
{
	SibsConfig sibsConfig(Compiler::GCC, TINYDIR_STRING("tests/src/confTest"));
    Result<bool> result = Config::readFromFile(TINYDIR_STRING("tests/src/confTest/invalidObject.conf"), sibsConfig);
    REQUIRE(result.isErr());
    REQUIRE(result.getErrMsg() == "Invalid config object \"invalidObj\"");
}

TEST_CASE("parse config - invalid field")
{
	SibsConfig sibsConfig(Compiler::GCC, TINYDIR_STRING("tests/src/confTest"));
    Result<bool> result = Config::readFromFile(TINYDIR_STRING("tests/src/confTest/invalidField.conf"), sibsConfig);
    REQUIRE(result.isErr());
    REQUIRE(result.getErrMsg() == "Invalid field \"invalidField\" under object \"package\"");
}