Skip to content

Commit

Permalink
Update warnings tests to check C++ and Python generators as well
Browse files Browse the repository at this point in the history
  • Loading branch information
mikir committed Mar 29, 2022
1 parent 911b00c commit 5c170bf
Show file tree
Hide file tree
Showing 31 changed files with 1,175 additions and 7 deletions.
25 changes: 25 additions & 0 deletions test/warnings/choice_types_warning/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
set(ZSERIO_GEN_DIR ${CMAKE_CURRENT_BINARY_DIR}/gen)
set(ZSERIO_GENERATED_SOURCES
${ZSERIO_GEN_DIR}/choice_types_warning/optional_references_in_selector/Selector.cpp
${ZSERIO_GEN_DIR}/choice_types_warning/optional_references_in_selector/Selector.h
${ZSERIO_GEN_DIR}/choice_types_warning/optional_references_in_selector/TestChoice.cpp
${ZSERIO_GEN_DIR}/choice_types_warning/optional_references_in_selector/TestChoice.h
)

zserio_add_library(TARGET choice_types_warning_zs
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/zs
MAIN_SOURCE choice_types_warning.zs
OUT_DIR ${ZSERIO_GEN_DIR}
OUT_FILES ${ZSERIO_GENERATED_SOURCES}
ZSERIO_CORE_DIR ${ZSERIO_JAR_DIR}
ZSERIO_CPP_DIR ${ZSERIO_CPP_DISTR_DIR}
ZSERIO_OPTIONS -withoutSourcesAmalgamation
EXPECTED_WARNINGS 1
ZSERIO_LOG_FILENAME zserio_log.txt
)

add_test_sources(
cpp/ChoiceTypesWarningTest.cpp
)

add_test_dependencies(choice_types_warning_zs)
23 changes: 23 additions & 0 deletions test/warnings/choice_types_warning/cpp/ChoiceTypesWarningTest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include <string>
#include <vector>

#include "gtest/gtest.h"

#include "test_utils/ZserioErrorOutput.h"

class ChoiceTypesWarningTest : public ::testing::Test
{
protected:
ChoiceTypesWarningTest()
: zserioWarnings("warnings/choice_types_warning")
{}

const test_utils::ZserioErrorOutput zserioWarnings;
};

