Skip to content

Commit 7200160

Browse files
committed
test: add integration tests
1 parent a61df70 commit 7200160

8 files changed

Lines changed: 222 additions & 0 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,3 +141,5 @@ cython_debug/
141141
# static files generated from Django application using `collectstatic`
142142
media
143143
static
144+
145+
test/fixtures/out
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
cmake_minimum_required(VERSION 2.8.8 FATAL_ERROR)
2+
cmake_policy(VERSION 2.8.8)
3+
project(test)
4+
set(configuration "Default")
5+
enable_language(ASM)
6+
set(builddir "${CMAKE_CURRENT_BINARY_DIR}")
7+
set(obj "${builddir}/obj")
8+
9+
set(CMAKE_C_OUTPUT_EXTENSION_REPLACE 1)
10+
set(CMAKE_CXX_OUTPUT_EXTENSION_REPLACE 1)
11+
12+
13+
14+
#/Users/cwu631/Developer/nodejs/gyp-next/test/fixtures/integration.gyp:test#target
15+
set(TARGET "test")
16+
set(TOOLSET "target")
17+
set(test__cxx_srcs "../../test.cc")
18+
link_directories( ../../mylib
19+
)
20+
add_executable(test ${test__cxx_srcs})
21+
set_target_properties(test PROPERTIES EXCLUDE_FROM_ALL "FALSE")
22+
set_target_properties(test PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${builddir}")
23+
set_target_properties(test PROPERTIES PREFIX "")
24+
set_target_properties(test PROPERTIES RUNTIME_OUTPUT_NAME "test")
25+
set_target_properties(test PROPERTIES SUFFIX "")
26+
set_source_files_properties(${builddir}/test PROPERTIES GENERATED "TRUE")
27+
set(test__include_dirs "${CMAKE_CURRENT_LIST_DIR}/../../include")
28+
set_property(TARGET test APPEND PROPERTY INCLUDE_DIRECTORIES ${test__include_dirs})
29+
set_target_properties(test PROPERTIES COMPILE_FLAGS "-fasm-blocks -mpascal-strings -Os -gdwarf-2 -arch x86_64 ")
30+
unset(TOOLSET)
31+
unset(TARGET)
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# This file is generated by gyp; do not edit.
2+
3+
TOOLSET := target
4+
TARGET := test
5+
DEFS_Default :=
6+
7+
# Flags passed to all source files.
8+
CFLAGS_Default := \
9+
-fasm-blocks \
10+
-mpascal-strings \
11+
-Os \
12+
-gdwarf-2 \
13+
-arch \
14+
x86_64
15+
16+
# Flags passed to only C files.
17+
CFLAGS_C_Default :=
18+
19+
# Flags passed to only C++ files.
20+
CFLAGS_CC_Default :=
21+
22+
# Flags passed to only ObjC files.
23+
CFLAGS_OBJC_Default :=
24+
25+
# Flags passed to only ObjC++ files.
26+
CFLAGS_OBJCC_Default :=
27+
28+
INCS_Default := \
29+
-I$(srcdir)/include
30+
31+
OBJS := \
32+
$(obj).target/$(TARGET)/test.o
33+
34+
# Add to the list of files we specially track dependencies for.
35+
all_deps += $(OBJS)
36+
37+
# CFLAGS et al overrides must be target-local.
38+
# See "Target-specific Variable Values" in the GNU Make manual.
39+
$(OBJS): TOOLSET := $(TOOLSET)
40+
$(OBJS): GYP_CFLAGS := $(DEFS_$(BUILDTYPE)) $(INCS_$(BUILDTYPE)) $(CFLAGS_$(BUILDTYPE)) $(CFLAGS_C_$(BUILDTYPE))
41+
$(OBJS): GYP_CXXFLAGS := $(DEFS_$(BUILDTYPE)) $(INCS_$(BUILDTYPE)) $(CFLAGS_$(BUILDTYPE)) $(CFLAGS_CC_$(BUILDTYPE))
42+
$(OBJS): GYP_OBJCFLAGS := $(DEFS_$(BUILDTYPE)) $(INCS_$(BUILDTYPE)) $(CFLAGS_$(BUILDTYPE)) $(CFLAGS_C_$(BUILDTYPE)) $(CFLAGS_OBJC_$(BUILDTYPE))
43+
$(OBJS): GYP_OBJCXXFLAGS := $(DEFS_$(BUILDTYPE)) $(INCS_$(BUILDTYPE)) $(CFLAGS_$(BUILDTYPE)) $(CFLAGS_CC_$(BUILDTYPE)) $(CFLAGS_OBJCC_$(BUILDTYPE))
44+
45+
# Suffix rules, putting all outputs into $(obj).
46+
47+
$(obj).$(TOOLSET)/$(TARGET)/%.o: $(srcdir)/%.cc FORCE_DO_CMD
48+
@$(call do_cmd,cxx,1)
49+
50+
# Try building from generated source, too.
51+
52+
$(obj).$(TOOLSET)/$(TARGET)/%.o: $(obj).$(TOOLSET)/%.cc FORCE_DO_CMD
53+
@$(call do_cmd,cxx,1)
54+
55+
$(obj).$(TOOLSET)/$(TARGET)/%.o: $(obj)/%.cc FORCE_DO_CMD
56+
@$(call do_cmd,cxx,1)
57+
58+
# End of this set of suffix rules
59+
### Rules for final target.
60+
LDFLAGS_Default := \
61+
-arch \
62+
x86_64 \
63+
-L$(builddir) \
64+
-Lmylib
65+
66+
LIBTOOLFLAGS_Default :=
67+
68+
LIBS :=
69+
70+
$(builddir)/test: GYP_LDFLAGS := $(LDFLAGS_$(BUILDTYPE))
71+
$(builddir)/test: LIBS := $(LIBS)
72+
$(builddir)/test: GYP_LIBTOOLFLAGS := $(LIBTOOLFLAGS_$(BUILDTYPE))
73+
$(builddir)/test: LD_INPUTS := $(OBJS)
74+
$(builddir)/test: TOOLSET := $(TOOLSET)
75+
$(builddir)/test: $(OBJS) FORCE_DO_CMD
76+
$(call do_cmd,link)
77+
78+
all_deps += $(builddir)/test
79+
# Add target alias
80+
.PHONY: test
81+
test: $(builddir)/test
82+
83+
# Add executable to "all" target.
84+
.PHONY: all
85+
all: $(builddir)/test
86+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
defines =
2+
includes = -I../../include
3+
cflags = -fasm-blocks -mpascal-strings -Os -gdwarf-2 -arch x86_64
4+
cflags_c =
5+
cflags_cc =
6+
cflags_objc = $cflags_c
7+
cflags_objcc = $cflags_cc
8+
arflags =
9+
10+
build obj/test.test.o: cxx ../../test.cc
11+
12+
ldflags = -arch x86_64 -L./
13+
libs = -L../../mylib
14+
build test: link obj/test.test.o
15+
ld = $ldxx

test/fixtures/include/test.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#pragma once
2+
3+
int foo();

test/fixtures/integration.gyp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
'targets': [
3+
{
4+
'target_name': 'test',
5+
'type': 'executable',
6+
'sources': [
7+
'test.cc',
8+
],
9+
'include_dirs': [
10+
'include',
11+
],
12+
'library_dirs': [
13+
'mylib'
14+
],
15+
},
16+
]
17+
}

