Skip to content

Commit 9d7aacc

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

9 files changed

Lines changed: 231 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

pylib/gyp/generator/ninja_test.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
import unittest
1212

1313
import gyp.generator.ninja as ninja
14+
from gyp.ninja_syntax import Writer
15+
from io import StringIO
1416

1517

1618
class TestPrefixesAndSuffixes(unittest.TestCase):
@@ -51,6 +53,12 @@ def test_BinaryNamesLinux(self):
5153
writer.ComputeOutputFileName(spec, "static_library").endswith(".a")
5254
)
5355

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

0 commit comments

Comments
 (0)