#!/bin/sh
# Build and run a small program against the installed library, using
# only the compiler flags reported by pkg-config.
set -eu

cd "${AUTOPKGTEST_TMP:-$(mktemp -d)}"

cat > test.c <<'END'
#include <stdio.h>
#include <xlsxwriter.h>

int main(void)
{
    lxw_workbook *workbook = workbook_new("test.xlsx");
    lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);
    lxw_error error;

    worksheet_write_string(worksheet, 0, 0, "Hello", NULL);
    worksheet_write_number(worksheet, 1, 0, 123, NULL);

    error = workbook_close(workbook);
    if (error != LXW_NO_ERROR) {
        fprintf(stderr, "workbook_close: %s\n", lxw_strerror(error));
        return 1;
    }
    printf("libxlsxwriter %s\n", LXW_VERSION);
    return 0;
}
END

pkg-config --cflags --libs xlsxwriter
# shellcheck disable=SC2046
gcc -Wall -Werror -o test test.c $(pkg-config --cflags --libs xlsxwriter)
./test

# An XLSX file is a ZIP archive.
test "$(head -c 2 test.xlsx)" = "PK"
echo "test.xlsx: $(wc -c < test.xlsx) bytes"