test/fixtures/test.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#include "test.h"
2+
3+
int main() {
4+
return foo();
5+
}
6+
7+
int foo() {
8+
return 0;
9+
}

test/integration_test.py

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#!/usr/bin/env python3
2+
3+
"""Integration test"""
4+
5+
import sys
6+
import unittest
7+
import os
8+
import shutil
9+
10+
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "../pylib"))
11+
import gyp
12+
13+
fixture_dir = os.path.join(os.path.dirname(__file__), "fixtures")
14+
gyp_file = os.path.join(os.path.dirname(__file__), "fixtures/integration.gyp")
15+
16+
17+
def assertFile(actual, expected):
18+
actual_bytes = open(os.path.join(fixture_dir, actual)).read()
19+
expected_bytes = open(os.path.join(fixture_dir, expected)).read()
20+
assert actual_bytes == expected_bytes
21+
22+
23+
class TestGyp(unittest.TestCase):
24+
def setUp(self):
25+
shutil.rmtree(os.path.join(fixture_dir, "out"), ignore_errors=True)
26+
27+
def test_ninja(self):
28+
rc = gyp.main(["-f", "ninja", "--depth", fixture_dir, gyp_file])
29+
assert rc == 0
30+
31+
files = [["out/Default/obj/test.ninja", "expected/ninja/test.ninja"]]
32+
for pair in files:
33+
assertFile(pair[0], pair[1])
34+
35+
def test_make(self):
36+
rc = gyp.main(
37+
[
38+
"-f",
39+
"make",
40+
"--depth",
41+
fixture_dir,
42+
"--generator-output",
43+
"out",
44+
gyp_file,
45+
]
46+
)
47+
assert rc == 0
48+
49+
files = [["out/test.target.mk", "expected/make/test.target.mk"]]
50+
for pair in files:
51+
assertFile(pair[0], pair[1])
52+
53+
def test_cmake(self):
54+
rc = gyp.main(["-f", "cmake", "--depth", fixture_dir, gyp_file])
55+
assert rc == 0
56+
57+
files = [["out/Default/CMakeLists.txt", "expected/cmake/CMakeLists.txt"]]
58+
for pair in files:
59+
assertFile(pair[0], pair[1])

0 commit comments

Comments
 (0)