#!/bin/bash

. ../init.sh || exit 1

set -e

mktmpdir

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

# We output dates, so make sure it matches our logs.
export LC_TIME="C"

# simple sync check
test 01 0 "qlop -s -f ${as}/sync.log"

# check all installed pkgs
test 02 0 "qlop -l -f ${as}/sync.log"

# check all uninstalled pkgs
test 03 0 "qlop -u -f ${as}/sync.log"

# verify atom parsing works (and not partial strings)
test 04 0 "qlop -l gcc -f ${as}/sync.log"

# verify atom version parsing works
test 05 0 "qlop -l '<gcc-5' -f ${as}/sync.log"

cleantmpdir

end
