Skip to content

Commit

Permalink
Improve adding RapidJSON include dirs to tests
Browse files Browse the repository at this point in the history
* Also check for `RapidJSON_INCLUDE_DIRS` which seems to be used now
* Do not add `-I` without subsequent path if the include directory
  is missing/empty which would lead to the Clang error:
  `error: unable to handle compilation, expected exactly one compiler job in ''`
  • Loading branch information
Martchus committed Aug 9, 2019
1 parent f21f255 commit fecde7d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
8 changes: 7 additions & 1 deletion generator/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,13 @@ endif ()
# add paths for include dirs of c++utilities and RapidJSON to config header so test cases can use it
set(META_CUSTOM_CONFIG "#define CPP_UTILITIES_INCLUDE_DIRS \"${CPP_UTILITIES_INCLUDE_DIRS}\"\n")
if (RapidJSON_FOUND)
string(APPEND META_CUSTOM_CONFIG "#define RAPIDJSON_INCLUDE_DIRS \"${RAPIDJSON_INCLUDE_DIRS}\"\n")
# add include dirs either from RapidJSON_INCLUDE_DIRS or RAPIDJSON_INCLUDE_DIRS
if (RapidJSON_INCLUDE_DIRS)
set(RAPIDJSON_INCLUDE_DIRS ${RapidJSON_INCLUDE_DIRS})
endif ()
if (RAPIDJSON_INCLUDE_DIRS)
string(APPEND META_CUSTOM_CONFIG "#define RAPIDJSON_INCLUDE_DIRS \"${RAPIDJSON_INCLUDE_DIRS}\"\n")
endif ()
endif ()

# add path of Clang's resource dir to config header so test cases can use it
Expand Down
16 changes: 11 additions & 5 deletions generator/tests/jsongenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,11 @@ void JsonGeneratorTests::testGeneratorItself()
{
const string inputFilePath(testFilePath("some_structs.h"));
const vector<const char *> inputFiles{ inputFilePath.data() };
const vector<string> clangOptions{ "-resource-dir", REFLECTION_GENERATOR_CLANG_RESOURCE_DIR, "-I", CPP_UTILITIES_INCLUDE_DIRS, "-I",
RAPIDJSON_INCLUDE_DIRS };
const vector<string> clangOptions{ "-resource-dir", REFLECTION_GENERATOR_CLANG_RESOURCE_DIR, "-I", CPP_UTILITIES_INCLUDE_DIRS,
#ifdef RAPIDJSON_INCLUDE_DIRS
"-I", RAPIDJSON_INCLUDE_DIRS
#endif
};

stringstream buffer;
JsonSerializationCodeGenerator::Options jsonOptions;
Expand All @@ -90,9 +93,12 @@ void JsonGeneratorTests::testCLI()
string stdout, stderr;

const string inputFilePath(testFilePath("some_structs.h"));
const char *const args1[]
= { PROJECT_NAME, "--input-file", inputFilePath.data(), "--json-classes", "TestNamespace2::ThirdPartyStruct", "--clang-opt", "-resource-dir",
REFLECTION_GENERATOR_CLANG_RESOURCE_DIR, "-I", CPP_UTILITIES_INCLUDE_DIRS, "-I", RAPIDJSON_INCLUDE_DIRS, nullptr };
const char *const args1[] = { PROJECT_NAME, "--input-file", inputFilePath.data(), "--json-classes", "TestNamespace2::ThirdPartyStruct",
"--clang-opt", "-resource-dir", REFLECTION_GENERATOR_CLANG_RESOURCE_DIR, "-I", CPP_UTILITIES_INCLUDE_DIRS,
#ifdef RAPIDJSON_INCLUDE_DIRS
"-I", RAPIDJSON_INCLUDE_DIRS,
#endif
nullptr };
TESTUTILS_ASSERT_EXEC(args1);
assertEqualityLinewise(m_expectedCode, toArrayOfLines(stdout));
#endif
Expand Down

0 comments on commit fecde7d

Please sign in to comment.