#!/bin/bash

TD="$(dirname "$0")"
LOGLEVEL=I
if [ -n "$PBUILDER_CHECKOUT" ]; then
    . "$TD/testlib.sh"
    . "$PBUILDER_CHECKOUT/pbuilder-modules"
else
    . "$TD/testlib.sh"
    . "$PBUILDER_TEST_PKGLIBDIR/pbuilder-modules"
fi

function test_information() {
    log "I: test"
    log "W: warning"
    log "E: error"
}
expect_output "I: test
W: warning
E: error" test_information
expect_stderr "W: warning
E: error" test_information

function test_log() {
    log.d "debug"  # this should not be printed in LOGLEVEL=I (the default)
    log.i "info"
    log.w "warn"
    log.e "error"
}
expect_output "I: info
W: warn
E: error" test_log
expect_stderr "W: warn
E: error" test_log

# test the non-copy case
function test_conditional_cp_a() {
    (
	TEMPDIR=$(mktemp -d)
	cd "${TEMPDIR}"
	touch "hoge"
	outdir=$(readlink -f "${TEMPDIR}/..")
	conditional_cp_a "hoge" "${outdir}" echo
    )
}
expect_output "I: file hoge is already in target, not copying." \
    test_conditional_cp_a

# test the copy case.
function test_conditional_cp_a_copy() {
    (
	cd /tmp
	outdir=/something-else
	conditional_cp_a "hoge" "${outdir}" echo
    )
}
expect_output "-a hoge /something-else" test_conditional_cp_a_copy

testlib_summary
