-
Notifications
You must be signed in to change notification settings - Fork 95
test: add integration tests #285
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| cmake_minimum_required(VERSION 2.8.8 FATAL_ERROR) | ||
| cmake_policy(VERSION 2.8.8) | ||
| project(test) | ||
| set(configuration "Default") | ||
| enable_language(ASM) | ||
| set(builddir "${CMAKE_CURRENT_BINARY_DIR}") | ||
| set(obj "${builddir}/obj") | ||
|
|
||
| set(CMAKE_C_OUTPUT_EXTENSION_REPLACE 1) | ||
| set(CMAKE_CXX_OUTPUT_EXTENSION_REPLACE 1) | ||
|
|
||
|
|
||
|
|
||
| #*/gyp-next/test/fixtures/integration.gyp:test#target | ||
| set(TARGET "test") | ||
| set(TOOLSET "target") | ||
| set(test__cxx_srcs "../../test.cc") | ||
| link_directories( ../../mylib | ||
| ) | ||
| add_executable(test ${test__cxx_srcs}) | ||
| set_target_properties(test PROPERTIES EXCLUDE_FROM_ALL "FALSE") | ||
| set_target_properties(test PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${builddir}") | ||
| set_target_properties(test PROPERTIES PREFIX "") | ||
| set_target_properties(test PROPERTIES RUNTIME_OUTPUT_NAME "test") | ||
| set_target_properties(test PROPERTIES SUFFIX "") | ||
| set_source_files_properties(${builddir}/test PROPERTIES GENERATED "TRUE") | ||
| set(test__include_dirs "${CMAKE_CURRENT_LIST_DIR}/../../include") | ||
| set_property(TARGET test APPEND PROPERTY INCLUDE_DIRECTORIES ${test__include_dirs}) | ||
| set_target_properties(test PROPERTIES COMPILE_FLAGS "-fasm-blocks -mpascal-strings -Os -gdwarf-2 -arch x86_64 ") | ||
| unset(TOOLSET) | ||
| unset(TARGET) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| # This file is generated by gyp; do not edit. | ||
|
|
||
| TOOLSET := target | ||
| TARGET := test | ||
| DEFS_Default := | ||
|
|
||
| # Flags passed to all source files. | ||
| CFLAGS_Default := \ | ||
| -fasm-blocks \ | ||
| -mpascal-strings \ | ||
| -Os \ | ||
| -gdwarf-2 \ | ||
| -arch \ | ||
| x86_64 | ||
|
|
||
| # Flags passed to only C files. | ||
| CFLAGS_C_Default := | ||
|
|
||
| # Flags passed to only C++ files. | ||
| CFLAGS_CC_Default := | ||
|
|
||
| # Flags passed to only ObjC files. | ||
| CFLAGS_OBJC_Default := | ||
|
|
||
| # Flags passed to only ObjC++ files. | ||
| CFLAGS_OBJCC_Default := | ||
|
|
||
| INCS_Default := \ | ||
| -I$(srcdir)/include | ||
|
|
||
| OBJS := \ | ||
| $(obj).target/$(TARGET)/test.o | ||
|
|
||
| # Add to the list of files we specially track dependencies for. | ||
| all_deps += $(OBJS) | ||
|
|
||
| # CFLAGS et al overrides must be target-local. | ||
| # See "Target-specific Variable Values" in the GNU Make manual. | ||
| $(OBJS): TOOLSET := $(TOOLSET) | ||
| $(OBJS): GYP_CFLAGS := $(DEFS_$(BUILDTYPE)) $(INCS_$(BUILDTYPE)) $(CFLAGS_$(BUILDTYPE)) $(CFLAGS_C_$(BUILDTYPE)) | ||
| $(OBJS): GYP_CXXFLAGS := $(DEFS_$(BUILDTYPE)) $(INCS_$(BUILDTYPE)) $(CFLAGS_$(BUILDTYPE)) $(CFLAGS_CC_$(BUILDTYPE)) | ||
| $(OBJS): GYP_OBJCFLAGS := $(DEFS_$(BUILDTYPE)) $(INCS_$(BUILDTYPE)) $(CFLAGS_$(BUILDTYPE)) $(CFLAGS_C_$(BUILDTYPE)) $(CFLAGS_OBJC_$(BUILDTYPE)) | ||
| $(OBJS): GYP_OBJCXXFLAGS := $(DEFS_$(BUILDTYPE)) $(INCS_$(BUILDTYPE)) $(CFLAGS_$(BUILDTYPE)) $(CFLAGS_CC_$(BUILDTYPE)) $(CFLAGS_OBJCC_$(BUILDTYPE)) | ||
|
|
||
| # Suffix rules, putting all outputs into $(obj). | ||
|
|
||
| $(obj).$(TOOLSET)/$(TARGET)/%.o: $(srcdir)/%.cc FORCE_DO_CMD | ||
| @$(call do_cmd,cxx,1) | ||
|
|
||
| # Try building from generated source, too. | ||
|
|
||
| $(obj).$(TOOLSET)/$(TARGET)/%.o: $(obj).$(TOOLSET)/%.cc FORCE_DO_CMD | ||
| @$(call do_cmd,cxx,1) | ||
|
|
||
| $(obj).$(TOOLSET)/$(TARGET)/%.o: $(obj)/%.cc FORCE_DO_CMD | ||
| @$(call do_cmd,cxx,1) | ||
|
|
||
| # End of this set of suffix rules | ||
| ### Rules for final target. | ||
| LDFLAGS_Default := \ | ||
| -arch \ | ||
| x86_64 \ | ||
| -L$(builddir) \ | ||
| -Lmylib | ||
|
|
||
| LIBTOOLFLAGS_Default := | ||
|
|
||
| LIBS := | ||
|
|
||
| $(builddir)/test: GYP_LDFLAGS := $(LDFLAGS_$(BUILDTYPE)) | ||
| $(builddir)/test: LIBS := $(LIBS) | ||
| $(builddir)/test: GYP_LIBTOOLFLAGS := $(LIBTOOLFLAGS_$(BUILDTYPE)) | ||
| $(builddir)/test: LD_INPUTS := $(OBJS) | ||
| $(builddir)/test: TOOLSET := $(TOOLSET) | ||
| $(builddir)/test: $(OBJS) FORCE_DO_CMD | ||
| $(call do_cmd,link) | ||
|
|
||
| all_deps += $(builddir)/test | ||
| # Add target alias | ||
| .PHONY: test | ||
| test: $(builddir)/test | ||
|
|
||
| # Add executable to "all" target. | ||
| .PHONY: all | ||
| all: $(builddir)/test | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| defines = | ||
| includes = -I../../include | ||
| cflags = -fasm-blocks -mpascal-strings -Os -gdwarf-2 -arch x86_64 | ||
| cflags_c = | ||
| cflags_cc = | ||
| cflags_objc = $cflags_c | ||
| cflags_objcc = $cflags_cc | ||
| arflags = | ||
|
|
||
| build obj/test.test.o: cxx ../../test.cc | ||
|
|
||
| ldflags = -arch x86_64 -L./ | ||
| libs = -L../../mylib | ||
| build test: link obj/test.test.o | ||
| ld = $ldxx |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| cmake_minimum_required(VERSION 2.8.8 FATAL_ERROR) | ||
| cmake_policy(VERSION 2.8.8) | ||
| project(test) | ||
| set(configuration "Default") | ||
| enable_language(ASM) | ||
| set(builddir "${CMAKE_CURRENT_BINARY_DIR}") | ||
| set(obj "${builddir}/obj") | ||
|
|
||
| set(CMAKE_C_OUTPUT_EXTENSION_REPLACE 1) | ||
| set(CMAKE_CXX_OUTPUT_EXTENSION_REPLACE 1) | ||
|
|
||
| set(CMAKE_NINJA_FORCE_RESPONSE_FILE 1) | ||
|
|
||
|
|
||
| #*/test/fixtures/integration.gyp:test#target | ||
| set(TARGET "test") | ||
| set(TOOLSET "target") | ||
| set(test__cxx_srcs "../../test.cc") | ||
| link_directories( ../../mylib | ||
| ) | ||
| add_executable(test ${test__cxx_srcs}) | ||
| set_target_properties(test PROPERTIES EXCLUDE_FROM_ALL "FALSE") | ||
| set_target_properties(test PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${builddir}") | ||
| set_target_properties(test PROPERTIES PREFIX "") | ||
| set_target_properties(test PROPERTIES RUNTIME_OUTPUT_NAME "test") | ||
| set_target_properties(test PROPERTIES SUFFIX "") | ||
| set_source_files_properties(${builddir}/test PROPERTIES GENERATED "TRUE") | ||
| set(test__include_dirs "${CMAKE_CURRENT_LIST_DIR}/../../include") | ||
| set_property(TARGET test APPEND PROPERTY INCLUDE_DIRECTORIES ${test__include_dirs}) | ||
| set_target_properties(test PROPERTIES COMPILE_FLAGS "") | ||
| unset(TOOLSET) | ||
| unset(TARGET) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| # This file is generated by gyp; do not edit. | ||
|
|
||
| TOOLSET := target | ||
| TARGET := test | ||
| DEFS_Default := | ||
|
|
||
| # Flags passed to all source files. | ||
| CFLAGS_Default := | ||
|
|
||
| # Flags passed to only C files. | ||
| CFLAGS_C_Default := | ||
|
|
||
| # Flags passed to only C++ files. | ||
| CFLAGS_CC_Default := | ||
|
|
||
| INCS_Default := \ | ||
| -I$(srcdir)/include | ||
|
|
||
| OBJS := \ | ||
| $(obj).target/$(TARGET)/test.o | ||
|
|
||
| # Add to the list of files we specially track dependencies for. | ||
| all_deps += $(OBJS) | ||
|
|
||
| # CFLAGS et al overrides must be target-local. | ||
| # See "Target-specific Variable Values" in the GNU Make manual. | ||
| $(OBJS): TOOLSET := $(TOOLSET) | ||
| $(OBJS): GYP_CFLAGS := $(DEFS_$(BUILDTYPE)) $(INCS_$(BUILDTYPE)) $(CFLAGS_$(BUILDTYPE)) $(CFLAGS_C_$(BUILDTYPE)) | ||
| $(OBJS): GYP_CXXFLAGS := $(DEFS_$(BUILDTYPE)) $(INCS_$(BUILDTYPE)) $(CFLAGS_$(BUILDTYPE)) $(CFLAGS_CC_$(BUILDTYPE)) | ||
|
|
||
| # Suffix rules, putting all outputs into $(obj). | ||
|
|
||
| $(obj).$(TOOLSET)/$(TARGET)/%.o: $(srcdir)/%.cc FORCE_DO_CMD | ||
| @$(call do_cmd,cxx,1) | ||
|
|
||
| # Try building from generated source, too. | ||
|
|
||
| $(obj).$(TOOLSET)/$(TARGET)/%.o: $(obj).$(TOOLSET)/%.cc FORCE_DO_CMD | ||
| @$(call do_cmd,cxx,1) | ||
|
|
||
| $(obj).$(TOOLSET)/$(TARGET)/%.o: $(obj)/%.cc FORCE_DO_CMD | ||
| @$(call do_cmd,cxx,1) | ||
|
|
||
| # End of this set of suffix rules | ||
| ### Rules for final target. | ||
| LDFLAGS_Default := \ | ||
| -Lmylib | ||
|
|
||
| LIBS := | ||
|
|
||
| $(builddir)/test: GYP_LDFLAGS := $(LDFLAGS_$(BUILDTYPE)) | ||
| $(builddir)/test: LIBS := $(LIBS) | ||
| $(builddir)/test: LD_INPUTS := $(OBJS) | ||
| $(builddir)/test: TOOLSET := $(TOOLSET) | ||
| $(builddir)/test: $(OBJS) FORCE_DO_CMD | ||
| $(call do_cmd,link) | ||
|
|
||
| all_deps += $(builddir)/test | ||
| # Add target alias | ||
| .PHONY: test | ||
| test: $(builddir)/test | ||
|
|
||
| # Add executable to "all" target. | ||
| .PHONY: all | ||
| all: $(builddir)/test | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| defines = | ||
| includes = -I../../include | ||
| cflags = | ||
| cflags_c = | ||
| cflags_cc = | ||
| arflags = | ||
|
|
||
| build obj/test.test.o: cxx ../../test.cc | ||
|
|
||
| ldflags = | ||
| libs = -L../../mylib | ||
| build test: link obj/test.test.o | ||
| ld = $ldxx |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| #pragma once | ||
|
|
||
| int foo(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| { | ||
| 'targets': [ | ||
| { | ||
| 'target_name': 'test', | ||
| 'type': 'executable', | ||
| 'sources': [ | ||
| 'test.cc', | ||
| ], | ||
| 'include_dirs': [ | ||
| 'include', | ||
| ], | ||
| 'library_dirs': [ | ||
| 'mylib' | ||
| ], | ||
| }, | ||
| ] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| #include "test.h" | ||
|
|
||
| int main() { | ||
| return foo(); | ||
| } | ||
|
|
||
| int foo() { | ||
| return 0; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| #!/usr/bin/env python3 | ||
|
|
||
| """Integration test""" | ||
|
|
||
| import os | ||
| import re | ||
| import shutil | ||
| import unittest | ||
|
|
||
| import gyp | ||
|
|
||
| fixture_dir = os.path.join(os.path.dirname(__file__), "fixtures") | ||
| gyp_file = os.path.join(os.path.dirname(__file__), "fixtures/integration.gyp") | ||
|
|
||
| supported_sysnames = {"darwin", "linux"} | ||
| sysname = os.uname().sysname.lower() | ||
| expected_dir = os.path.join(fixture_dir, f"expected-{sysname}") | ||
|
|
||
|
|
||
| class TestGyp(unittest.TestCase): | ||
| def setUp(self) -> None: | ||
| if sysname not in supported_sysnames: | ||
| self.skipTest(f"Unsupported system: {sysname}") | ||
| shutil.rmtree(os.path.join(fixture_dir, "out"), ignore_errors=True) | ||
|
|
||
| def assert_file(self, actual, expected) -> None: | ||
| actual_filepath = os.path.join(fixture_dir, actual) | ||
| expected_filepath = os.path.join(expected_dir, expected) | ||
|
|
||
| with open(expected_filepath) as in_file: | ||
| expected_bytes = re.escape(in_file.read()) | ||
| expected_bytes = expected_bytes.replace("\\*", ".*") | ||
| expected_re = re.compile(expected_bytes) | ||
|
|
||
| with open(actual_filepath) as in_file: | ||
| actual_bytes = in_file.read() | ||
|
|
||
| try: | ||
| self.assertRegex(actual_bytes, expected_re) | ||
| except Exception: | ||
| shutil.copyfile(actual_filepath, f"{expected_filepath}.actual") | ||
| raise | ||
|
|
||
| def test_ninja(self) -> None: | ||
| rc = gyp.main(["-f", "ninja", "--depth", fixture_dir, gyp_file]) | ||
| assert rc == 0 | ||
|
|
||
| self.assert_file("out/Default/obj/test.ninja", "ninja/test.ninja") | ||
|
|
||
| def test_make(self) -> None: | ||
| rc = gyp.main( | ||
| [ | ||
| "-f", | ||
| "make", | ||
| "--depth", | ||
| fixture_dir, | ||
| "--generator-output", | ||
| "out", | ||
| gyp_file, | ||
| ] | ||
| ) | ||
| assert rc == 0 | ||
|
|
||
| self.assert_file("out/test.target.mk", "make/test.target.mk") | ||
|
|
||
| def test_cmake(self) -> None: | ||
| rc = gyp.main(["-f", "cmake", "--depth", fixture_dir, gyp_file]) | ||
| assert rc == 0 | ||
|
|
||
| self.assert_file("out/Default/CMakeLists.txt", "cmake/CMakeLists.txt") | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comparing
assert re.search(expected_re, actual_bytes)andself.assertRegex(actual_bytes, expected_re), when there is a mismatch,self.assertRegexprovides more information on the regex and the input:On the other hand,
assert re.searchdoes not print all the inputsThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you running the tests with pytest (which does assertion rewriting) or with unittest?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm running with
pytest -vv.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK. The rewriting might be limited inside a
unittest.TestCase. Thanks for the nice work on this one.