diff options
Diffstat (limited to 'src/jaegertracing/thrift/compiler/cpp/test')
21 files changed, 273 insertions, 0 deletions
diff --git a/src/jaegertracing/thrift/compiler/cpp/test/CMakeLists.txt b/src/jaegertracing/thrift/compiler/cpp/test/CMakeLists.txt new file mode 100644 index 000000000..2bc7e9e69 --- /dev/null +++ b/src/jaegertracing/thrift/compiler/cpp/test/CMakeLists.txt @@ -0,0 +1,43 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +# Unit tests for the compiler still require boost +include(BoostMacros) +REQUIRE_BOOST_HEADERS() +set(BOOST_COMPONENTS unit_test_framework) +REQUIRE_BOOST_LIBRARIES(BOOST_COMPONENTS) + +file(GLOB KEYWORD_SAMPLES "${CMAKE_CURRENT_SOURCE_DIR}/keyword-samples/*.thrift") +foreach(LANG ${thrift_compiler_LANGS}) + foreach(SAMPLE ${KEYWORD_SAMPLES}) + get_filename_component(FILENAME ${SAMPLE} NAME_WE) + add_test(NAME "${LANG}_${FILENAME}" + COMMAND thrift-compiler --gen ${LANG} ${SAMPLE}) + set_tests_properties("${LANG}_${FILENAME}" PROPERTIES + PASS_REGULAR_EXPRESSION "Cannot use reserved language keyword") + endforeach() +endforeach() + + +find_package(PythonInterp QUIET) +if(PYTHONINTERP_FOUND) + add_test(NAME StalenessCheckTest COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/compiler/staleness_check.py ${THRIFT_COMPILER}) +else() + message(WARNING "Skipping StalenessCheckTest as there is no python interpreter available.") +endif() diff --git a/src/jaegertracing/thrift/compiler/cpp/test/Makefile.am b/src/jaegertracing/thrift/compiler/cpp/test/Makefile.am new file mode 100644 index 000000000..801f9d85e --- /dev/null +++ b/src/jaegertracing/thrift/compiler/cpp/test/Makefile.am @@ -0,0 +1,28 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +# +# Contains some contributions under the Thrift Software License. +# Please see doc/old-thrift-license.txt in the Thrift distribution for +# details. + +AUTOMAKE_OPTIONS = subdir-objects serial-tests nostdinc + +AM_CPPFLAGS = $(BOOST_CPPFLAGS) -I$(top_srcdir)/compiler/cpp/src +AM_LDFLAGS = $(BOOST_LDFLAGS) +AM_CXXFLAGS = -Wall -Wextra -pedantic diff --git a/src/jaegertracing/thrift/compiler/cpp/test/bincat.sh b/src/jaegertracing/thrift/compiler/cpp/test/bincat.sh new file mode 100755 index 000000000..c7f90785e --- /dev/null +++ b/src/jaegertracing/thrift/compiler/cpp/test/bincat.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +exec /bin/cat diff --git a/src/jaegertracing/thrift/compiler/cpp/test/compiler/Included.thrift b/src/jaegertracing/thrift/compiler/cpp/test/compiler/Included.thrift new file mode 100644 index 000000000..ce84ab6b9 --- /dev/null +++ b/src/jaegertracing/thrift/compiler/cpp/test/compiler/Included.thrift @@ -0,0 +1,18 @@ +const string foo = "bar" + +struct a_struct { + 1: bool im_true, + 2: bool im_false, + 3: i8 a_bite, + 4: i16 integer16, + 5: i32 integer32, + 6: i64 integer64, + 7: double double_precision, + 8: string some_characters, + 9: string zomg_unicode, + 10: bool what_who, +} + +service AService { + i32 a_procedure(1: i32 arg) +} diff --git a/src/jaegertracing/thrift/compiler/cpp/test/compiler/Including.thrift b/src/jaegertracing/thrift/compiler/cpp/test/compiler/Including.thrift new file mode 100644 index 000000000..677af7bb2 --- /dev/null +++ b/src/jaegertracing/thrift/compiler/cpp/test/compiler/Including.thrift @@ -0,0 +1,7 @@ +include "Included.thrift" + +const string s = "string" + +struct BStruct { + 1: Included.a_struct one_of_each +} diff --git a/src/jaegertracing/thrift/compiler/cpp/test/compiler/Single.thrift b/src/jaegertracing/thrift/compiler/cpp/test/compiler/Single.thrift new file mode 100644 index 000000000..2ec301f50 --- /dev/null +++ b/src/jaegertracing/thrift/compiler/cpp/test/compiler/Single.thrift @@ -0,0 +1 @@ +const string foo = "bar" diff --git a/src/jaegertracing/thrift/compiler/cpp/test/compiler/staleness_check.py b/src/jaegertracing/thrift/compiler/cpp/test/compiler/staleness_check.py new file mode 100755 index 000000000..5b11dff9e --- /dev/null +++ b/src/jaegertracing/thrift/compiler/cpp/test/compiler/staleness_check.py @@ -0,0 +1,142 @@ +#!/usr/bin/env python3 +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +from __future__ import print_function +import os +import shutil +import subprocess +import sys +import tempfile +import time +import unittest + + +class TestStalenessCheck(unittest.TestCase): + + CURRENT_DIR_PATH = os.path.dirname(os.path.realpath(__file__)) + THRIFT_EXECUTABLE_PATH = None + SINGLE_THRIFT_FILE_PATH = os.path.join(CURRENT_DIR_PATH, "Single.thrift") + INCLUDING_THRIFT_FILE_PATH = os.path.join(CURRENT_DIR_PATH, "Including.thrift") + INCLUDED_THRIFT_FILE_PATH = os.path.join(CURRENT_DIR_PATH, "Included.thrift") + + def test_staleness_check_of_single_thrift_file_without_changed_output(self): + temp_dir = tempfile.mkdtemp(dir=TestStalenessCheck.CURRENT_DIR_PATH) + + command = [TestStalenessCheck.THRIFT_EXECUTABLE_PATH, "-gen", "cpp", "-o", temp_dir] + command += [TestStalenessCheck.SINGLE_THRIFT_FILE_PATH] + subprocess.call(command) + + used_file_path = os.path.join(temp_dir, "gen-cpp", "Single_constants.cpp") + + first_modification_time = os.path.getmtime(os.path.join(used_file_path)) + + time.sleep(0.1) + + subprocess.call(command) + + second_modification_time = os.path.getmtime(used_file_path) + + self.assertEqual(second_modification_time, first_modification_time) + + shutil.rmtree(temp_dir, ignore_errors=True) + + def test_staleness_check_of_single_thrift_file_with_changed_output(self): + temp_dir = tempfile.mkdtemp(dir=TestStalenessCheck.CURRENT_DIR_PATH) + + command = [TestStalenessCheck.THRIFT_EXECUTABLE_PATH, "-gen", "cpp", "-o", temp_dir] + command += [TestStalenessCheck.SINGLE_THRIFT_FILE_PATH] + subprocess.call(command) + + used_file_path = os.path.join(temp_dir, "gen-cpp", "Single_constants.cpp") + + first_modification_time = os.path.getmtime(os.path.join(used_file_path)) + used_file = open(used_file_path, "r") + first_contents = used_file.read() + used_file.close() + + used_file = open(used_file_path, "a") + used_file.write("\n/* This is a comment */\n") + used_file.close() + + time.sleep(0.1) + + subprocess.call(command) + + second_modification_time = os.path.getmtime(used_file_path) + used_file = open(used_file_path, "r") + second_contents = used_file.read() + used_file.close() + + self.assertGreater(second_modification_time, first_modification_time) + self.assertEqual(first_contents, second_contents) + + shutil.rmtree(temp_dir, ignore_errors=True) + + def test_staleness_check_of_included_file(self): + temp_dir = tempfile.mkdtemp(dir=TestStalenessCheck.CURRENT_DIR_PATH) + + temp_included_file_path = os.path.join(temp_dir, "Included.thrift") + temp_including_file_path = os.path.join(temp_dir, "Including.thrift") + + shutil.copy2(TestStalenessCheck.INCLUDED_THRIFT_FILE_PATH, temp_included_file_path) + shutil.copy2(TestStalenessCheck.INCLUDING_THRIFT_FILE_PATH, temp_including_file_path) + + command = [TestStalenessCheck.THRIFT_EXECUTABLE_PATH, "-gen", "cpp", "-recurse", "-o", temp_dir] + command += [temp_including_file_path] + + subprocess.call(command) + + included_constants_cpp_file_path = os.path.join(temp_dir, "gen-cpp", "Included_constants.cpp") + including_constants_cpp_file_path = os.path.join(temp_dir, "gen-cpp", "Including_constants.cpp") + + included_constants_cpp_first_modification_time = os.path.getmtime(included_constants_cpp_file_path) + including_constants_cpp_first_modification_time = os.path.getmtime(including_constants_cpp_file_path) + + temp_included_file = open(temp_included_file_path, "a") + temp_included_file.write("\nconst i32 an_integer = 42\n") + temp_included_file.close() + + time.sleep(0.1) + + subprocess.call(command) + + included_constants_cpp_second_modification_time = os.path.getmtime(included_constants_cpp_file_path) + including_constants_cpp_second_modification_time = os.path.getmtime(including_constants_cpp_file_path) + + self.assertGreater( + included_constants_cpp_second_modification_time, included_constants_cpp_first_modification_time) + self.assertEqual( + including_constants_cpp_first_modification_time, including_constants_cpp_second_modification_time) + + shutil.rmtree(temp_dir, ignore_errors=True) + + +def suite(): + suite = unittest.TestSuite() + loader = unittest.TestLoader() + suite.addTest(loader.loadTestsFromTestCase(TestStalenessCheck)) + return suite + + +if __name__ == "__main__": + # The path of Thrift compiler is passed as an argument to the test script. + # Remove it to not confuse the unit testing framework + TestStalenessCheck.THRIFT_EXECUTABLE_PATH = sys.argv[-1] + del sys.argv[-1] + unittest.main(defaultTest="suite", testRunner=unittest.TextTestRunner(verbosity=2)) diff --git a/src/jaegertracing/thrift/compiler/cpp/test/keyword-samples/const1_return.thrift b/src/jaegertracing/thrift/compiler/cpp/test/keyword-samples/const1_return.thrift new file mode 100644 index 000000000..735e4acd8 --- /dev/null +++ b/src/jaegertracing/thrift/compiler/cpp/test/keyword-samples/const1_return.thrift @@ -0,0 +1 @@ +const bool return = 0 diff --git a/src/jaegertracing/thrift/compiler/cpp/test/keyword-samples/enum1_return.thrift b/src/jaegertracing/thrift/compiler/cpp/test/keyword-samples/enum1_return.thrift new file mode 100644 index 000000000..6d834e1da --- /dev/null +++ b/src/jaegertracing/thrift/compiler/cpp/test/keyword-samples/enum1_return.thrift @@ -0,0 +1,2 @@ +enum return { +} diff --git a/src/jaegertracing/thrift/compiler/cpp/test/keyword-samples/enum2_return.thrift b/src/jaegertracing/thrift/compiler/cpp/test/keyword-samples/enum2_return.thrift new file mode 100644 index 000000000..a2caa8e14 --- /dev/null +++ b/src/jaegertracing/thrift/compiler/cpp/test/keyword-samples/enum2_return.thrift @@ -0,0 +1,3 @@ +enum enum_name { + return +} diff --git a/src/jaegertracing/thrift/compiler/cpp/test/keyword-samples/exception1_return.thrift b/src/jaegertracing/thrift/compiler/cpp/test/keyword-samples/exception1_return.thrift new file mode 100644 index 000000000..eadb33834 --- /dev/null +++ b/src/jaegertracing/thrift/compiler/cpp/test/keyword-samples/exception1_return.thrift @@ -0,0 +1 @@ +exception return {} diff --git a/src/jaegertracing/thrift/compiler/cpp/test/keyword-samples/exception2_return.thrift b/src/jaegertracing/thrift/compiler/cpp/test/keyword-samples/exception2_return.thrift new file mode 100644 index 000000000..493c35297 --- /dev/null +++ b/src/jaegertracing/thrift/compiler/cpp/test/keyword-samples/exception2_return.thrift @@ -0,0 +1,3 @@ +exception exception_name { + 1: required i8 return +} diff --git a/src/jaegertracing/thrift/compiler/cpp/test/keyword-samples/service1_return.thrift b/src/jaegertracing/thrift/compiler/cpp/test/keyword-samples/service1_return.thrift new file mode 100644 index 000000000..5286a3691 --- /dev/null +++ b/src/jaegertracing/thrift/compiler/cpp/test/keyword-samples/service1_return.thrift @@ -0,0 +1 @@ +service return {} diff --git a/src/jaegertracing/thrift/compiler/cpp/test/keyword-samples/service2_return.thrift b/src/jaegertracing/thrift/compiler/cpp/test/keyword-samples/service2_return.thrift new file mode 100644 index 000000000..6f7331da0 --- /dev/null +++ b/src/jaegertracing/thrift/compiler/cpp/test/keyword-samples/service2_return.thrift @@ -0,0 +1,3 @@ +service service_name { + bool function_name(1: i32 return) +} diff --git a/src/jaegertracing/thrift/compiler/cpp/test/keyword-samples/service3_return.thrift b/src/jaegertracing/thrift/compiler/cpp/test/keyword-samples/service3_return.thrift new file mode 100644 index 000000000..c6dd946fd --- /dev/null +++ b/src/jaegertracing/thrift/compiler/cpp/test/keyword-samples/service3_return.thrift @@ -0,0 +1,3 @@ +service service_name { + void return() +} diff --git a/src/jaegertracing/thrift/compiler/cpp/test/keyword-samples/service4_return.thrift b/src/jaegertracing/thrift/compiler/cpp/test/keyword-samples/service4_return.thrift new file mode 100644 index 000000000..d0787dfde --- /dev/null +++ b/src/jaegertracing/thrift/compiler/cpp/test/keyword-samples/service4_return.thrift @@ -0,0 +1,5 @@ +exception exception_name {} + +service service_name { + void function_name() throws ( 1: exception_name return) +} diff --git a/src/jaegertracing/thrift/compiler/cpp/test/keyword-samples/struct1_return.thrift b/src/jaegertracing/thrift/compiler/cpp/test/keyword-samples/struct1_return.thrift new file mode 100644 index 000000000..c82b8b9ca --- /dev/null +++ b/src/jaegertracing/thrift/compiler/cpp/test/keyword-samples/struct1_return.thrift @@ -0,0 +1 @@ +struct return {} diff --git a/src/jaegertracing/thrift/compiler/cpp/test/keyword-samples/struct2_return.thrift b/src/jaegertracing/thrift/compiler/cpp/test/keyword-samples/struct2_return.thrift new file mode 100644 index 000000000..a0700d101 --- /dev/null +++ b/src/jaegertracing/thrift/compiler/cpp/test/keyword-samples/struct2_return.thrift @@ -0,0 +1,3 @@ +struct struct_name { + 1: required bool return = 1 +} diff --git a/src/jaegertracing/thrift/compiler/cpp/test/keyword-samples/typedef1_return.thrift b/src/jaegertracing/thrift/compiler/cpp/test/keyword-samples/typedef1_return.thrift new file mode 100644 index 000000000..f159bb880 --- /dev/null +++ b/src/jaegertracing/thrift/compiler/cpp/test/keyword-samples/typedef1_return.thrift @@ -0,0 +1 @@ +typedef bool return diff --git a/src/jaegertracing/thrift/compiler/cpp/test/keyword-samples/union1_return.thrift b/src/jaegertracing/thrift/compiler/cpp/test/keyword-samples/union1_return.thrift new file mode 100644 index 000000000..368df1383 --- /dev/null +++ b/src/jaegertracing/thrift/compiler/cpp/test/keyword-samples/union1_return.thrift @@ -0,0 +1 @@ +union return {} diff --git a/src/jaegertracing/thrift/compiler/cpp/test/keyword-samples/union2_return.thrift b/src/jaegertracing/thrift/compiler/cpp/test/keyword-samples/union2_return.thrift new file mode 100644 index 000000000..9719d1e40 --- /dev/null +++ b/src/jaegertracing/thrift/compiler/cpp/test/keyword-samples/union2_return.thrift @@ -0,0 +1,3 @@ +union union_name { + 1: optional bool return=1 +} |