Compare commits

...

14 Commits

Author SHA1 Message Date
e4fb5f4866 Merge branch 'develop' 2020-03-01 00:18:20 -05:00
9cf66925d4 Latest Borland with clang can support variadic macros. Updated iso test to be more correct choosing compiler level. 2020-02-18 02:44:51 -05:00
e4ce0f06f5 Merge branch 'develop' 2020-02-01 23:12:13 -05:00
98f6c75e1e Make the quick.cpp test 'explicit'. 2020-01-06 02:34:42 -05:00
f99ed9921a Merge pull request #28 from boostorg/feature/add-cmake-tests
Add CMake install support, tests
2020-01-05 20:20:29 -05:00
a378d239da Disable the Appveyor cmake_test configuration on 2015/2017 as it's too slow; only bootstrap b2 in the boost_build_test configuration 2020-01-05 07:19:59 +02:00
0332a793f5 Fix Appveyor branch handling 2020-01-05 06:48:21 +02:00
6c350c6fc3 Update appveyor.yml 2020-01-05 06:46:08 +02:00
728c71ba75 Enable C in test/CMakeLists.txt; add int main() {} to quick.cpp 2020-01-05 05:07:08 +02:00
1ab9385a91 Add CMake install support, tests 2020-01-05 04:32:16 +02:00
688c3f2ee6 Turn off variadic macro support by default for nvcc only when compiling CUDA files. 2019-12-14 13:20:45 -05:00
bd0db5ce8b Changed __CUDACC__ to __NVCC__ as other compilers do define __CUDACC__ when compiling CUDA files. 2019-12-14 12:45:02 -05:00
da60e76913 Added 'explicit' for test_iso. 2019-11-13 20:45:02 -05:00
661dd91603 Added explicit test with the alias 'test_iso' to run tests for macro expansion for the various C++ standards. 2019-11-13 20:38:10 -05:00
10 changed files with 1041 additions and 68 deletions

View File

