#!/bin/sh
# Build and run a small program against the installed SDK using the
# CMake package configuration shipped in libsentry-dev.
set -eu

WORKDIR=$(mktemp -d)
trap 'rm -rf "$WORKDIR"' EXIT
cd "$WORKDIR"

cat > CMakeLists.txt <<'CMAKE'
cmake_minimum_required(VERSION 3.10)
project(sentry_autopkgtest C)
find_package(sentry REQUIRED)
add_executable(sentry_autopkgtest main.c)
target_link_libraries(sentry_autopkgtest PRIVATE sentry::sentry)
CMAKE

cat > main.c <<'C'
#include <sentry.h>
#include <stdio.h>
#include <string.h>

int
main(void)
{
    sentry_options_t *options = sentry_options_new();
    sentry_options_set_dsn(options, "http://key@127.0.0.1:1/42");
    sentry_options_set_database_path(options, ".sentry-native");
    sentry_options_set_transport(options, NULL);
    if (sentry_init(options) != 0) {
        return 1;
    }
    sentry_set_tag("test", "autopkgtest");
    sentry_add_breadcrumb(sentry_value_new_breadcrumb("default", "hello"));
    sentry_capture_event(sentry_value_new_message_event(
        SENTRY_LEVEL_INFO, "autopkgtest", "hello from autopkgtest"));
    sentry_close();
    printf("sentry %s ok\n", sentry_sdk_version());
    return strcmp(sentry_sdk_version(), SENTRY_SDK_VERSION) != 0;
}
C

cmake -S . -B build
cmake --build build
./build/sentry_autopkgtest
