This commit is contained in:
Treb Connell 2015-09-24 15:55:19 -07:00
commit 8007df439f
6 changed files with 138 additions and 17 deletions

67
.travis.yml Normal file
View File

@ -0,0 +1,67 @@
# Based on https://github.com/ldionne/hana/blob/master/.travis.yml
language: cpp
sudo: false
matrix:
include:
- env: COMPILER=clang++-3.6 BUILD_TYPE=Debug CLANG=1
compiler: clang
addons: &clang36
apt:
packages:
- clang-3.6
- cmake
sources: &sources
- ubuntu-toolchain-r-test
- llvm-toolchain-precise-3.6
- kalakris-cmake
- env: COMPILER=clang++-3.6 BUILD_TYPE=Release CLANG=1
compiler: clang
addons: *clang36
- env: COMPILER=g++-5 BUILD_TYPE=Debug
compiler: gcc
addons: &gcc5
apt:
packages: g++-5
sources: *sources
- env: COMPILER=g++-5 BUILD_TYPE=Release
compiler: gcc
addons: *gcc5
install:
- which $COMPILER
- DEPS_DIR="${TRAVIS_BUILD_DIR}/deps"
- mkdir ${DEPS_DIR} && cd ${DEPS_DIR}
- |
if [[ "$CLANG" == 1 && "${TRAVIS_OS_NAME}" == "linux" && "${STDLIB}" != "libstdc++" ]]; then
if [[ "${COMPILER}" == "clang++-3.5" ]]; then LLVM_VERSION="3.5.2"; fi
if [[ "${COMPILER}" == "clang++-3.6" ]]; then LLVM_VERSION="3.6.2"; fi
if [[ "${COMPILER}" == "clang++-3.7" ]]; then LLVM_VERSION="3.7.0"; fi
LLVM_URL="http://llvm.org/releases/${LLVM_VERSION}/llvm-${LLVM_VERSION}.src.tar.xz"
LIBCXX_URL="http://llvm.org/releases/${LLVM_VERSION}/libcxx-${LLVM_VERSION}.src.tar.xz"
LIBCXXABI_URL="http://llvm.org/releases/${LLVM_VERSION}/libcxxabi-${LLVM_VERSION}.src.tar.xz"
mkdir -p llvm llvm/build llvm/projects/libcxx llvm/projects/libcxxabi
travis_retry wget --quiet -O - ${LLVM_URL} | tar --strip-components=1 -xJ -C llvm
travis_retry wget --quiet -O - ${LIBCXX_URL} | tar --strip-components=1 -xJ -C llvm/projects/libcxx
travis_retry wget --quiet -O - ${LIBCXXABI_URL} | tar --strip-components=1 -xJ -C llvm/projects/libcxxabi
(cd llvm/build && cmake .. -DCMAKE_INSTALL_PREFIX=${DEPS_DIR}/llvm/install -DCMAKE_CXX_COMPILER=clang++)
(cd llvm/build/projects/libcxx && make install -j2)
(cd llvm/build/projects/libcxxabi && make install -j2)
export CXXFLAGS="-I ${DEPS_DIR}/llvm/install/include/c++/v1"
export LDFLAGS="-L ${DEPS_DIR}/llvm/install/lib -l c++ -l c++abi"
export LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:${DEPS_DIR}/llvm/install/lib"
fi
before_script:
- cd ${TRAVIS_BUILD_DIR}
- git clone --depth 1 https://github.com/Microsoft/unittest-cpp tests/unittest-cpp
- cmake -H. -Bb -DCMAKE_CXX_COMPILER=$COMPILER -DCMAKE_INSTALL_PREFIX=$PWD/o -DCMAKE_BUILD_TYPE=$BUILD_TYPE
- cmake --build b
script:
- cd b
- ctest
notifications:
email: false

View File