@ -1,49 +1,322 @@
# Copyright 2016 Edward Diener
# Copyright 2016-2019 Peter Dimov
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or copy at http://boost.org/LICENSE_1_0.txt)
language: cpp
sudo: false
python: "2.7"
os:
- linux
- osx
dist: xenial
branches:
only:
- master
- develop
- /feature\/.*/
env:
matrix:
- BOGUS_JOB=true
matrix:
exclude:
- env: BOGUS_JOB=true
include:
- install: true
- os: linux
compiler: g++
env: TOOLSET=gcc COMPILER=g++ CXXSTD=03,11
- os: linux
compiler: g++-4.4
env: TOOLSET=gcc COMPILER=g++-4.4 CXXSTD=98
addons:
apt:
packages:
- g++-4.4
sources:
- ubuntu-toolchain-r-test
- os: linux
compiler: g++-4.6
env: TOOLSET=gcc COMPILER=g++-4.6 CXXSTD=03,0x
addons:
apt:
packages:
- g++-4.6
sources:
- ubuntu-toolchain-r-test
- os: linux
compiler: g++-4.7
env: TOOLSET=gcc COMPILER=g++-4.7 CXXSTD=03,11
addons:
apt:
packages:
- g++-4.7
sources:
- ubuntu-toolchain-r-test
- os: linux
compiler: g++-4.8
env: TOOLSET=gcc COMPILER=g++-4.8 CXXSTD=03,11
addons:
apt:
packages:
- g++-4.8
sources:
- ubuntu-toolchain-r-test
- os: linux
compiler: g++-4.9
env: TOOLSET=gcc COMPILER=g++-4.9 CXXSTD=03,11
addons:
apt:
packages:
- g++-4.9
sources:
- ubuntu-toolchain-r-test
- os: linux
compiler: g++-5
env: TOOLSET=gcc COMPILER=g++-5 CXXSTD=03,11,14,1z
addons:
apt:
packages:
- g++-5
sources:
- ubuntu-toolchain-r-test
- os: linux
compiler: g++-6
env: TOOLSET=gcc COMPILER=g++-6 CXXSTD=03,11,14,1z
addons:
apt:
packages:
- g++-6
sources:
- ubuntu-toolchain-r-test
- os: linux
dist: trusty
compiler: g++-7
env: TOOLSET=gcc COMPILER=g++-7 CXXSTD=03,11,14,17
addons:
apt:
packages:
- g++-7
sources:
- ubuntu-toolchain-r-test
- os: linux
compiler: g++-8
env: TOOLSET=gcc COMPILER=g++-8 CXXSTD=03,11,14,17,2a
addons:
apt:
packages:
- g++-8
sources:
- ubuntu-toolchain-r-test
- os: linux
compiler: g++-9
env: TOOLSET=gcc COMPILER=g++-9 CXXSTD=03,11,14,17,2a
addons:
apt:
packages:
- g++-9
sources:
- ubuntu-toolchain-r-test
- os: linux
compiler: clang++
env: TOOLSET=clang COMPILER=clang++ CXXSTD=03,11
- os: linux
dist: trusty
compiler: /usr/bin/clang++
env: TOOLSET=clang COMPILER=/usr/bin/clang++ CXXSTD=03,11
addons:
apt:
packages:
- clang-3.3
- os: linux
dist: trusty
compiler: /usr/bin/clang++
env: TOOLSET=clang COMPILER=/usr/bin/clang++ CXXSTD=03,11
addons:
apt:
packages:
- clang-3.4
- os: linux
compiler: clang++-3.5
env: TOOLSET=clang COMPILER=clang++-3.5 CXXSTD=03,11,14,1z
addons:
apt:
packages:
- clang-3.5
sources:
- ubuntu-toolchain-r-test
- os: linux
compiler: clang++-3.6
env: TOOLSET=clang COMPILER=clang++-3.6 CXXSTD=03,11,14,1z
addons:
apt:
packages:
- clang-3.6
sources:
- ubuntu-toolchain-r-test
- os: linux
compiler: clang++-3.7
env: TOOLSET=clang COMPILER=clang++-3.7 CXXSTD=03,11,14,1z
addons:
apt:
packages:
- clang-3.7
sources:
- ubuntu-toolchain-r-test
- os: linux
compiler: clang++-3.8
env: TOOLSET=clang COMPILER=clang++-3.8 CXXSTD=03,11,14,1z
addons:
apt:
packages:
- clang-3.8
sources:
- ubuntu-toolchain-r-test
- os: linux
compiler: clang++-3.9
env: TOOLSET=clang COMPILER=clang++-3.9 CXXSTD=03,11,14,1z
addons:
apt:
packages:
- clang-3.9
sources:
- ubuntu-toolchain-r-test
- os: linux
compiler: clang++-4.0
env: TOOLSET=clang COMPILER=clang++-4.0 CXXSTD=03,11,14,1z
addons:
apt:
packages:
- clang-4.0
sources:
- ubuntu-toolchain-r-test
- os: linux
compiler: clang++-5.0
env: TOOLSET=clang COMPILER=clang++-5.0 CXXSTD=03,11,14,1z
addons:
apt:
packages:
- clang-5.0
sources:
- ubuntu-toolchain-r-test
- os: linux
compiler: clang++-6.0
env: TOOLSET=clang COMPILER=clang++-6.0 CXXSTD=03,11,14,17,2a
addons:
apt:
packages:
- clang-6.0
sources:
- ubuntu-toolchain-r-test
- os: linux
compiler: clang++-7
env: TOOLSET=clang COMPILER=clang++-7 CXXSTD=03,11,14,17,2a
addons:
apt:
packages:
- clang-7
sources:
- ubuntu-toolchain-r-test
- llvm-toolchain-xenial-7
- os: linux
compiler: clang++-8
env: TOOLSET=clang COMPILER=clang++-8 CXXSTD=03,11,14,17,2a
addons:
apt:
packages:
- clang-8
sources:
- ubuntu-toolchain-r-test
- llvm-toolchain-xenial-8
- os: linux
compiler: clang++-9
env: TOOLSET=clang COMPILER=clang++-9 CXXSTD=03,11,14,17,2a
addons:
apt:
packages:
- clang-9
sources:
- ubuntu-toolchain-r-test
- sourceline: 'deb https://apt.llvm.org/xenial/ llvm-toolchain-xenial-9 main'
key_url: 'https://apt.llvm.org/llvm-snapshot.gpg.key'
- os: linux
dist: trusty
compiler: clang++-libc++
env: TOOLSET=clang COMPILER=clang++-libc++ CXXSTD=03,11,14,1z
addons:
apt:
packages:
- libc++-dev
- os: osx
compiler: clang++
env: TOOLSET=clang COMPILER=clang++ CXXSTD=03,11,14,1z
- os: linux
env: CMAKE_TEST=1
script:
- mkdir __build__ && cd __build__
- cmake ../test
- cmake --build .
- cmake -DBOOST_ENABLE_CMAKE=1 -DBoost_VERBOSE=1 -DBOOST_INCLUDE_LIBRARIES=preprocessor ..
- ctest --output-on-failure -R boost_preprocessor
- os: linux
env: CMAKE_SUBDIR_TEST=1
install: true
script:
- cd test/cmake_subdir_test && mkdir __build__ && cd __build__
- cmake ..
- cmake --build .
- cmake --build . --target check
- os: linux
env: CMAKE_INSTALL_TEST=1
script:
- mkdir __build__ && cd __build__
- cmake -DBOOST_ENABLE_CMAKE=1 -DBoost_VERBOSE=1 -DBOOST_INCLUDE_LIBRARIES=preprocessor -DCMAKE_INSTALL_PREFIX=~/.local ..
- cmake --build . --target install
- cd ../libs/preprocessor/test/cmake_install_test && mkdir __build__ && cd __build__
- cmake -DCMAKE_INSTALL_PREFIX=~/.local ..
- cmake --build .
- cmake --build . --target check
install:
- BOOST_BRANCH=develop && [ "$TRAVIS_BRANCH" == "master" ] && BOOST_BRANCH=master || true
- cd ..
- git clone -b $TRAVIS_BRANCH --depth 1 https://github.com/boostorg/boost.git boost-root
- git clone -b $BOOST_BRANCH --depth 1 https://github.com/boostorg/boost.git boost-root
- cd boost-root
- git submodule update --init tools/build
- git submodule update --init libs/config
- git submodule update --init tools/boostdep
- git submodule update --init tools/boost_install
- git submodule update --init libs/headers
- cp -r $TRAVIS_BUILD_DIR/* libs/preprocessor
- python tools/boostdep/depinst/depinst.py preprocessor
- ./bootstrap.sh
- ./b2 headers
script:
- TOOLSET=gcc,clang
- if [ $TRAVIS_OS_NAME == osx ]; then TOOLSET=clang; fi
- ./b2 libs/preprocessor/test toolset=$TOOLSET
- |-
echo "using $TOOLSET : : $COMPILER ;" > ~/user-config.jam
- ./b2 -j 3 libs/preprocessor/test toolset=$TOOLSET cxxstd=$CXXSTD
notifications:
email:

View File

@ -1,12 +1,25 @@
# Copyright 2018 Mike Dev
# Copyright 2019 Peter Dimov
# Distributed under the Boost Software License, Version 1.0.
# See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt
cmake_minimum_required(VERSION 3.5)
project(BoostPreprocessor LANGUAGES CXX)
cmake_minimum_required(VERSION 3.5...3.16)
project(boost_preprocessor VERSION "${BOOST_SUPERPROJECT_VERSION}" LANGUAGES CXX)
add_library(boost_preprocessor INTERFACE)
add_library(Boost::preprocessor ALIAS boost_preprocessor)
target_include_directories(boost_preprocessor INTERFACE include)
if(BOOST_SUPERPROJECT_VERSION)
include(BoostInstall)
boost_install(TARGETS boost_preprocessor HEADER_DIRECTORY include/)
endif()
if(BUILD_TESTING)
add_subdirectory(test)
endif()

View File

@ -1,5 +1,6 @@
# Copyright 2017 Edward Diener
# Copyright 2018 Mike Dev
# Copyright 2019 Peter Dimov
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or copy at http://boost.org/LICENSE_1_0.txt)
@ -8,13 +9,16 @@ version: 1.0.{build}-{branch}
shallow_clone: true
configuration:
- boost_test
- cmake_self_test
- boost_build_test
- cmake_test
- cmake_subdir_test
- cmake_install_test
branches:
only:
- master
- develop
- /feature\/.*/
environment:
matrix:
@ -22,41 +26,70 @@ environment:
TOOLSET: msvc-9.0,msvc-10.0,msvc-11.0,msvc-12.0,msvc-14.0
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
TOOLSET: msvc-14.1
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019
TOOLSET: msvc-14.2
matrix:
exclude:
- configuration: cmake_test
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
- configuration: cmake_test
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
build: off
install:
- set BOOST_BRANCH=develop
- if "%APPVEYOR_REPO_BRANCH%" == "master" set BOOST_BRANCH=master
- cd ..
- git clone -b %BOOST_BRANCH% --depth 1 https://github.com/boostorg/boost.git boost-root
- cd boost-root
- git submodule update --init tools/boostdep
- xcopy /s /e /q %APPVEYOR_BUILD_FOLDER% libs\preprocessor\
- python tools/boostdep/depinst/depinst.py preprocessor
for:
-
matrix:
only:
- configuration: cmake_self_test
- configuration: boost_build_test
test_script:
- mkdir __build__
- cd __build__
- cmake ../test
- cmake --build .
- bootstrap
- b2 -d0 headers
- b2 -j3 libs/preprocessor/test toolset=%TOOLSET%
-
matrix:
only:
- configuration: boost_test
install:
- cd ..
- git clone -b %APPVEYOR_REPO_BRANCH% https://github.com/boostorg/boost.git boost-root
- cd boost-root
- git submodule update --init tools/build
- git submodule update --init libs/config
- git submodule update --init tools/boostdep
- git submodule update --init tools/boost_install
- git submodule update --init libs/headers
- xcopy /s /e /q %APPVEYOR_BUILD_FOLDER% libs\preprocessor
- python tools/boostdep/depinst/depinst.py preprocessor
- bootstrap
- b2 headers
- configuration: cmake_test
test_script:
- b2 libs/preprocessor/test toolset=%TOOLSET%
- cd ../preprocessor/test
- mkdir __build__ && cd __build__
- cmake -DBOOST_ENABLE_CMAKE=1 -DBoost_VERBOSE=1 -DBOOST_INCLUDE_LIBRARIES=preprocessor ..
- ctest --output-on-failure -R boost_preprocessor -C Debug
-
matrix:
only:
- configuration: cmake_subdir_test
test_script:
- cd libs/preprocessor/test/cmake_subdir_test && mkdir __build__ && cd __build__
- cmake ..
- cmake --build .
- cmake --build . --target check
-
matrix:
only:
- configuration: cmake_install_test
test_script:
- mkdir __build__ && cd __build__
- cmake -DBOOST_ENABLE_CMAKE=1 -DBoost_VERBOSE=1 -DBOOST_INCLUDE_LIBRARIES=preprocessor -DCMAKE_INSTALL_PREFIX=C:/cmake-prefix ..
- cmake --build . --target install
- cd ../libs/preprocessor/test/cmake_install_test && mkdir __build__ && cd __build__
- cmake -DCMAKE_INSTALL_PREFIX=C:/cmake-prefix ..
- cmake --build .
- cmake --build . --target check

