#!/bin/bash

. ../init.sh || exit 1

set -e

export ROOT=${as}/root
export Q_VDB=/

mktmpdir

test() {
	local num=$1 exp=$2 ret=0
	shift 2
	eval "$@" > list || ret=$?
	if ! diff -u ${as}/list${num}.good list ; then
		tfail "output does not match for: $*"
	fi
	if [[ ${exp} -ne ${ret} ]] ; then
		tfail "exit code (${ret}) does not match expected (${exp})"
	fi
	tend $? "$*"
}

# simple install check
test 01 0 "qlist -I"

# simple files list
test 02 0 "qlist --showdebug cpio"

# symlink verbose list
test 03 0 "qlist --showdebug mtools -e -v"

# dir test
test 04 0 "qlist --showdebug mtools -d"

# obj test
test 05 0 "qlist --showdebug mtools -o"

# sym test
test 06 0 "qlist --showdebug mtools -s"

# SLOT test
test 07 0 "qlist -IS"

# showdebug test #1
test 08 0 "qlist cpio"

# dir test
test 09 0 "qlist mtools -d"

# ver test
test 10 0 "qlist -Iv =mtools-4*"

# repo test
test 11 0 "qlist -IR"

# slot with repo test
test 12 0 "qlist -ISR"

# exact CAT/PN:slot::repo files list test
test 13 0 "qlist -e --showdebug app-arch/cpio:0::gentoo"

# sub-SLOT test
test 14 0 "qlist -ISS"

# no matches
test 15 1 "qlist -Iv lajsdflkjasdflkjasdfljasdf"

# match test w/out sub-SLOT
test 16 0 "qlist -ISS virtual/sub-2:1"

# check USE retrieval
test 17 0 "qlist -IUv mtools"

cleantmpdir

end