@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.2.2) cmake_minimum_required(VERSION 2.8.7)
project(GSL) project(GSL CXX)
include_directories( include_directories(
${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}

View File

@ -1,4 +1,4 @@
# GSL: Guidelines Support Library # GSL: Guidelines Support Library [![Build Status](https://travis-ci.org/Microsoft/GSL.svg?branch=master)](https://travis-ci.org/Microsoft/GSL)
The Guidelines Support Library (GSL) contains functions and types that are suggested for use by the The Guidelines Support Library (GSL) contains functions and types that are suggested for use by the
[C++ Core Guidelines](https://github.com/isocpp/CppCoreGuidelines) maintained by the [Standard C++ Foundation](https://isocpp.org). [C++ Core Guidelines](https://github.com/isocpp/CppCoreGuidelines) maintained by the [Standard C++ Foundation](https://isocpp.org).
@ -33,7 +33,7 @@ contributing any changes that were necessary back to this project to benefit the
## Building the tests ## Building the tests
To build the tests, you will require the following: To build the tests, you will require the following:
* [CMake](http://cmake.org), version 3.3 or later to be installed and in your PATH. * [CMake](http://cmake.org), version 2.8.7 or later to be installed and in your PATH.
* [UnitTest-cpp](https://github.com/Microsoft/unittest-cpp), to be cloned under the [tests/unittest-cpp](./tests/unittest-cpp) directory * [UnitTest-cpp](https://github.com/Microsoft/unittest-cpp), to be cloned under the [tests/unittest-cpp](./tests/unittest-cpp) directory
of your GSL source. of your GSL source.

View File

@ -205,6 +205,8 @@ public:
bool operator==(const T& rhs) const { tested_ = true; return ptr_ == rhs; } bool operator==(const T& rhs) const { tested_ = true; return ptr_ == rhs; }
bool operator!=(const T& rhs) const { return !(*this == rhs); } bool operator!=(const T& rhs) const { return !(*this == rhs); }
bool operator==(const maybe_null_dbg& rhs) const { tested_ = true; rhs.tested_ = true; return ptr_ == rhs.ptr_; }
bool operator!=(const maybe_null_dbg& rhs) const { return !(*this == rhs); }
T get() const { T get() const {
fail_fast_assert(tested_); fail_fast_assert(tested_);

View File

@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.2.2) cmake_minimum_required(VERSION 2.8.7)
project(GSLTests) project(GSLTests CXX)
add_subdirectory(unittest-cpp) add_subdirectory(unittest-cpp)
@ -23,7 +23,7 @@ else()
elseif(COMPILER_SUPPORTS_CXX11) elseif(COMPILER_SUPPORTS_CXX11)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
else() else()
message(STATUS "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.") message(STATUS "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.")
endif() endif()
endif() endif()
@ -38,8 +38,8 @@ function(add_gsl_test name)
RUNTIME DESTINATION bin RUNTIME DESTINATION bin
) )
add_test( add_test(
NAME ${name} ${name}
COMMAND ${name} ${name}
) )
endfunction() endfunction()

View File

@ -189,6 +189,58 @@ SUITE(MaybeNullTests)
CHECK(q.present()); CHECK(q.present());
CHECK(q->foo()); CHECK(q->foo());
} }
TEST(TestMaybeNullCompare)
{
int i1 = 1;
int i2 = 2;
maybe_null_dbg<int*> p1 = &i1;
maybe_null_dbg<int*> p1_2 = &i1;
maybe_null_dbg<int*> p2 = &i2;
CHECK_THROW(p1.get(), fail_fast);
CHECK_THROW(p1_2.get(), fail_fast);
CHECK_THROW(p2.get(), fail_fast);
CHECK(p1 != p2);
CHECK(!(p1 == p2));
CHECK(p1 == p1);
CHECK(p1 == p1_2);
// Make sure we no longer throw here
CHECK(p1.get() != nullptr);
CHECK(p1_2.get() != nullptr);
CHECK(p2.get() != nullptr);
}
TEST(TestMaybeNullCopy)
{
int i1 = 1;
int i2 = 2;
maybe_null_dbg<int*> p1 = &i1;
maybe_null_dbg<int*> p1_2 = &i1;
maybe_null_dbg<int*> p2 = &i2;
CHECK(p1 != p2);
CHECK(p1 == p1_2);
// Make sure we no longer throw here
CHECK(p1.get() != nullptr);
CHECK(p2.get() != nullptr);
p1 = p2;
// Make sure we now throw
CHECK_THROW(p1.get(), fail_fast);
CHECK(p1 == p2);
CHECK(p1 != p1_2);
// Make sure we no longer throw here
CHECK(p1.get() != nullptr);
}
} }
int main(int, const char *[]) int main(int, const char *[])