#!/bin/sh

set -eu

pwd=$(pwd -P)
cd "@builddir@"
npwd=$(pwd -P)

if test "$pwd" != "$npwd"; then
    echo "This script should be run from the build directory (@builddir@)"
    printf "Press ENTER to continue anyway"
    read -r _
fi

# Initialize.
rm -f x u get_config_unittest_rebuild.cc
cp -f "@skeleton@" get_config_unittest_rebuild.cc
rm -f kea-dhcp4-tests-extract
echo "Please recompile kea-dhcp4-tests-extract"
printf "Press ENTER when ready"
read -r _

# Extract step.
./kea-dhcp4-tests-extract --gtest_filter="Dhcp4Parser*" > /dev/null 2> x
rm -f kea-dhcp4-tests-generate
echo "Please copy content of x file into EXTRACTED_CONFIGS in get_config_unittest_rebuild.cc and recompile kea-dhcp4-tests-generate"
printf "Press ENTER when ready"
read -r _

# Generate step
./kea-dhcp4-tests-generate --gtest_filter="Dhcp4GetConfig*" > /dev/null 2> u
echo "Please copy content of u file into UNPARSED_CONFIGS in get_config_unittest_rebuild.cc"
printf "Press ENTER when ready"
read -r _
mv get_config_unittest_rebuild.cc get_config_unittest.cc
cp -f get_config_unittest.cc "@source@"
echo "Please recompile the kea-dhcp4-tests"
echo "When done with success you can check it (test suite is Dhcp4GetConfigTest)"