View File

@ -80,7 +80,7 @@
# if !defined BOOST_PP_VARIADICS
# /* variadic support explicitly disabled for all untested compilers */
# if defined __GCCXML__ || (defined __CUDACC__ && !(defined(__clang__) && defined(__CUDA__))) || defined __PATHSCALE__ || defined __DMC__ || defined __CODEGEARC__ || defined __BORLANDC__ || defined __MWERKS__ || ( defined __SUNPRO_CC && __SUNPRO_CC < 0x5120 ) || (defined __HP_aCC && !defined __EDG__) || defined __MRC__ || defined __SC__ || (defined(__PGI) && !defined(__EDG__))
# if defined __GCCXML__ || (defined __NVCC__ && defined __CUDACC__) || defined __PATHSCALE__ || defined __DMC__ || (defined __CODEGEARC__ && !defined(__clang__)) || (defined __BORLANDC__ && !defined(__clang__)) || defined __MWERKS__ || ( defined __SUNPRO_CC && __SUNPRO_CC < 0x5120 ) || (defined __HP_aCC && !defined __EDG__) || defined __MRC__ || defined __SC__ || (defined(__PGI) && !defined(__EDG__))
# define BOOST_PP_VARIADICS 0
# elif defined(_MSC_VER) && defined(__clang__)
# define BOOST_PP_VARIADICS 1
@ -103,7 +103,7 @@
# elif !BOOST_PP_VARIADICS + 1 < 2
# undef BOOST_PP_VARIADICS
# define BOOST_PP_VARIADICS 1
# if defined _MSC_VER && _MSC_VER >= 1400 && !defined(__clang__) && (defined(__INTELLISENSE__) || (defined(__INTEL_COMPILER) && __INTEL_COMPILER >= 1700) || !(defined __EDG__ || defined __GCCXML__ || defined __CUDACC__ || defined __PATHSCALE__ || defined __DMC__ || defined __CODEGEARC__ || defined __BORLANDC__ || defined __MWERKS__ || defined __SUNPRO_CC || defined __HP_aCC || defined __MRC__ || defined __SC__ || defined __IBMCPP__ || defined __PGI)) && (!defined(_MSVC_TRADITIONAL) || _MSVC_TRADITIONAL)
# if defined _MSC_VER && _MSC_VER >= 1400 && !defined(__clang__) && (defined(__INTELLISENSE__) || (defined(__INTEL_COMPILER) && __INTEL_COMPILER >= 1700) || !(defined __EDG__ || defined __GCCXML__ || (defined __NVCC__ && defined __CUDACC__) || defined __PATHSCALE__ || defined __DMC__ || defined __CODEGEARC__ || defined __BORLANDC__ || defined __MWERKS__ || defined __SUNPRO_CC || defined __HP_aCC || defined __MRC__ || defined __SC__ || defined __IBMCPP__ || defined __PGI)) && (!defined(_MSVC_TRADITIONAL) || _MSVC_TRADITIONAL)
# undef BOOST_PP_VARIADICS_MSVC
# define BOOST_PP_VARIADICS_MSVC 1
# endif

