Merge branch 'issue480' of github.com:openscad/openscad into issue480

Conflicts:
	tests/CMakeLists.txt
issue480
Don Bright 2013-09-22 16:45:38 -05:00
commit c9f8b7bf6b
27 changed files with 102 additions and 54 deletions

View File

@ -69,11 +69,9 @@ This is almost the same as adding a new regression test:
Migration away from dedicated regression tests:
-----------------------------------------------
Two tests still need an intermediate script that mangles away timestamps and
This test still needs an intermediate script that mangles away timestamps and
near-zero floating point numbers:
* dumptest
* echotest
* cgalstlsanitytest
Some tests are yet to be converted:
@ -85,15 +83,6 @@ These look like tests, but are not actually in use:
* modulecachetest
* cgalcachetest
In the course of migration, the possibilities of using the OPENSCAD_TESTING
compile time flag go away; that flag used to strip timestamps out of files,
to unify float output, and to tweak the file inclusion paths. With that flag
unused, we get better coverage of the primary code paths, at the cost of
having to do some normalization in the unit testing process (thus the dumptest
and echo test scripts). Especially, having a nonstandard MCAD library in the
user include path can now break things -- but so can having misbehaving
programs in your PATH.
Troubleshooting:
------------------------------

View File

@ -43,14 +43,23 @@ setenv_common()
setenv_freebsd()
{
echo .... freebsd detected.
echo .... if you have freebsd >9, it is advisable to install
echo .... the clang compiler and re-run this script as
echo .... '. ./scripts/setenv-unibuild.sh clang'
setenv_common
QMAKESPEC=freebsd-g++
QTDIR=/usr/local/share/qt4
export QMAKESPEC
export QTDIR
}
setenv_netbsd()
{
setenv_common
echo --- netbsd build situation is complex. it comes with gcc4.5
echo --- which is incompatable with updated CGAL.
echo --- you may need to hack with newer gcc to make it work
QMAKESPEC=netbsd-g++
QTDIR=/usr/pkg/qt4
PATH=/usr/pkg/qt4/bin:$PATH
@ -75,6 +84,30 @@ setenv_linux_clang()
echo QMAKESPEC has been modified: $QMAKESPEC
}
setenv_freebsd_clang()
{
export CC=clang
export CXX=clang++
export QMAKESPEC=freebsd-clang
echo CC has been modified: $CC
echo CXX has been modified: $CXX
echo QMAKESPEC has been modified: $QMAKESPEC
}
setenv_netbsd_clang()
{
echo --------------------- this is not yet supported. netbsd 6 lacks
echo --------------------- certain things needed for clang support
export CC=clang
export CXX=clang++
export QMAKESPEC=./patches/mkspecs/netbsd-clang
echo CC has been modified: $CC
echo CXX has been modified: $CXX
echo QMAKESPEC has been modified: $QMAKESPEC
}
clean_note()
{
if [ $QT5_SETUP ]; then
@ -125,8 +158,14 @@ if [ "`uname | grep -i 'linux\|debian'`" ]; then
fi
elif [ "`uname | grep -i freebsd`" ]; then
setenv_freebsd
if [ "`echo $* | grep clang`" ]; then
setenv_freebsd_clang
fi
elif [ "`uname | grep -i netbsd`" ]; then
setenv_netbsd
if [ "`echo $* | grep clang`" ]; then
setenv_netbsd_clang
fi
else
# guess
setenv_common

View File

@ -292,6 +292,7 @@ build_cgal()
echo "Building CGAL" $version "..."
cd $BASEDIR/src
rm -rf CGAL-$version
ver4_2="curl --insecure -O https://gforge.inria.fr/frs/download.php/32360/CGAL-4.2.tar.bz2"
ver4_1="curl --insecure -O https://gforge.inria.fr/frs/download.php/31640/CGAL-4.1.tar.bz2"
ver4_0_2="curl --insecure -O https://gforge.inria.fr/frs/download.php/31174/CGAL-4.0.2.tar.bz2"
ver4_0="curl --insecure -O https://gforge.inria.fr/frs/download.php/30387/CGAL-4.0.tar.gz"
@ -299,7 +300,7 @@ build_cgal()
ver3_8="curl --insecure -O https://gforge.inria.fr/frs/download.php/28500/CGAL-3.8.tar.gz"
ver3_7="curl --insecure -O https://gforge.inria.fr/frs/download.php/27641/CGAL-3.7.tar.gz"
vernull="echo already downloaded..skipping"
download_cmd=ver`echo $version | sed s/"\."/"_"/`
download_cmd=ver`echo $version | sed s/"\."/"_"/ | sed s/"\."/"_"/`
if [ -e CGAL-$version.tar.gz ]; then
download_cmd=vernull;
@ -308,6 +309,7 @@ build_cgal()
download_cmd=vernull;
fi
eval echo "$"$download_cmd
`eval echo "$"$download_cmd`
zipper=gzip
@ -574,7 +576,7 @@ if [ $1 ]; then
exit $?
fi
if [ $1 = "cgal" ]; then
build_cgal 4.1 use-sys-libs
build_cgal 4.0.2 use-sys-libs
exit $?
fi
if [ $1 = "opencsg" ]; then
@ -605,7 +607,7 @@ build_gmp 5.0.5
build_mpfr 3.1.1
build_boost 1.53.0
# NB! For CGAL, also update the actual download URL in the function
build_cgal 4.1
build_cgal 4.0.2
build_glew 1.9.0
build_opencsg 1.3.2

View File

@ -83,6 +83,21 @@ using std::vector;
using boost::lexical_cast;
using boost::is_any_of;
class Echostream : public std::ofstream
{
public:
Echostream( const char * filename ) : std::ofstream( filename ) {
set_output_handler( &Echostream::output, this );
}
static void output( const std::string &msg, void *userdata ) {
Echostream *thisp = static_cast<Echostream*>(userdata);
*thisp << msg << "\n";
}
~Echostream() {
this->close();
}
};
static void help(const char *progname)
{
int tab = int(strlen(progname))+8;
@ -191,7 +206,7 @@ int cmdline( const char* deps_output_file, const char* filename, Camera &camera,
const char *png_output_file = NULL;
const char *ast_output_file = NULL;
const char *term_output_file = NULL;
bool null_output = false;
const char *echo_output_file = NULL;
std::string suffix = boosty::extension_str( output_file );
boost::algorithm::to_lower( suffix );
@ -203,7 +218,7 @@ int cmdline( const char* deps_output_file, const char* filename, Camera &camera,
else if (suffix == ".png") png_output_file = output_file;
else if (suffix == ".ast") ast_output_file = output_file;
else if (suffix == ".term") term_output_file = output_file;
else if (strcmp(output_file, "null") == 0) null_output = true;
else if (suffix == ".echo") echo_output_file = output_file;
else {
fprintf(stderr, "Unknown suffix for output file %s\n", output_file);
return 1;
@ -215,6 +230,9 @@ int cmdline( const char* deps_output_file, const char* filename, Camera &camera,
#if 0 && DEBUG
top_ctx.dump(NULL, NULL);
#endif
shared_ptr<Echostream> echostream;
if (echo_output_file)
echostream.reset( new Echostream( echo_output_file ) );
FileModule *root_module;
ModuleInstantiation root_inst("group");
@ -301,8 +319,8 @@ int cmdline( const char* deps_output_file, const char* filename, Camera &camera,
}
else {
#ifdef ENABLE_CGAL
if ((null_output || png_output_file) && !(renderer==Render::CGAL)) {
// null output or OpenCSG png -> don't necessarily need CGALMesh evaluation
if ((echo_output_file || png_output_file) && !(renderer==Render::CGAL)) {
// echo or OpenCSG png -> don't necessarily need CGALMesh evaluation
} else {
root_N = cgalevaluator.evaluateCGALMesh(*tree.root());
}

View File

@ -1,5 +1,7 @@
# instructions - see ../doc/testing.txt
set(DEBUG_OSCD 1) # print debug info during cmake
cmake_minimum_required(VERSION 2.8)
if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_GREATER 2.8.3)
# Explicitly use new include policy to avoid globally shadowing included modules
@ -38,6 +40,7 @@ set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}")
# Build debug build as default
if(NOT CMAKE_BUILD_TYPE)
<<<<<<< HEAD
# set(CMAKE_BUILD_TYPE Release)
if(CMAKE_COMPILER_IS_GNUCXX)
execute_process(COMMAND ${CMAKE_C_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_VERSION)
@ -49,6 +52,10 @@ if(NOT CMAKE_BUILD_TYPE)
else()
set(CMAKE_BUILD_TYPE RelWithDebInfo)
endif()
=======
set(CMAKE_BUILD_TYPE RelWithDebInfo)
# set(CMAKE_BUILD_TYPE Release)
>>>>>>> 4ebd8136a83325e67be7a39c9349ec8812aa05c1
endif()
if(CMAKE_COMPILER_IS_GNUCXX)
@ -124,12 +131,15 @@ endif()
#
function(inclusion user_set_path found_paths)
# If user_set_path indicates an env. variable was specifically
# set by the user, then found_paths become an include priority (prepend);
# otherwise found_paths are stuck on the end of the include flags (append).
# Set up compiler include paths with prepend/append rules. Input is
# a path and a set of paths. If user_set_path matches anything in found_paths
# then we prepend the found_paths because we assume the user wants
# their set_paths to be a priority.
# message(STATUS "inclusion ${user_set_path} ${found_paths}")
# message(STATUS "inclusion ${${user_set_path}} ${${found_paths}}")
if (DEBUG_OSCD)
message(STATUS "inclusion ${user_set_path} ${found_paths}")
message(STATUS "inclusion ${${user_set_path}} ${${found_paths}}")
endif()
set( inclusion_match 0 )
foreach( found_path ${${found_paths}} )
if (${found_path} MATCHES ${${user_set_path}}.*)
@ -138,10 +148,14 @@ function(inclusion user_set_path found_paths)
endforeach()
if (user_set_path AND inclusion_match)
include_directories(BEFORE ${${found_paths}})
# message(STATUS "inclusion prepend ${${found_paths}} for ${user_set_path}")
if (DEBUG_OSCD)
message(STATUS "inclusion prepend ${${found_paths}} for ${user_set_path}")
endif()
else()
include_directories(AFTER ${${found_paths}})
# message(STATUS "inclusion append ${${found_paths}} for ${user_set_path}")
if (DEBUG_OSCD)
message(STATUS "inclusion append ${${found_paths}} for ${user_set_path}")
endif()
endif()
set( inclusion_match 0 )
endfunction()
@ -339,6 +353,13 @@ if(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
set(FLEX_EXECUTABLE /usr/local/bin/flex)
endif()
# prepend the dir where deps were built
if (NOT $ENV{OPENSCAD_LIBRARIES} STREQUAL "")
set(OSCAD_DEPS "")
set(OSCAD_DEPS_PATHS $ENV{OPENSCAD_LIBRARIES}/include)
inclusion(OSCAD_DEPS OSCAD_DEPS_PATHS)
endif()
if(${CMAKE_SYSTEM_NAME} MATCHES "NetBSD")
include_directories( /usr/pkg/include /usr/X11R7/include )
set(FLEX_EXECUTABLE /usr/pkg/bin/flex)
@ -567,9 +588,9 @@ target_link_libraries(cgalcachetest tests-cgal ${TESTS-CGAL-LIBRARIES} ${GLEW_LI
#
# openscad no-qt
#
add_executable(openscad ../src/openscad.cc)
set_target_properties(openscad PROPERTIES COMPILE_FLAGS "-fno-strict-aliasing -DEIGEN_DONT_ALIGN -DENABLE_CGAL -DENABLE_OPENCSG ${CGAL_CXX_FLAGS_INIT}")
target_link_libraries(openscad tests-offscreen tests-cgal tests-nocgal ${TESTS-CORE-LIBRARIES} ${TESTS-CGAL-LIBRARIES} ${GLEW_LIBRARY} ${Boost_LIBRARIES} ${OPENCSG_LIBRARY} ${COCOA_LIBRARY} )
add_executable(openscad_nogui ../src/openscad.cc)
set_target_properties(openscad_nogui PROPERTIES COMPILE_FLAGS "-fno-strict-aliasing -DEIGEN_DONT_ALIGN -DENABLE_CGAL -DENABLE_OPENCSG ${CGAL_CXX_FLAGS_INIT}")
target_link_libraries(openscad_nogui tests-offscreen tests-cgal tests-nocgal ${TESTS-CORE-LIBRARIES} ${TESTS-CGAL-LIBRARIES} ${GLEW_LIBRARY} ${Boost_LIBRARIES} ${OPENCSG_LIBRARY} ${COCOA_LIBRARY} )
#
# GUI binary tests
@ -596,9 +617,9 @@ target_link_libraries(openscad tests-offscreen tests-cgal tests-nocgal ${TESTS-C
#endif()
if(WIN32)
set(OPENSCAD_BINPATH "${CMAKE_CURRENT_BINARY_DIR}/openscad.exe")
set(OPENSCAD_BINPATH "${CMAKE_CURRENT_BINARY_DIR}/openscad_nogui.exe")
else()
set(OPENSCAD_BINPATH "${CMAKE_CURRENT_BINARY_DIR}/openscad")
set(OPENSCAD_BINPATH "${CMAKE_CURRENT_BINARY_DIR}/openscad_nogui")
endif()
#
@ -878,8 +899,6 @@ file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/CTestCustom.cmake ${TMP})
# Add tests
add_cmdline_test(echotest EXE ${CMAKE_SOURCE_DIR}/echotest SUFFIX txt ARGS ${OPENSCAD_BINPATH} FILES ${ECHO_FILES})
add_cmdline_test(dumptest EXE ${CMAKE_SOURCE_DIR}/dumptest SUFFIX csg ARGS ${OPENSCAD_BINPATH} FILES ${DUMPTEST_FILES})
add_cmdline_test(moduledumptest EXE ${OPENSCAD_BINPATH} ARGS -o SUFFIX ast FILES
${CMAKE_SOURCE_DIR}/../testdata/scad/misc/allmodules.scad
${CMAKE_SOURCE_DIR}/../testdata/scad/misc/allfunctions.scad
@ -892,6 +911,8 @@ add_cmdline_test(csgtermtest EXE ${OPENSCAD_BINPATH} ARGS -o SUFFIX term FILES
${CMAKE_SOURCE_DIR}/../testdata/scad/misc/allexpressions.scad
${CMAKE_SOURCE_DIR}/../testdata/scad/misc/allfunctions.scad
${CMAKE_SOURCE_DIR}/../testdata/scad/misc/allmodules.scad)
add_cmdline_test(echotest EXE ${OPENSCAD_BINPATH} ARGS -o SUFFIX echo FILES ${ECHO_FILES})
add_cmdline_test(dumptest EXE ${OPENSCAD_BINPATH} ARGS -o SUFFIX csg FILES ${DUMPTEST_FILES})
add_cmdline_test(cgalpngtest EXE ${OPENSCAD_BINPATH} ARGS --render -o SUFFIX png FILES ${CGALPNGTEST_FILES})
add_cmdline_test(opencsgtest EXE ${OPENSCAD_BINPATH} ARGS -o SUFFIX png FILES ${OPENCSGTEST_FILES})
add_cmdline_test(throwntogethertest EXE ${OPENSCAD_BINPATH} ARGS --preview=throwntogether -o SUFFIX png FILES ${THROWNTOGETHERTEST_FILES})

View File

@ -1,12 +0,0 @@
#!/usr/bin/env python
import re, sys, subprocess
subprocess.check_call([sys.argv[2], sys.argv[1], '-o', sys.argv[3]])
result = open(sys.argv[3]).read()
result = re.sub(r', timestamp = [0-9]*', '', result)
result = re.sub(r'-?[0-9].[0-9]*e-[0-9]{2,}', '0', result)
open(sys.argv[3], 'w').write(result)

View File

@ -1,8 +0,0 @@
#!/usr/bin/env python
import re, sys, subprocess
result = subprocess.Popen([sys.argv[2], sys.argv[1], '-o', 'null'], stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()[1]
result = re.sub(r'-?[0-9].[0-9]*e-[0-9]{2,}', '0', result)
open(sys.argv[3], 'w').write(result)

View File

@ -1,4 +1,3 @@
#!/usr/bin/env python
#
# Regression test driver for cmd-line tools