#!/bin/sh

. ../../../scripts/test-utils.sh

fpp_depend=../../../bin/fpp-depend

compare()
{
  outfile=$1
  diff -u $outfile.ref.txt $outfile.out.txt > $outfile.diff.txt 2>&1
}

run_test()
{
  args=$1
  infile=$2
  if test -n "$3"
  then
    outfile=$3
  else
    outfile=$infile
  fi
  $fpp_depend $args $infile.fpp 2>&1 | remove_path_prefix > $outfile.out.txt
  compare $outfile
}

. ./tests.sh

# Default tests
for t in $tests
do
  echo "
$t()
{
  run_test '' $t
}"
done > default-tests.sh
. ./default-tests.sh

# Custom tests
direct()
{
  run_test '-d tmp.out.txt' direct_a direct
  remove_path_prefix < tmp.out.txt > direct_output.out.txt
  compare direct_output
}

filenames()
{
  run_test '-g filenames_output.out.txt' filenames
  compare filenames_output
}

filenames_include()
{
  run_test '-g filenames_include_output.out.txt' filenames_include
  compare filenames_include_output
}

framework()
{
  run_test '-f framework_output.out.txt' framework
  compare framework_output
}

framework_include()
{
  run_test '-f framework_include_output.out.txt' framework_include
  compare framework_include_output
}

include()
{
  run_test '-i tmp.out.txt' include
  remove_path_prefix < tmp.out.txt > include_output.out.txt
  compare include_output
}

included_dep_i()
{
  run_test '-i tmp.out.txt' included_dep included_dep_i
  remove_path_prefix < tmp.out.txt > included_dep_i_output.out.txt
  compare included_dep_i_output
}

input()
{
  run_test '' 'input_1.fpp input_2' input
}

locate_constant_include_no_i()
{
  run_test '' locate_constant_include_1 locate_constant_include_no_i
}

locate_constant_include_i()
{
  run_test '-i tmp.out.txt' locate_constant_include_1 locate_constant_include_i
  remove_path_prefix < tmp.out.txt > locate_constant_include_i_output.out.txt
  compare locate_constant_include_i_output
}

missing()
{
  run_test '-m tmp.out.txt' missing
  remove_path_prefix < tmp.out.txt > missing_output.out.txt
  compare missing_output
}

run_suite $tests
