Skip to content

Commit

Permalink
Merge pull request #5 from UCBoulder/dev
Browse files Browse the repository at this point in the history
Release: 0.8.0
  • Loading branch information
NateAM authored Apr 2, 2024
2 parents ae46e25 + 063ab9f commit 08bc2c2
Show file tree
Hide file tree
Showing 5 changed files with 139 additions and 8 deletions.
62 changes: 62 additions & 0 deletions .github/workflows/github-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: Tests on pull request
run-name: ${{ github.actor }} is testing a pull request
on:
pull_request:
types:
- opened
- edited
- synchronize
branches:
- dev
- main
jobs:
build:
runs-on: ${{ matrix.os }}

strategy:
# Set fail-fast to false to ensure that feedback is delivered for all matrix combinations. Consider changing this to true when your workflow is stable.
fail-fast: false
matrix:
os: [ubuntu-latest]
build_type: [Release]
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: MiniConda setup
uses: conda-incubator/setup-miniconda@v2
with:
miniforge-variant: Mambaforge
channels: conda-forge,defaults
channel-priority: true
auto-activate-base: false
activate-environment: "test-environment"
- name: check solution
run: |
conda env export
- name: Set reusable strings
id: strings
shell: bash
run: |
echo "build-output-dir=${{ github.workspace }}/build" >> "$GITHUB_OUTPUT"
echo "environment-file=${{ github.workspace }}/environment.txt" >> "$GITHUB_OUTPUT"
echo "moose-dir=${{ github.workspace }}/moose-dir" >> "$GITHUB_OUTPUT"
- name: Conda environment
shell: bash -el {0}
run: |
mamba install --file ${{ steps.strings.outputs.environment-file }} --yes --channel conda-forge
- name: Build
shell: bash -el {0}
run: |
mkdir build
cd build
cmake ..
make
- name: Test
shell: bash -el {0}
# working-directory: ${{ steps.strings.outputs.build-output-dir }}
run: |
conda activate test-environment
cd build
ctest
12 changes: 11 additions & 1 deletion docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,19 @@ Changelog
#########

******************
0.7.3 (unreleased)
0.8.0 (2024-04-02)
******************

New Features
============
- Added a catch function to replace the if statement pattern (:pull:`2`). By `Nathan Miller`_.
- Added parenthesis to the catch function to try and prevent issues (:pull:`3`). By `Nathan Miller`_.
- Added a function to capture the error message in a standard string (:pull:`4`). By `Nathan Miller`_.

Breaking Changes
================
- Changed the printNestedExceptions interface to only accept the exception and a header message. This will affect almost no-one but it is breaking (:pull:`4`). By `Nathan Miller`_.

******************
0.7.2 (2023-09-27)
******************
Expand Down
25 changes: 19 additions & 6 deletions src/cpp/tardigrade_error_tools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,11 @@ namespace tardigradeErrorTools{
return;
}

void printNestedExceptions( const std::exception &e, std::size_t depth, std::string message){
void captureNestedExceptions( const std::exception &e, std::string &message, std::size_t depth ){
/*!
* Print the nested exceptions starting with the one deepest (closest to the error) and ending
* with the outermost function call. Users should call this function by just passing in the
* exception. The other arguments are for recursion.
* Capture the nested exceptions starting with the one deepest (closest to the error) and ending
* with the outermost function call. Users should typically call this function by just passing in the
* exception and a std::string for the message. The depth is for recursion.
*
* \param &e: The nested exceptions
* \param depth: The current depth (defaults to zero)
Expand All @@ -94,14 +94,27 @@ namespace tardigradeErrorTools{
try {

std::rethrow_if_nested( e );
std::cerr << message;

}
catch ( const std::exception &nested ){

printNestedExceptions( nested, depth + 1, message );
captureNestedExceptions( nested, message, depth + 1 );

}
}

void printNestedExceptions( const std::exception &e, std::string message ){
/*!
* Print the nested exceptions starting with the one deepest (closest to the error) and ending
* with the outermost function call. Users should call this function by just passing in the
* exception.
*
* \param &e: The nested exceptions
* \param message: The output message (defaults to "")
*/

captureNestedExceptions( e, message );
std::cerr << message;
}

}
24 changes: 23 additions & 1 deletion src/cpp/tardigrade_error_tools.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,26 @@
*/
#define TARDIGRADE_ERROR_TOOLS_CATCH_NODE_POINTER(expr) TARDIGRADE_ERROR_TOOLS_CATCH_NODE_POINTER_INTERNAL(expr, __func__, __LINE__, __FILE__)

/*!
\brief A macro to check for issues that we want to throw an exception if a condition isn't met
\param condition: An expression that evaluates as a boolean
\param error_message: The output message if it fails
\param func: A standard string or char function name
\param line: The integer filename
\param file: A standard string or char filename
*/
#define TARDIGRADE_ERROR_TOOLS_CHECK_INTERNAL(condition, error_message, func, line, file) \
if ( ! ( condition ) ){ \
TARDIGRADE_ERROR_TOOLS_CATCH(throw std::runtime_error(error_message) ) \
} \

/*!
\brief A macro to check for issues that we want to throw an exception if a condition isn't met
\param condition: An expression that evaluates as a boolean
\param error_message: The output message if it fails
*/
#define TARDIGRADE_ERROR_TOOLS_CHECK(condition, error_message) TARDIGRADE_ERROR_TOOLS_CHECK_INTERNAL(condition, error_message, __func__, __LINE__, __FILE__)


namespace tardigradeErrorTools{

Expand Down Expand Up @@ -141,7 +161,9 @@ namespace tardigradeErrorTools{
void print( const bool header = true );
};

void printNestedExceptions( const std::exception &e, std::size_t depth = 0, std::string message = "");
void captureNestedExceptions( const std::exception &e, std::string &message, std::size_t depth = 0);

void printNestedExceptions( const std::exception &e, std::string message = "" );

}

Expand Down
24 changes: 24 additions & 0 deletions src/cpp/tests/test_tardigrade_error_tools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,3 +232,27 @@ BOOST_AUTO_TEST_CASE( test_form_node_stacktrace ){
BOOST_CHECK( !result.is_empty( ) );

}

void runCheck( const bool condition ){
TARDIGRADE_ERROR_TOOLS_CHECK(condition, "mymessage")
}

BOOST_AUTO_TEST_CASE( test_tardigrade_error_tools_check ){

boost::test_tools::output_test_stream result;

//Initialize test variables
cerr_redirect guard( result.rdbuf( ) );

BOOST_CHECK_NO_THROW( runCheck( true ) );

try{
TARDIGRADE_ERROR_TOOLS_CATCH( runCheck( false ) );
}
catch( std::exception &e ){
tardigradeErrorTools::printNestedExceptions( e );
}

BOOST_CHECK( !result.is_empty( ) );

}

0 comments on commit 08bc2c2

Please sign in to comment.