TEST_F(ChoiceTypesWarningTest, optionalReferencesInSelector)
{
const std::string warning = "optional_references_in_selector.zs:8:41: Choice 'TestChoice' selector "
"contains reference to optional field 'numBits'.";
ASSERT_TRUE(zserioWarnings.isPresent(warning));
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uninitMemberVar:*/choice_types_warning/optional_references_in_selector/TestChoice.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import unittest

from testutils import getZserioApi, assertWarningsPresent

class ArrayTypesWarningTest(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.warnings = {}
cls.api = getZserioApi(__file__, "choice_types_warning.zs",
expectedWarnings=1, errorOutputDict=cls.warnings)

def testOptionalReferencesInSelector(self):
assertWarningsPresent(self,
"choice_types_warning.zs",
[
"optional_references_in_selector.zs:8:41: Choice 'TestChoice' selector "
"contains reference to optional field 'numBits'."
]
)
80 changes: 80 additions & 0 deletions test/warnings/comments_warning/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
set(ZSERIO_GEN_DIR ${CMAKE_CURRENT_BINARY_DIR}/gen)
set(ZSERIO_GENERATED_SOURCES
${ZSERIO_GEN_DIR}/comments_warning/markdown_comment_with_wrong_terminator/OtherTestStruct.cpp
${ZSERIO_GEN_DIR}/comments_warning/markdown_comment_with_wrong_terminator/OtherTestStruct.h
${ZSERIO_GEN_DIR}/comments_warning/markdown_comment_with_wrong_terminator/TestDatabase.cpp
${ZSERIO_GEN_DIR}/comments_warning/markdown_comment_with_wrong_terminator/TestDatabase.h
${ZSERIO_GEN_DIR}/comments_warning/markdown_comment_with_wrong_terminator/TestStruct.cpp
${ZSERIO_GEN_DIR}/comments_warning/markdown_comment_with_wrong_terminator/TestStruct.h
${ZSERIO_GEN_DIR}/comments_warning/markdown_comment_with_wrong_terminator/TestTable.cpp
${ZSERIO_GEN_DIR}/comments_warning/markdown_comment_with_wrong_terminator/TestTable.h

${ZSERIO_GEN_DIR}/comments_warning/unresolved_see_tag_in_templated_struct/TemplatedStructString.cpp
${ZSERIO_GEN_DIR}/comments_warning/unresolved_see_tag_in_templated_struct/TemplatedStructString.h
${ZSERIO_GEN_DIR}/comments_warning/unresolved_see_tag_in_templated_struct/TemplatedStructUInt32.cpp
${ZSERIO_GEN_DIR}/comments_warning/unresolved_see_tag_in_templated_struct/TemplatedStructUInt32.h

${ZSERIO_GEN_DIR}/comments_warning/unresolved_see_tag_reference/Database.cpp
${ZSERIO_GEN_DIR}/comments_warning/unresolved_see_tag_reference/Database.h
${ZSERIO_GEN_DIR}/comments_warning/unresolved_see_tag_reference/Table.cpp
${ZSERIO_GEN_DIR}/comments_warning/unresolved_see_tag_reference/Table.h
${ZSERIO_GEN_DIR}/comments_warning/unresolved_see_tag_reference/Test.cpp
${ZSERIO_GEN_DIR}/comments_warning/unresolved_see_tag_reference/Test.h
${ZSERIO_GEN_DIR}/comments_warning/unresolved_see_tag_reference/VALUE.h

${ZSERIO_GEN_DIR}/comments_warning/unused_field_comments/BasicComment.cpp
${ZSERIO_GEN_DIR}/comments_warning/unused_field_comments/BasicComment.h
${ZSERIO_GEN_DIR}/comments_warning/unused_field_comments/ByAlignmentAndType.cpp
${ZSERIO_GEN_DIR}/comments_warning/unused_field_comments/ByAlignmentAndType.h
${ZSERIO_GEN_DIR}/comments_warning/unused_field_comments/ByIndexedOffsetAndType.cpp
${ZSERIO_GEN_DIR}/comments_warning/unused_field_comments/ByIndexedOffsetAndType.h
${ZSERIO_GEN_DIR}/comments_warning/unused_field_comments/ByOffsetAndType.cpp
${ZSERIO_GEN_DIR}/comments_warning/unused_field_comments/ByOffsetAndType.h
${ZSERIO_GEN_DIR}/comments_warning/unused_field_comments/ByOptionalAndType.cpp
${ZSERIO_GEN_DIR}/comments_warning/unused_field_comments/ByOptionalAndType.h
${ZSERIO_GEN_DIR}/comments_warning/unused_field_comments/Database.cpp
${ZSERIO_GEN_DIR}/comments_warning/unused_field_comments/Database.h
${ZSERIO_GEN_DIR}/comments_warning/unused_field_comments/MultipleComments.cpp
${ZSERIO_GEN_DIR}/comments_warning/unused_field_comments/MultipleComments.h
${ZSERIO_GEN_DIR}/comments_warning/unused_field_comments/MultipleFieldComments.cpp
${ZSERIO_GEN_DIR}/comments_warning/unused_field_comments/MultipleFieldComments.h
${ZSERIO_GEN_DIR}/comments_warning/unused_field_comments/MultipleUnmaskedComments.cpp
${ZSERIO_GEN_DIR}/comments_warning/unused_field_comments/MultipleUnmaskedComments.h
${ZSERIO_GEN_DIR}/comments_warning/unused_field_comments/Table.cpp
${ZSERIO_GEN_DIR}/comments_warning/unused_field_comments/Table.h
${ZSERIO_GEN_DIR}/comments_warning/unused_field_comments/UnusedCommentById.cpp
${ZSERIO_GEN_DIR}/comments_warning/unused_field_comments/UnusedCommentById.h

${ZSERIO_GEN_DIR}/comments_warning/unused_struct_comment_by_id/Database.cpp
${ZSERIO_GEN_DIR}/comments_warning/unused_struct_comment_by_id/Database.h
${ZSERIO_GEN_DIR}/comments_warning/unused_struct_comment_by_id/Table.cpp
${ZSERIO_GEN_DIR}/comments_warning/unused_struct_comment_by_id/Table.h
${ZSERIO_GEN_DIR}/comments_warning/unused_struct_comment_by_id/Test.cpp
${ZSERIO_GEN_DIR}/comments_warning/unused_struct_comment_by_id/Test.h
${ZSERIO_GEN_DIR}/comments_warning/unused_struct_comment_multiple_comments/Database.cpp
${ZSERIO_GEN_DIR}/comments_warning/unused_struct_comment_multiple_comments/Database.h
${ZSERIO_GEN_DIR}/comments_warning/unused_struct_comment_multiple_comments/Table.cpp
${ZSERIO_GEN_DIR}/comments_warning/unused_struct_comment_multiple_comments/Table.h
${ZSERIO_GEN_DIR}/comments_warning/unused_struct_comment_multiple_comments/Test.cpp
${ZSERIO_GEN_DIR}/comments_warning/unused_struct_comment_multiple_comments/Test.h
)

zserio_add_library(TARGET comments_warning_zs
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/zs
MAIN_SOURCE comments_warning.zs
OUT_DIR ${ZSERIO_GEN_DIR}
OUT_FILES ${ZSERIO_GENERATED_SOURCES}
ZSERIO_CORE_DIR ${ZSERIO_JAR_DIR}
ZSERIO_CPP_DIR ${ZSERIO_CPP_DISTR_DIR}
ZSERIO_OPTIONS -withoutSourcesAmalgamation
EXPECTED_WARNINGS 13
ZSERIO_LOG_FILENAME zserio_log.txt
)

target_include_directories(comments_warning_zs SYSTEM PRIVATE ${SQLITE_INCDIR})

add_test_sources(
cpp/CommentsWarningTest.cpp
)

add_test_dependencies(comments_warning_zs)
74 changes: 74 additions & 0 deletions test/warnings/comments_warning/cpp/CommentsWarningTest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#include <string>
#include <vector>

#include "gtest/gtest.h"

#include "test_utils/ZserioErrorOutput.h"

class CommentsWarningTest : public ::testing::Test
{
protected:
CommentsWarningTest()
: zserioWarnings("warnings/comments_warning")
{}

const test_utils::ZserioErrorOutput zserioWarnings;
};

TEST_F(CommentsWarningTest, markdownCommentWithWrongTerminator)
{
ASSERT_TRUE(zserioWarnings.isPresent("markdown_comment_with_wrong_terminator.zs:3:1: "
"Markdown documentation comment should be terminated by '!*/'!"));

ASSERT_TRUE(zserioWarnings.isPresent("markdown_comment_with_wrong_terminator.zs:7:1: "
"Markdown documentation comment should be terminated by '!*/'!"));

ASSERT_TRUE(zserioWarnings.isPresent("markdown_comment_with_wrong_terminator.zs:21:1: "
"Markdown documentation comment should be terminated by '!*/'!"));

ASSERT_TRUE(zserioWarnings.isPresent("markdown_comment_with_wrong_terminator.zs:26:5: "
"Markdown documentation comment should be terminated by '!*/'!"));

ASSERT_TRUE(zserioWarnings.isPresent("markdown_comment_with_wrong_terminator.zs:38:5: "
"Markdown documentation comment should be terminated by '!*/'!"));
}

TEST_F(CommentsWarningTest, unresolvedSeeTagInTemplatedStruct)
{
ASSERT_TRUE(zserioWarnings.isPresent("unresolved_see_tag_in_templated_struct.zs:3:5: "
"Documentation: Unresolved referenced symbol 'unknown' for type 'TemplatedStruct'!"));
}

TEST_F(CommentsWarningTest, unresolvedSeeTagReference)
{
ASSERT_TRUE(zserioWarnings.isPresent("unresolved_see_tag_reference.zs:8:4: "
"Documentation: Unresolved referenced symbol 'Unexisting'!"));

ASSERT_TRUE(zserioWarnings.isPresent("unresolved_see_tag_reference.zs:15:4: "
"Documentation: Unresolved referenced symbol 'Unexisting' for type 'Table'!"));
}

TEST_F(CommentsWarningTest, unusedFieldComments)
{
ASSERT_TRUE(zserioWarnings.isPresent(
"unused_field_comments.zs:11:11: Documentation comment is not used!"));

ASSERT_TRUE(zserioWarnings.isPresent(
"unused_field_comments.zs:55:45: Documentation comment is not used!"));

ASSERT_TRUE(zserioWarnings.isPresent(
"unused_field_comments.zs:61:45: Documentation comment is not used!"));
}

TEST_F(CommentsWarningTest, unusedStructCommentById)
{
const std::string warning = "unused_struct_comment_by_id.zs:3:8: Documentation comment is not used!";
ASSERT_TRUE(zserioWarnings.isPresent(warning));
}

TEST_F(CommentsWarningTest, unusedStructCommentMultipleComments)
{
const std::string warning = "unused_struct_comment_multiple_comments.zs:5:9: "
"Documentation comment is not used!";
ASSERT_TRUE(zserioWarnings.isPresent(warning));
}
115 changes: 115 additions & 0 deletions test/warnings/comments_warning/python/CommentsWarningTest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
import unittest

from testutils import getZserioApi, assertWarningsPresent

class CommentsWarningTest(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.warnings = {}
cls.api = getZserioApi(__file__, "comments_warning.zs",
expectedWarnings=13, errorOutputDict=cls.warnings)

def testMarkdownCommentWithWrongTerminator(self):
assertWarningsPresent(self,
"comments_warning.zs",
[
"markdown_comment_with_wrong_terminator.zs:3:1: "
"Markdown documentation comment should be terminated by '!*/'!"
]
)

assertWarningsPresent(self,
"comments_warning.zs",
[
"markdown_comment_with_wrong_terminator.zs:7:1: "
"Markdown documentation comment should be terminated by '!*/'!"
]
)

assertWarningsPresent(self,
"comments_warning.zs",
[
"markdown_comment_with_wrong_terminator.zs:21:1: "
"Markdown documentation comment should be terminated by '!*/'!"
]
)

assertWarningsPresent(self,
"comments_warning.zs",
[
"markdown_comment_with_wrong_terminator.zs:26:5: "
"Markdown documentation comment should be terminated by '!*/'!"
]
)

assertWarningsPresent(self,
"comments_warning.zs",
[
"markdown_comment_with_wrong_terminator.zs:38:5: "
"Markdown documentation comment should be terminated by '!*/'!"
]
)

def testUnresolvedSeeTagInTemplatedStruct(self):
assertWarningsPresent(self,
"comments_warning.zs",
[
"unresolved_see_tag_in_templated_struct.zs:3:5: "
"Documentation: Unresolved referenced symbol 'unknown' for type 'TemplatedStruct'!"
]
)

def testUnresolvedSeeTagReference(self):
assertWarningsPresent(self,
"comments_warning.zs",
[
"unresolved_see_tag_reference.zs:8:4: "
"Documentation: Unresolved referenced symbol 'Unexisting'!"
]
)

assertWarningsPresent(self,
"comments_warning.zs",
[
"unresolved_see_tag_reference.zs:15:4: "
"Documentation: Unresolved referenced symbol 'Unexisting' for type 'Table'!"
]
)

def testUnusedFieldComments(self):
assertWarningsPresent(self,
"comments_warning.zs",
[
"unused_field_comments.zs:11:11: Documentation comment is not used!"
]
)
assertWarningsPresent(self,
"comments_warning.zs",
[
"unused_field_comments.zs:55:45: Documentation comment is not used!"
]
)

assertWarningsPresent(self,
"comments_warning.zs",
[
"unused_field_comments.zs:61:45: Documentation comment is not used!"
]
)

def testUnusedStructCommentById(self):
assertWarningsPresent(self,
"comments_warning.zs",
[
"unused_struct_comment_by_id.zs:3:8: Documentation comment is not used!"
]
)

def testUnusedStructCommentMultipleComments(self):
assertWarningsPresent(self,
"comments_warning.zs",
[
"unused_struct_comment_multiple_comments.zs:5:9: "
"Documentation comment is not used!"
]
)
25 changes: 18 additions & 7 deletions test/warnings/compatibility_warning/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,17 +1,28 @@
set(ZSERIO_GEN_DIR ${CMAKE_CURRENT_BINARY_DIR}/gen)
set(ZSERIO_GEN_DIR_ROOT_WITH ${CMAKE_CURRENT_BINARY_DIR}/gen_root_with)
set(ZSERIO_GEN_DIR_ROOT_WITHOUT ${CMAKE_CURRENT_BINARY_DIR}/gen_root_without)
set(LOG_FILENAME zserio_log.txt)

# clean old log file
file(REMOVE ${CMAKE_CURRENT_BINARY_DIR}/${LOG_FILENAME})

set(ZSERIO_GENERATED_SOURCES_ROOT_WITH
${ZSERIO_GEN_DIR_ROOT_WITH}/compatibility_warning/subpackage/TestStruct.cpp
${ZSERIO_GEN_DIR_ROOT_WITH}/compatibility_warning/subpackage/TestStruct.h
)

set(ZSERIO_GENERATED_SOURCES_ROOT_WITHOUT
${ZSERIO_GEN_DIR_ROOT_WITHOUT}/compatibility_warning/subpackage/TestStruct.cpp
${ZSERIO_GEN_DIR_ROOT_WITHOUT}/compatibility_warning/subpackage/TestStruct.h
)

zserio_add_library(TARGET root_with_diff_compatibility_warning_zs
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/zs
MAIN_SOURCE compatibility_warning/root_with_diff_compatibility_warning.zs
OUT_DIR ${ZSERIO_GEN_DIR}
OUT_FILES EMPTY
OUT_DIR ${ZSERIO_GEN_DIR_ROOT_WITH}
OUT_FILES ${ZSERIO_GENERATED_SOURCES_ROOT_WITH}
ZSERIO_CORE_DIR ${ZSERIO_JAR_DIR}
ZSERIO_CPP_DIR ${ZSERIO_CPP_DISTR_DIR}
ZSERIO_OPTIONS -withoutCrossExtensionCheck
ZSERIO_OPTIONS -withoutCrossExtensionCheck -withoutSourcesAmalgamation
EXPECTED_WARNINGS 1
ZSERIO_LOG_FILENAME ${LOG_FILENAME}
APPEND_TO_ZSERIO_LOG_FILE ON
Expand All @@ -20,11 +31,11 @@ zserio_add_library(TARGET root_with_diff_compatibility_warning_zs
zserio_add_library(TARGET root_without_compatibility_warning_zs
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/zs
MAIN_SOURCE compatibility_warning/root_without_compatibility_warning.zs
OUT_DIR ${ZSERIO_GEN_DIR}
OUT_FILES EMPTY
OUT_DIR ${ZSERIO_GEN_DIR_ROOT_WITHOUT}
OUT_FILES ${ZSERIO_GENERATED_SOURCES_ROOT_WITHOUT}
ZSERIO_CORE_DIR ${ZSERIO_JAR_DIR}
ZSERIO_CPP_DIR ${ZSERIO_CPP_DISTR_DIR}
ZSERIO_OPTIONS -withoutCrossExtensionCheck
ZSERIO_OPTIONS -withoutCrossExtensionCheck -withoutSourcesAmalgamation
EXPECTED_WARNINGS 1
ZSERIO_LOG_FILENAME ${LOG_FILENAME}
APPEND_TO_ZSERIO_LOG_FILE ON
Expand Down
Loading

0 comments on commit 5c170bf

Please sign in to comment.