#!/bin/sh
set -e

if [ -z "$AUTOPKGTEST_TMP" ]; then
    AUTOPKGTEST_TMP=$(mktemp -d)
    trap 'rm -rf "$AUTOPKGTEST_TMP"' EXIT INT TERM
fi

cp "$(dirname "$0")/smoke.cpp" "$AUTOPKGTEST_TMP/"
cd "$AUTOPKGTEST_TMP"

cat > smoke.gfa <<GFA
H	VN:Z:1.1
S	1	CAAATAAG
S	2	A
S	3	G
L	1	+	2	+	0M
L	2	+	3	+	0M
P	path	1+,2+,3+	*
GFA

# Command line tool: index a GFA and read the index back as GFA.
xg -g smoke.gfa -o smoke.xg
xg -i smoke.xg -G | grep -q '^S'

# Library: build an xg graph from the GFA, serialize and load it again.
# Note: must be C++17+, since the library heap-allocates an over-aligned
# mmmulti map and relies on C++17 aligned new.
g++ -std=c++17 -O2 -Wall -Wextra -fopenmp -o smoke smoke.cpp \
    -lxg -lsdsl -lhandlegraph -ldivsufsort -ldivsufsort64
ldd ./smoke | grep -q 'libxg\.so'
./smoke