View File

@ -1,16 +1,33 @@
# Copyright 2018 Mike Dev
# Copyright 2018, 2019 Peter Dimov
# Distributed under the Boost Software License, Version 1.0.
# See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt
#
# NOTE: This does NOT run the unit tests for Boost.Preprocessor (yet).
# It only tests, if the CMakeLists.txt file works as expected
cmake_minimum_required( VERSION 3.5 )
include(BoostTest OPTIONAL RESULT_VARIABLE HAVE_BOOST_TEST)
project( BoostPreprocessorCMakeSelfTest )
if(NOT HAVE_BOOST_TEST)
return()
endif()
add_subdirectory( .. ${CMAKE_CURRENT_BINARY_DIR}/boost_preprocessor )
enable_language(C)
add_executable( boost_preprocessor_cmake_self_test config_info.cpp )
target_link_libraries( boost_preprocessor_cmake_self_test Boost::preprocessor )
set(tests_common arithmetic array comparison control debug facilities list logical punctuation selection seq slot stringize tuple variadic isempty)
set(tests_c ${tests_common})
set(tests_cpp ${tests_common} iteration repetition quick)
set(BOOST_TEST_LINK_LIBRARIES Boost::preprocessor)
include_directories(../../..) # for `include <libs/preprocessor/...>` to work
foreach(test IN LISTS tests_c)
boost_test(TYPE compile SOURCES ${test}.c)
boost_test(TYPE compile NAME ${test}_c_nvm SOURCES ${test}.c COMPILE_DEFINITIONS BOOST_PP_VARIADICS=0)
endforeach()
foreach(test IN LISTS tests_cpp)
boost_test(TYPE compile SOURCES ${test}.cpp)
boost_test(TYPE compile NAME ${test}_cpp_nvm SOURCES ${test}.cpp COMPILE_DEFINITIONS BOOST_PP_VARIADICS=0)
endforeach()

