#!/bin/sh

# test if the output of 'optcomplete -p' reproduces the current configuration

tmpfile=/tmp/xpcomp-test.$$

. scripts/loadxpcomp.sh -q

for checked_cmd in $(xpcomp -p |cut -d: -f2)
do
	if test -e $tmpfile.1 -o -e $tmpfile.2 ; then
		echo "File $tmpfile.[12] exists" >&2
		exit 1
	fi

	optcomplete -p $checked_cmd > $tmpfile.1
	. $tmpfile.1
	optcomplete -p $checked_cmd > $tmpfile.2
	diffout=$(diff $tmpfile.[12])
	if test -n "$diffout";then
		echo "$checked_cmd:$diffout"
		return
	fi
	rm -f $tmpfile.[12]
done
xpcomp -X
