Skip to content

Instantly share code, notes, and snippets.

@Quiark
Last active January 19, 2016 04:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Quiark/7924bfc88c0f1d9a8aad to your computer and use it in GitHub Desktop.
Save Quiark/7924bfc88c0f1d9a8aad to your computer and use it in GitHub Desktop.
Emscripten exception bug
#!/bin/sh
FLAGS='-Wall -pedantic -std=c++11 -m32 -O0'
echo Compiling Emscripten...
mkdir -p emcc
/usr/local/opt/emscripten/libexec/em++ -o emcc/run.o $FLAGS -c -s DISABLE_EXCEPTION_CATCHING=0 -D_EXPORTING -D_REENTRANT -Isrc -Ithirdparty run.cpp
/usr/local/opt/emscripten/libexec/em++ -o emcc/tests_run.html $FLAGS -s DISABLE_EXCEPTION_CATCHING=0 emcc/run.o
echo Compiling native...
mkdir -p build
g++ -o build/run.o $FLAGS -c -D_EXPORTING -D_REENTRANT -Isrc -Ithirdparty run.cpp
g++ -o build/tests_run $FLAGS build/run.o
echo Running Emscripten...
node emcc/tests_run.js [blah]
echo Running native...
build/tests_run [blah]
/**
* This is the main test runner file for tests
*/
#include <iostream>
#include <stdio.h>
struct AssertionInfo
{
AssertionInfo() {}
AssertionInfo( std::string const& _macroName,
std::string const& _capturedExpression,
int _resultDisposition );
std::string macroName;
std::string capturedExpression;
int resultDisposition;
};
class Before {
public:
Before( char const* macroName,
char const* capturedExpression,
int resultDisposition)
{
}
bool allow() { return true; }
void capture() {}
static bool alwaysFalse() { return false; }
AssertionInfo m_assertionInfo;
};
#define MY_INTERNAL_CATCH_THROWS_AS( expr, exceptionType, resultDisposition, macroName ) \
do { \
Before bef( macroName, #expr, resultDisposition); \
if( bef.allow() ) { \
try { \
expr; \
bef.capture(); \
} \
catch( exceptionType ) { \
printf("- Caught expected\n"); \
bef.capture(); \
} \
catch( ... ) { \
printf("- Caught different\n"); \
bef.capture(); \
} } \
else { clock(); } \
} while( Before::alwaysFalse() )
#define MY_REQUIRE_THROWS_AS( expr, exceptionType ) MY_INTERNAL_CATCH_THROWS_AS( expr, exceptionType, 1, "CATCH_REQUIRE_THROWS_AS" )
void do_throw2() {
throw std::runtime_error("runtime_error() thrown");
}
void runtest() {
printf("- Blah starting\n");
MY_REQUIRE_THROWS_AS(
do_throw2(),
std::runtime_error
);
}
int main( int argc, char* argv[] ) {
runtest();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment