#!/usr/bin/env bash

. ../common.sh

init "compiledir with yacc"

( echo "#line 1 \"./bar.y\"" ; cat bar.y ) > bar.c
compile_c bar.c

compile_c foo.c
link foo foo.o bar.o

run foo 1
run foo 2
run foo 23 423

run_gcov bar.y

# All the actual source lines are in bar.y and bar.c is
# just an intermediate file left over from the build
# process.  Thus, tggcov should produce an annotation
# file only for bar.y and never for bar.c, and this
# should be true regardless of which of bar.c and bar.y
# appear on the commandline or their order.

tggcov_check1()
{
    rm -f bar.*.tggcov*
    run_tggcov "$@"
    echo "Files: " ; ls -tr1 bar*
    [ -f bar.y.tggcov ] || fail "no bar.y.tggcov produced"
    [ ! -f bar.c.tggcov ] || fail "bar.c.tggcov mistakenly produced"
}

tggcov_check1 bar.y
# tggcov_check1 bar.c
tggcov_check1 bar.c bar.y
tggcov_check1 bar.y bar.c

compare_lines bar.y
compare_counts bar.y

