blob: 25c00896520d0db1289cb8cd2b4c5106481f708e [file] [log] [blame]
Brian Silvermana6f7ce02018-07-07 15:04:00 -07001///////////////////////////////////////////////////////////////////////////////
2//
3// Copyright (c) 2015 Microsoft Corporation. All rights reserved.
4//
5// This code is licensed under the MIT License (MIT).
6//
7// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
8// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
9// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
10// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
11// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
12// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
13// THE SOFTWARE.
14//
15///////////////////////////////////////////////////////////////////////////////
16
17#include <catch/catch.hpp> // for AssertionHandler, StringRef, CHECK, CHECK...
18
19#include <gsl/gsl_assert> // for fail_fast (ptr only), Ensures, Expects
20
21using namespace gsl;
22
23int f(int i)
24{
25 Expects(i > 0 && i < 10);
26 return i;
27}
28
29TEST_CASE("expects")
30{
31 CHECK(f(2) == 2);
32 CHECK_THROWS_AS(f(10), fail_fast);
33}
34
35int g(int i)
36{
37 i++;
38 Ensures(i > 0 && i < 10);
39 return i;
40}
41
42TEST_CASE("ensures")
43{
44 CHECK(g(2) == 3);
45 CHECK_THROWS_AS(g(9), fail_fast);
46}