#!/bin/bash

set -e 
$PREPARE_DEFAULT > /dev/null
$INCLUDE_FUNCS
cd $WC

LOG=$LOGDIR/041.options

# step 1: empty settings file.
CONF=$FSVS_CONF/config

touch $CONF
if ! $BINdflt st
then
	$ERROR "Empty config file fails"
fi

echo '## comment' > $CONF
echo '# comment' >> $CONF
echo '' >> $CONF
if ! $BINdflt st
then
	$ERROR "Comment-only settings file gives an error"
fi


touch empty-file
echo 'path=absolute' > $CONF
if ! $BINdflt st > $LOG
then
	$ERROR "Reading config-file fails (1)"
fi

if grep "$WC1/empty-file" < $LOG > /dev/null
then
	$SUCCESS "Parameter path read and understood."
else
	$ERROR "Parameter path not read"
fi


# The file is only touched, so filter=text shouldn't find it.
echo 'filter=text' > $CONF
if ! $BINdflt st > $LOG
then
	$ERROR "Reading config-file fails (2)"
fi

if [[ `wc -l < $LOG` -eq 0 ]]
then
	$SUCCESS "Parameter filter read and understood."
else
	$ERROR "Parameter filter not read"
fi


echo 'invalid string' > $CONF
if $BINdflt st > $LOG 2>&1
then
	$ERROR "Invalid string doesn't fail"
fi

echo 'invalid=option' > $CONF
if $BINdflt st > $LOG 2>&1
then
	$ERROR "Invalid option doesn't fail"
fi

$SUCCESS "Config file correctly parsed."

# Restore default behaviour.
rm $CONF

