Skip to content

Commit

Permalink
Split test-py2cpp into multiple files
Browse files Browse the repository at this point in the history
  • Loading branch information
dubzzz committed Oct 22, 2015
1 parent 8a18b25 commit 691421d
Show file tree
Hide file tree
Showing 5 changed files with 937 additions and 904 deletions.
16 changes: 12 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ ifeq ($(origin GXX), undefined)
else
CC=$(GXX)
endif
CFLAGS=-std=c++11 -Wall -Isrc $(shell python-config --cflags | sed -e "s/-Wstrict-prototypes//g") -fprofile-arcs -ftest-coverage
CFLAGS=-std=c++11 -Wall -I. $(shell python-config --cflags | sed -e "s/-Wstrict-prototypes//g") -fprofile-arcs -ftest-coverage
LDFLAGS=$(shell python-config --ldflags) -fprofile-arcs
CGTEST=-I/usr/local/include
LDGTEST=-L/usr/local/lib -lgtest
Expand All @@ -12,15 +12,23 @@ all: build examples

# *.o files compilation

build/test/test-py2cpp.o: test/test-py2cpp.cpp src/py2cpp.hpp
mkdir_test:
mkdir -p build/test

build/test/test-py2cpp.o: mkdir_test test/test-py2cpp.cpp
$(CC) -o build/test/test-py2cpp.o -c test/test-py2cpp.cpp $(CFLAGS) $(CGTEST)

build/test/helper.o: mkdir_test test/helper.hpp test/helper.cpp
$(CC) -o build/test/helper.o -c test/helper.cpp $(CFLAGS) $(CGTEST)

build/test/test-py2cpp-builder.o: mkdir_test test/test-py2cpp-builder.cpp src/py2cpp.hpp
$(CC) -o build/test/test-py2cpp-builder.o -c test/test-py2cpp-builder.cpp $(CFLAGS) $(CGTEST)

# Binaries

build/py2cpp.out: build/test/test-py2cpp.o
build/py2cpp.out: build/test/test-py2cpp.o build/test/test-py2cpp-builder.o build/test/helper.o
mkdir -p build
$(CC) -o build/py2cpp.out build/test/test-py2cpp.o $(LDFLAGS) $(LDGTEST)
$(CC) -o build/py2cpp.out build/test/test-py2cpp.o build/test/test-py2cpp-builder.o build/test/helper.o $(LDFLAGS) $(LDGTEST)

# Allowed commands

Expand Down
21 changes: 21 additions & 0 deletions test/helper.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include <Python.h>
#include "test/helper.hpp"

bool uncaught_exception()
{
if (!! PyErr_Occurred())
{
PyErr_Print();
PyErr_Clear();
return true;
}
return false;
}

PyObject* get_py_dict()
{
static PyObject* py_main { PyImport_AddModule("__main__") };
static PyObject* py_dict { PyModule_GetDict(py_main) };
return py_dict;
}

14 changes: 14 additions & 0 deletions test/helper.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#ifndef __HELPER_HPP__
#define __HELPER_HPP__

#include <Python.h>

// true if a Python error occurred and was not catch
// Print the error and free error space
bool uncaught_exception();

// PyObject corresponding to Python environment
PyObject* get_py_dict();

#endif

Loading

0 comments on commit 691421d

Please sign in to comment.