#!/usr/bin/env atf-sh

. $(atf_get_srcdir)/test_env.sh
init_tests \
	abuild_tar_help \
	abuild_tar_invalid_opt \
	abuild_tar_cut \
	abuild_tar_hash

DATADIR=$(atf_get_srcdir)/testdata

abuild_tar_help_body() {
	atf_check -s exit:0 \
		-o match:"usage:" \
		abuild-tar --help
}

abuild_tar_invalid_opt_body() {
	atf_check -s not-exit:0 \
		-e match:"usage:" \
		abuild-tar --invalid
}

abuild_tar_cut_body() {
	atf_require_prog tar

	echo foo > foo
	echo bar > bar
	tar -cf foo.tar foo
	tar -cf bar.tar bar

	cat foo.tar bar.tar > foobar.tar
	atf_check -o not-match:bar \
		tar -tf foobar.tar

	tar -cf - foo | abuild-tar --cut > cutted.tar
	cat cutted.tar bar.tar > foobar.tar
	atf_check -o match:bar \
		tar -tf foobar.tar
}

abuild_tar_hash_body() {
	atf_require_prog tar strings

	echo foo > foo
	tar --format=posix -cf - foo | abuild-tar --hash > foo.tar
	atf_check -o match:foo tar -tvf foo.tar
	atf_check -o match:"APK-TOOLS.checksum" strings foo.tar
}
