name: run address sanitizer
on:
  push:
    branches: [master]
  pull_request:
    branches: [master]
jobs:
  Matrix-build:
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        os: [ubuntu-latest]
        python-version: [3.13]  # Could add more here, but it just makes the build matrix bigger
    steps:
      - name: checkout
        uses: actions/checkout@v4
      - name: Build REFPROP
        shell: bash
        run: |
          set -x
          cd .github/workflows
          chmod +x buildREFPROP.sh
          ./buildREFPROP.sh
          echo COOLPROP_REFPROP_ROOT=`pwd`/gpgREFPROP/REFPROP-cmake/bld >> $GITHUB_ENV
        env:
          REFPROP_GPG_PASSPHRASE: ${{ secrets.REFPROP_GPG_PASSPHRASE }}
      - name: checkout submodules
        run: git submodule update --init --recursive
      - name: mkdir
        run: mkdir build && cd build
      - name: cmake config
        run: cd build && CXX=clang++ cmake .. -DCMAKE_BUILD_TYPE=Asan -DCOOLPROP_ASAN=ON -DCOOLPROP_CATCH_MODULE=ON
      - name: build all Catch tests
        run: cmake --build build --config Asan
      # You can use tmate to log into the running container, which helps to debug paths...
      - name: run all the compiled Catch tests with address sanitizer
        run: cd build && ASAN_OPTIONS=detect_stack_use_after_return=1:verbosity=1 ASAN_SYMBOLIZER_PATH=/usr/bin/llvm-symbolizer-18 ./CatchTestRunner --benchmark-samples 1
        # ASAN CLI docs here: https://github.com/google/sanitizers/wiki/AddressSanitizerFlags
