#!/bin/bash

. ./config-settings.bash


if [ ! -f CPANorig-file-list.txt ] ; then
    echo "Creatig CPANorig-file-list.txt"
    find ../../perllib/cpan.orig/ -type f > CPANorig-file-list.txt
fi

echo ""
echo "****"
echo "* Skipping coverage tests for 'auto/*, perl-5.8/*, Win32/*"
echo "* Skipping coverage test of JSON, and Mojo.* as definite cpanm installed, only newer versions"
echo "****"
echo ""

for f in $( cat CPANorig-file-list.txt ) ; do
    tail_f=${f##*cpan.orig/}
    #echo $tail_f

    ls_check=1
    
    if [ "x${tail_f##auto*}" = "x" ] ; then
	ls_check=0
    elif [ "x${tail_f##perl-5.8*}" = "x" ] ; then
	ls_check=0
    elif [ "x${tail_f##Win32*}" = "x" ] ; then
	ls_check=0
    elif [ "x${tail_f##JSON*}" = "x" ] ; then
	ls_check=0
    elif [ "x${tail_f##Mojo*}" = "x" ] ; then
	ls_check=0
    fi	

    if [ "$ls_check" = "1" ] ; then
	ls "dist/perl-$version/lib/site_perl/$version/$tail_f" >/dev/null 2>&1
	if [ $? != "0" ] ; then
	    ls "dist/perl-$version/lib/site_perl/$version/x86_64-linux-thread-multi/$tail_f" >/dev/null 2>&1

	    if [ $? != "0" ] ; then
		echo "Failed to find: $tail_f"
#	    else
#		echo "[$tail_f looks to be XS-based]"
	    fi
	fi
    fi
done


echo ""
echo "----"
echo "See CHECK-COVERAGE-NOTES.txt for details"
echo "----"
echo ""
