Skip to content

Commit

Permalink
cpp: Prove broken exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
jenswet committed Jan 17, 2022
1 parent 95b5052 commit 7940cbe
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 0 deletions.
9 changes: 9 additions & 0 deletions tests/cpp_exception/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
include ../Makefile.tests_common

# If you want to add some extra flags when compile c++ files, add these flags
# to CXXEXFLAGS variable
CXXEXFLAGS += -std=c++11
FEATURES_REQUIRED += cpp

include $(RIOTBASE)/Makefile.include
deps: $(BUILDDEPS)
49 changes: 49 additions & 0 deletions tests/cpp_exception/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright (C) 2022 Jens Wetterich <[email protected]>
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/

/**
* @ingroup tests
* @{
* @file
* @brief Unit test to show the wrong behavior of c++ exceptions
* @author Jens Wetterich <[email protected]>
*/

#include <cstdio>
#include <stdexcept>
#include "test_utils/expect.h"

int main() {
puts("\n************ C++ exception test ***********");

bool enabled = false;

if(__EXCEPTIONS) {
puts("Exceptions enabled");
enabled = true;
} else {
puts("Exceptions disabled");
}

expect(enabled);

bool catched = false;

try {
throw std::runtime_error("Exception");
} catch(std::exception& e) {
catched = true;
printf("%s catched\n", e.what());
}

expect(catched);

puts("******************************************");

return 0;
}
21 changes: 21 additions & 0 deletions tests/cpp_exception/tests/01-run.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env python3

# Copyright (C) 2022 Jens Wetterich <[email protected]>
#
# This file is subject to the terms and conditions of the GNU Lesser
# General Public License v2.1. See the file LICENSE in the top level
# directory for more details.

import sys
from testrunner import run


def testfunc(child):
child.expect_exact("************ C++ exception test ***********")
child.expect_exact("Exceptions enabled")
child.expect_exact("Exception catched")
child.expect_exact("******************************************")


if __name__ == "__main__":
sys.exit(run(testfunc))

0 comments on commit 7940cbe

Please sign in to comment.