From 4582c3e595022773ac3c4e6603194621b18b8c7f Mon Sep 17 00:00:00 2001 From: BodgeMaster <> Date: Tue, 2 Aug 2022 00:41:11 +0200 Subject: [PATCH] test/nbt_helpers: move the test that aborts to its own program --- scripts/test.sh | 2 ++ src/test/nbt_helpers.cpp | 2 -- src/test/nbt_writestring_failure_mode.cpp | 16 ++++++++++++++++ 3 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 src/test/nbt_writestring_failure_mode.cpp diff --git a/scripts/test.sh b/scripts/test.sh index 1b7c304..21e1627 100755 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -34,6 +34,7 @@ COMPILE_COMMANDS=( "$CXX_WITH_FLAGS src/test/nbt_helpers.cpp -I./include -Lbin/lib -l:nbt.so -l:javacompat.so -o bin/test/nbt_helpers" "$CXX_WITH_FLAGS src/test/cli_argument_parser.cpp -Lbin/lib -l:cli.so -o bin/test/cli_argument_parser" "$CXX_WITH_FLAGS src/test/javacompat.cpp -I./include -Lbin/lib -l:javacompat.so -o bin/test/javacompat" + "$CXX_WITH_FLAGS src/test/nbt_writestring_failure_mode.cpp -I./include -Lbin/lib -l:nbt.so -l:javacompat.so -o bin/test/nbt_writestring_failure_mode" ) for command in ${!COMPILE_COMMANDS[@]}; do echo "${COMPILE_COMMANDS[command]}" @@ -45,6 +46,7 @@ wait echo "Running tests..." +set +e for test in $(ls bin/test); do bin/test/$test done diff --git a/src/test/nbt_helpers.cpp b/src/test/nbt_helpers.cpp index a7f4019..edcb82e 100644 --- a/src/test/nbt_helpers.cpp +++ b/src/test/nbt_helpers.cpp @@ -522,8 +522,6 @@ int main(){ NBT::helper::writeString(exportedString, normalString); ASSERT(javaStdString1 == *exportedString); - std::string overrunString = std::string(0xFFFFF, '.'); - NBT::helper::writeString(exportedString, tiny_utf8::string(overrunString)); std::cout << "Passed writeString NBT helper test." << std::endl; return 0; } diff --git a/src/test/nbt_writestring_failure_mode.cpp b/src/test/nbt_writestring_failure_mode.cpp new file mode 100644 index 0000000..ff846ca --- /dev/null +++ b/src/test/nbt_writestring_failure_mode.cpp @@ -0,0 +1,16 @@ +#include +#include +#include +#include "../lib/nbt.h++" +#include "../lib/error.h++" +#include "../lib/javacompat.h++" + +int main() { + std::cout << "=================================" << std::endl; + std::cout << "NBT write string helper failure mode test" << std::endl; + std::cout << "=================================" << std::endl; + std::cout << "This is supposed to abort." << std::endl; + std::vector* exportedString = new std::vector(); + std::string overrunString = std::string(0xFFFFF, '.'); + NBT::helper::writeString(exportedString, tiny_utf8::string(overrunString)); +}