View File

@ -22,17 +22,17 @@ alias preprocessor : :
<toolset>gcc
<toolset-gcc:version>3.4
;
alias preprocessor : :
<toolset>gcc
<toolset-gcc:version>4.1
;
alias preprocessor : :
<toolset>gcc
<toolset-gcc:version>4.2
;
alias preprocessor
:
[ compile arithmetic.cpp ]
@ -192,22 +192,22 @@ alias preprocessor_c_nvm
: tuple_c_nvm
]
;
alias preprocessor_isempty : :
<toolset>gcc
<toolset-gcc:version>3.4
;
alias preprocessor_isempty : :
<toolset>gcc
<toolset-gcc:version>4.1
;
alias preprocessor_isempty : :
<toolset>gcc
<toolset-gcc:version>4.2
;
alias preprocessor_isempty
:
[ compile isempty.cpp ]
@ -216,12 +216,12 @@ alias preprocessor_isempty
[ compile-fail isempty_variadic_standard_failure2.cpp : <define>BOOST_PP_VARIADICS=1 ]
[ compile vaopt.cpp ]
;
alias preprocessor_isempty_nvm
:
[ compile isempty.cpp : <define>BOOST_PP_VARIADICS=0 : isempty_nvm ]
;
alias preprocessor_isempty_c
:
[ compile isempty.c
@ -237,7 +237,7 @@ alias preprocessor_isempty_c
: isempty_variadic_standard_failure2_c
]
;
alias preprocessor_isempty_c_nvm
:
[ compile isempty.c
@ -250,7 +250,7 @@ alias preprocessor_config
:
[ run config_info.cpp ]
;
alias test_clang_cuda
:
[ compile [ cast _ cpp : clang_cuda.cu ]
@ -262,3 +262,12 @@ alias test_clang_cuda
;
explicit test_clang_cuda ;
alias test_iso
:
[ run cpp_standard.cpp ]
;
explicit test_iso ;
explicit compile quick.cpp ; # "Quick" test (for CI)

View File

@ -0,0 +1,17 @@
# Copyright 2018, 2019 Peter Dimov
# Distributed under the Boost Software License, Version 1.0.
# See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt
cmake_minimum_required(VERSION 3.5...3.16)
project(cmake_install_test LANGUAGES CXX)
find_package(boost_preprocessor REQUIRED)
add_executable(quick ../quick.cpp)
target_link_libraries(quick Boost::preprocessor)
enable_testing()
add_test(quick quick)
add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure -C $<CONFIG>)

View File

@ -0,0 +1,17 @@
# Copyright 2018, 2019 Peter Dimov
# Distributed under the Boost Software License, Version 1.0.
# See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt
cmake_minimum_required(VERSION 3.5...3.16)
project(cmake_subdir_test LANGUAGES CXX)
add_subdirectory(../.. boostorg/preprocessor)
add_executable(quick ../quick.cpp)
target_link_libraries(quick Boost::preprocessor)
enable_testing()
add_test(quick quick)
add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure -C $<CONFIG>)

551
test/cpp_standard.cpp Normal file
View File

@ -0,0 +1,551 @@
#include <iostream>
#include <iomanip>
#include <string>
#include <boost/preprocessor/config/config.hpp>
static unsigned int indent = 4;
static unsigned int width = 90;
using std::cout;
using std::istream;
void print_separator()
{
std::cout <<
"\n\n*********************************************************************\n\n";
}
std::string remove_spaces(const std::string ss)
{
bool inquotes(false);
bool escape(false);
char qchar;
int len(static_cast<int>(ss.length()));
std::string ret;
for (int i = 0; i < len; ++i)
{
char ch(ss[i]);
if (inquotes)
{
if (escape)
{
escape = false;
}
else if (ch == '\\')
{
escape = true;
}
else if (ch == qchar)
{
inquotes = false;
}
ret.push_back(ch);
}
else
{
if (ch == '\'' || ch == '"')
{
inquotes = true;
qchar = ch;
ret.push_back(ch);
}
else if (ch != ' ')
{
ret.push_back(ch);
}
}
}
return ret;
}
int print_macro(const std::string name,const std::string expected, const std::string expansion)
{
int bret(0);
const std::string sg("Success: ");
const std::string sb("Failure: ");
for(unsigned i = 0; i < indent; ++i) std::cout.put(' ');
if (name == expansion)
{
if (expected == expansion)
{
std::cout << sg;
std::cout << std::setw(width);
cout.setf(istream::left, istream::adjustfield);
std::cout << name;
std::cout << " [no value]\n";
}
else
{
std::cout << sb;
std::cout << std::setw(width);
cout.setf(istream::left, istream::adjustfield);
std::cout << name;
std::cout << " [no value]: ";
std::cout << " [expected]: ";
std::cout << expected << "\n";
bret = 1;
}
}
else
{
std::string sexpected(remove_spaces(expected));
std::string sexpansion(remove_spaces(expansion));
if (sexpected == sexpansion)
{
std::cout << sg;
std::cout << std::setw(width);
cout.setf(istream::left, istream::adjustfield);
std::cout << name;
std::cout << expansion << "\n";
}
else
{
std::cout << sb;
std::cout << std::setw(width);
cout.setf(istream::left, istream::adjustfield);
std::cout << name;
std::cout << expansion;
std::cout << " [expected]: ";
std::cout << expected << "\n";
bret = 1;
}
}
return bret;
}
#if !BOOST_PP_VARIADICS
#define STRINGIZE(arg) # arg
#define PRINT_MACRO_RESULTS(X,exp) print_macro(std::string(# X), std::string(# exp), std::string(STRINGIZE(X)))
#define PRINT_MACRO(x) std::string(# x)
#define PRINT_EXPECTED(x) std::string(# x)
#define PRINT_EXPANSION(x) std::string(STRINGIZE(x))
#else
#define STRINGIZE(...) # __VA_ARGS__
#define PRINT_MACRO_RESULTS(X,...) print_macro(std::string(# X), std::string(# __VA_ARGS__), std::string(STRINGIZE(X)))
#define PRINT_MACRO(...) std::string(# __VA_ARGS__)
#define PRINT_EXPECTED(...) std::string(# __VA_ARGS__)
#define PRINT_EXPANSION(...) std::string(STRINGIZE(__VA_ARGS__))
#endif
#if __cplusplus > 201703L
int print_macros_common_c20()
{
int bret = 0;
#define LPAREN() (
#define G(Q) 42
#define F(R, X, ...) __VA_OPT__(G R X) )
// int x = F(LPAREN(), 0, <:-);
// replaced by
// int x = 42;
bret += PRINT_MACRO_RESULTS(int x = F(LPAREN(), 0, <:-);,int x = 42;);
#undef LPAREN
#undef G
#undef F
#define F(...) f(0 __VA_OPT__(,) __VA_ARGS__)
#define G(X, ...) f(0, X __VA_OPT__(,) __VA_ARGS__)
#define SDEF(sname, ...) S sname __VA_OPT__(= { __VA_ARGS__ })
#define EMP
// F(a, b, c)
// F()
// F(EMP)
// replaced by
// f(0, a, b, c)
// f(0)
// f(0)
// G(a, b, c)
// G(a, )
// G(a)
// replaced by
// f(0, a, b, c)
// f(0, a)
// f(0, a)
// SDEF(foo);
// SDEF(bar, 1, 2);
// replaced by
// S foo;
// S bar = { 1, 2 };
bret += PRINT_MACRO_RESULTS(F(a, b, c),f(0, a, b, c));
bret += PRINT_MACRO_RESULTS(F(),f(0));
bret += PRINT_MACRO_RESULTS(F(EMP),f(0));
bret += PRINT_MACRO_RESULTS(G(a, b, c),f(0, a, b, c));
bret += PRINT_MACRO_RESULTS(G(a, ),f(0, a));
bret += PRINT_MACRO_RESULTS(G(a),f(0, a));
bret += PRINT_MACRO_RESULTS(SDEF(foo);,S foo;);
bret += PRINT_MACRO_RESULTS(SDEF(bar, 1, 2);,S bar = { 1, 2 };);
#undef F
#undef G
#undef SDEF
#undef EMP
#define H2(X, Y, ...) __VA_OPT__(X ## Y,) __VA_ARGS__
#define H3(X, ...) #__VA_OPT__(X##X X##X)
#define H4(X, ...) __VA_OPT__(a X ## X) ## b
#define H5A(...) __VA_OPT__()/**/__VA_OPT__()
#define H5B(X) a ## X ## b
#define H5C(X) H5B(X)
// H2(a, b, c, d)
// replaced by
// ab, c, d
// H3(, 0)
// replaced by
// ""
// H4(, 1)
// replaced by
// a b
// H5C(H5A())
// replaced by
// ab
bret += PRINT_MACRO_RESULTS(H2(a, b, c, d),ab, c, d);
bret += PRINT_MACRO_RESULTS(H3(, 0),"");
bret += PRINT_MACRO_RESULTS(H4(, 1),a b);
bret += PRINT_MACRO_RESULTS(H5C(H5A()),ab);
#undef H2
#undef H3
#undef H4
#undef H5A
#undef H5B
#undef H5C
return bret;
}
#endif
int print_macros_common_1()
{
int bret = 0;
#define x 3
#define f(a) f(x * (a))
#undef x
#define x 2
#define g f
#define z z[0]
#define h g(~
#define m(a) a(w)
#define w 0,1
#define t(a) a
// f(y+1) + f(f(z)) % t(t(g)(0) + t)(1);
// g(x+(3,4)-w) | h 5) & m(f)^m(m);
// results in
// f(2 * (y+1)) + f(2 * (f(2 * (z[0])))) % f(2 * (0)) + t(1);
// f(2 * (2+(3,4)-0,1)) | f(2 * ( ~ 5)) & f(2 * (0,1))^m(0,1);
bret += PRINT_MACRO_RESULTS(f(y+1) + f(f(z)) % t(t(g)(0) + t)(1);,f(2 * (y+1)) + f(2 * (f(2 * (z[0])))) % f(2 * (0)) + t(1););
#define PRINT_INPUT g(x+(3,4)-w) | h 5) & m(f)^m(m);
bret += print_macro
(
std::string("g(x+(3,4)-w) | h 5) & m(f)^m(m);"),
PRINT_EXPECTED(f(2 * (2+(3,4)-0,1)) | f(2 * ( ~ 5)) & f(2 * (0,1))^m(0,1);),
PRINT_EXPANSION(PRINT_INPUT)
);
#undef PRINT_INPUT
#undef f
#undef x
#undef g
#undef z
#undef h
#undef m
#undef w
#undef t
return bret;
}
int print_macros_common_4()
{
int bret = 0;
#define str(s) # s
#define xstr(s) str(s)
#define debug(s, t) printf("x" # s "= %d, x" # t "= %s", x ## s, x ## t)
#define INCFILE(n) vers ## n
#define glue(a, b) a ## b
#define xglue(a, b) glue(a, b)
#define HIGHLOW "hello"
#define LOW LOW ", world"
// debug(1, 2);
// fputs(str(strncmp("abc\0d", "abc", <20>\4<>) // this goes away
// == 0) str(: @\n), s);
// #include xstr(INCFILE(2).h)
// glue(HIGH, LOW);
// xglue(HIGH, LOW)
// results in
// printf("x" "1" "= %d, x" "2" "= %s", x1, x2);
// fputs("strncmp(\"abc\\0d\", \"abc\", <20>\\4<>) == 0" ": @\n", s);
// #include "vers2.h" (after macro replacement, before file access)
// "hello";
// "hello" ", world"
bret += PRINT_MACRO_RESULTS(debug(1, 2);,printf("x" "1" "= %d, x" "2" "= %s", x1, x2););
bret += print_macro
(
std::string("fputs(str(strncmp(\"abc\\0d\", \"abc\", '\\4') /* this goes away */== 0) str(: @\\n), s);"),
PRINT_EXPECTED(fputs("strncmp(\"abc\\0d\", \"abc\", '\\4') == 0" ": @\n", s);),
PRINT_EXPANSION(fputs(str(strncmp("abc\0d", "abc", '\4') /* this goes away */== 0) str(: @\n), s);)
);
bret += PRINT_MACRO_RESULTS(xstr(INCFILE(2).h),"vers2.h");
bret += PRINT_MACRO_RESULTS(glue(HIGH, LOW);,"hello";);
#if __cplusplus <= 199711L
bret += print_macro
(
PRINT_MACRO(xglue(HIGH, LOW)),
std::string("\"hello\" \", world\""),
PRINT_EXPANSION(xglue(HIGH, LOW))
);
#else
bret += PRINT_MACRO_RESULTS(xglue(HIGH, LOW),"hello" ", world");
#endif
#undef str
#undef xstr
#undef debug
#undef INCFILE
#undef glue
#undef xglue
#undef HIGHLOW
#undef LOW
return bret;
}
int print_macros_common_2()
{
int bret = 0;
#define hash_hash # ## #
#define mkstr(a) # a
#define in_between(a) mkstr(a)
#define join(c, d) in_between(c hash_hash d)
// char p[] = join(x, y);
// equivalent to
// char p[] = "x ## y";
bret += PRINT_MACRO_RESULTS(char p[] = join(x, y);,char p[] = "x ## y";);
#undef hash_hash
#undef mkstr
#undef in_between
#undef join
return bret;
}
#if BOOST_PP_VARIADICS && __cplusplus > 199711L
int print_macros_common_3()
{
int bret = 0;
#define p() int
#define q(x) x
#define r(x,y) x ## y
#define str(x) # x
// p() i[q()] = { q(1), r(2,3), r(4,), r(,5), r(,) };
// char c[2][6] = { str(hello), str() };
// results in
// int i[] = { 1, 23, 4, 5, };
// char c[2][6] = { "hello", "" };
bret += print_macro
(
PRINT_MACRO(p() i[q()] = { q(1), r(2,3), r(4,), r(,5), r(,) };),
PRINT_EXPECTED(int i[] = { 1, 23, 4, 5, };),
PRINT_EXPANSION(p() i[q()] = { q(1), r(2,3), r(4,), r(,5), r(,) };)
);
bret += print_macro
(
PRINT_MACRO(char c[2][6] = { str(hello), str() };),
PRINT_EXPECTED(char c[2][6] = { "hello", "" };),
PRINT_EXPANSION(char c[2][6] = { str(hello), str() };)
);
#undef p
#undef q
#undef r
#undef str
bret += print_macros_common_4();
#define t(x,y,z) x ## y ## z
// int j[] = { t(1,2,3), t(,4,5), t(6,,7), t(8,9,), t(10,,), t(,11,), t(,,12), t(,,) };
// results in
// int j[] = { 123, 45, 67, 89, 10, 11, 12, };
bret += print_macro
(
PRINT_MACRO(int j[] = { t(1,2,3), t(,4,5), t(6,,7), t(8,9,), t(10,,), t(,11,), t(,,12), t(,,) };),
PRINT_EXPECTED(int j[] = { 123, 45, 67, 89, 10, 11, 12, };),
PRINT_EXPANSION(int j[] = { t(1,2,3), t(,4,5), t(6,,7), t(8,9,), t(10,,), t(,11,), t(,,12), t(,,) };)
);
#undef t
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define showlist(...) puts(#__VA_ARGS__)
#define report(test, ...) ((test) ? puts(#test) : printf(__VA_ARGS__))
// debug("Flag");
// debug("X = %d\n", x);
// showlist(The first, second, and third items.);
// report(x>y, "x is %d but y is %d", x, y);
// results in
// fprintf(stderr, "Flag");
// fprintf(stderr, "X = %d\n", x);
// puts("The first, second, and third items.");
// ((x>y) ? puts("x>y") : printf("x is %d but y is %d", x, y));
#define save_stderr stderr
#undef stderr
bret += PRINT_MACRO_RESULTS(debug("Flag");,fprintf(stderr, "Flag"););
bret += PRINT_MACRO_RESULTS(debug("X = %d\n", x);,fprintf(stderr, "X = %d\n", x););
#define stderr save_stderr
bret += PRINT_MACRO_RESULTS(showlist(The first, second, and third items.);,puts("The first, second, and third items."););
bret += PRINT_MACRO_RESULTS(report(x>y, "x is %d but y is %d", x, y);,((x>y) ? puts("x>y") : printf("x is %d but y is %d", x, y)););
#undef debug
#undef showlist
#undef report
return bret;
}
#endif
int print_macros()
{
int bret = 0;
print_separator();
std::cout << "__cplusplus = " << __cplusplus;
print_separator();
#define OBJ_LIKE (1-1)
#define OBJ_LIKE /* white space */ (1-1) /* other */
#define FTN_LIKE(a) ( a )
#define FTN_LIKE( a )( /* note the white space */ a /* other stuff on this line */ )
#if !BOOST_PP_VARIADICS
bret += print_macros_common_1();
bret += print_macros_common_4();
#elif __cplusplus <= 199711L
bret += print_macros_common_2();
bret += print_macros_common_1();
bret += print_macros_common_4();
#elif __cplusplus <= 201703L
bret += print_macros_common_2();
bret += print_macros_common_1();
bret += print_macros_common_3();
#else
bret += print_macros_common_c20();
bret += print_macros_common_2();
bret += print_macros_common_1();
bret += print_macros_common_3();
#endif
print_separator();
return bret;
}
int main()
{
return (print_macros());
}

43
test/quick.cpp Normal file
View File

@ -0,0 +1,43 @@
// Copyright 2002 Paul Mensonides
// Copyright 2019 Peter Dimov
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#include <boost/preprocessor/comparison.hpp>
#include "test_macro.h"
/* equality */
BEGIN BOOST_PP_EQUAL(2, 0) == 0 END
BEGIN BOOST_PP_EQUAL(2, 2) == 1 END
/* inequality */
BEGIN BOOST_PP_NOT_EQUAL(2, 0) == 1 END
BEGIN BOOST_PP_NOT_EQUAL(2, 2) == 0 END
/* less */
BEGIN BOOST_PP_LESS(2, 1) == 0 END
BEGIN BOOST_PP_LESS(1, 2) == 1 END
/* less_equal */
BEGIN BOOST_PP_LESS_EQUAL(2, 1) == 0 END
BEGIN BOOST_PP_LESS_EQUAL(1, 2) == 1 END
BEGIN BOOST_PP_LESS_EQUAL(2, 2) == 1 END
/* greater */
BEGIN BOOST_PP_GREATER(2, 1) == 1 END
BEGIN BOOST_PP_GREATER(1, 2) == 0 END
/* greater_equal */
BEGIN BOOST_PP_GREATER_EQUAL(2, 1) == 1 END
BEGIN BOOST_PP_GREATER_EQUAL(1, 2) == 0 END
BEGIN BOOST_PP_GREATER_EQUAL(2, 2) == 1 END
int main()
{
}