Skip to content

Commit

Permalink
Attempt to use c++23's stacktrace. Maybe it works on clang-18 or gcc-14
Browse files Browse the repository at this point in the history
  • Loading branch information
ViliusSutkus89 committed Sep 2, 2024
1 parent a2375c0 commit 43c0155
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 37 deletions.
20 changes: 10 additions & 10 deletions .github/workflows/build_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
fail-fast: false
matrix:
include:
# - { os: ubuntu-24.04, compiler: clang-18 }
- { os: ubuntu-24.04, compiler: clang-18 }
- { os: ubuntu-24.04, compiler: gcc-14 }
# - { os: macos-13, compiler: clang-14 }
# - { os: macos-14, compiler: armv8-clang-14 }
Expand Down Expand Up @@ -50,7 +50,7 @@ jobs:
- name: conan config
run: conan config install .github/config/${{ matrix.os }}-${{ matrix.compiler }}/conan
- name: conan install
run: conan install . --output-folder=build --build=missing -s build_type=Debug
run: conan install . --output-folder=build --build=never

- name: cache
uses: actions/cache@v4
Expand All @@ -68,7 +68,7 @@ jobs:
cmake -B build -S .
-DCMAKE_TOOLCHAIN_FILE="conan_toolchain.cmake"
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache
-DCMAKE_BUILD_TYPE=Debug
-DCMAKE_BUILD_TYPE=Release
-DCMAKE_CXX_FLAGS="-Werror"
-DCMAKE_INSTALL_PREFIX=install
-DODR_TEST=ON
Expand All @@ -79,15 +79,15 @@ jobs:
cmake -B build -S .
-DCMAKE_TOOLCHAIN_FILE="conan_toolchain.cmake"
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache
-DCMAKE_BUILD_TYPE=Debug
-DCMAKE_BUILD_TYPE=Release
-DCMAKE_INSTALL_PREFIX=install
-DODR_TEST=ON
- name: build
run: cmake --build build --config Debug
run: cmake --build build --config Release

- name: install
run: cmake --build build --target install --config Debug
run: cmake --build build --target install --config Release

- name: upload binaries to github
uses: actions/upload-artifact@v4
Expand All @@ -96,7 +96,7 @@ jobs:
path: |
install
build/test/odr_test
build/test/Debug/odr_test.exe
build/test/Release/odr_test.exe
docker:
if: false
Expand Down Expand Up @@ -163,7 +163,7 @@ jobs:
fail-fast: false
matrix:
include:
# - { os: ubuntu-24.04, compiler: clang-18 }
- { os: ubuntu-24.04, compiler: clang-18 }
- { os: ubuntu-24.04, compiler: gcc-14 }
# - { os: macos-13, compiler: clang-14 }
# - { os: macos-14, compiler: armv8-clang-14 }
Expand Down Expand Up @@ -208,11 +208,11 @@ jobs:

- name: fix artifact permissions
if: runner.os == 'Windows'
run: chmod +x build/test/Debug/odr_test.exe
run: chmod +x build/test/Release/odr_test.exe
- name: test
if: runner.os == 'Windows'
working-directory: build/test
run: ./Debug/odr_test.exe
run: ./Release/odr_test.exe

- name: tidy public test outputs
run: python3 -u test/scripts/tidy_output.py build/test/output/odr-public/output
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.15)

project(odr LANGUAGES C CXX)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

Expand Down
32 changes: 6 additions & 26 deletions test/src/pdf2htmlEX_wrapper_test.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <execinfo.h>
#include <filesystem>
#include <iostream>
#include <optional>
#include <stacktrace>
#include <string>

#include <gtest/gtest.h>
Expand All @@ -20,17 +20,6 @@ namespace fs = std::filesystem;

using pdf2htmlEXWrapperTests = ::testing::TestWithParam<std::string>;

static void print_backtrace() {
void *array[10];
int size = backtrace(array, 10);
char **symbols = backtrace_symbols(array, size);
for (int i = 0; i < size; i++) {
std::cerr << symbols[i] << std::endl;
}
free(symbols);
std::cerr << std::flush;
}

TEST_P(pdf2htmlEXWrapperTests, html) {
const std::string test_file_path = GetParam();
const TestFile test_file = TestData::test_file(test_file_path);
Expand Down Expand Up @@ -62,28 +51,19 @@ TEST_P(pdf2htmlEXWrapperTests, html) {

std::cout << "Calling pdf2htmlEX_wrapper" << std::endl << std::flush;
try {
std::this_thread::set_capture_stacktraces_at_throw(true);
Html html = odr::internal::html::pdf2htmlEX_wrapper(
test_file.path, output_path, config, password);
std::cout << "Returned from pdf2htmlEX_wrapper" << std::endl << std::flush;
for (const HtmlPage &html_page : html.pages()) {
EXPECT_TRUE(fs::is_regular_file(html_page.path));
EXPECT_LT(0, fs::file_size(html_page.path));
}
} catch (const std::exception &e) {
std::cerr << "Exception in pdf2htmlEX_wrapper: " << std::endl
<< e.what() << std::endl
<< std::flush;
print_backtrace();
throw e;
} catch (const std::string &e) {
std::cerr << "Exception in pdf2htmlEX_wrapper: " << std::endl
<< e << std::endl
<< std::flush;
print_backtrace();
throw e;
} catch (...) {
std::cerr << "Exception in pdf2htmlEX_wrapper!" << std::endl << std::flush;
print_backtrace();
std::stacktrace trace = std::stacktrace::from_current_exception();
std::cerr << "Exception in pdf2htmlEX_wrapper!" << std::endl;
std::cerr << trace << std::endl << std::flush;

throw std::runtime_error("Unexpected error");
}
std::cerr << "End of test" << std::endl << std::flush;
Expand Down

0 comments on commit 43c0155

Please sign in to comment.