From: karltk Date: Thu, 30 Sep 2004 14:12:31 +0000 (-0000) Subject: Added unit tests for --help X-Git-Tag: gentoolkit-0.2.4.3~358 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=b7176544f1cf27a24f227abe0967d31ed4997156;p=gentoolkit.git Added unit tests for --help svn path=/; revision=144 --- diff --git a/trunk/src/equery/ChangeLog b/trunk/src/equery/ChangeLog index d83bef1..10fd9c8 100644 --- a/trunk/src/equery/ChangeLog +++ b/trunk/src/equery/ChangeLog @@ -1,3 +1,6 @@ +2004-09-30 Karl Trygve Kalleberg + * Added unit tests for --help + 2004-09-27 Karl Trygve Kalleberg * Added short commands * Fixed copyright dates diff --git a/trunk/src/equery/TODO b/trunk/src/equery/TODO index 05738c6..7db2b39 100644 --- a/trunk/src/equery/TODO +++ b/trunk/src/equery/TODO @@ -1,6 +1,57 @@ -- clean up colours for output! - - error, warning, info - - package, searchterm, useflag, number, ... - - structured output, to allow for XML, piping and tty? -- list all global useflags -- list all local useflags +- pkgquery language: + Query ::= NewStyle | OldStyle | with OldStyle NewStyle + NewStyle ::= NameVar in /RegExp/ + | VerVar in [ VerExpr ] + | SetVar in [ SetExpr ] + NameVar ::= PC | PN | DESCRIPTION | SRC_URI | HOMEPAGE + + SetVar ::= LICENSE | KEYWORDS | IUSE + VerVar ::= SLOT | PV | DEPEND | RDEPEND + + BinaryOp ::= and | or + UnaryOp ::= not + + VerExpr ::= SingleVer + | VerExpr BinOp VerExpr + | UnaryOp UnaryOp + + SetExpr ::= Element + | Element BinOp Element + | UnaryOp Element + + SingleVer ::= PrefixOp VersionBody ( VersionSuffix )? ( - Revision )? + PrefixOp ::= ! | < | > | <= | >= | = | ~ + VersionBody ::= Number ( . Number )+ ( . * )? + VersionSuffix ::= _ ( pre | beta | alpha | rc ) Number? + | [a-z] + Revision ::= r Number + +------ + + PC in /dev-java/ and + PN in /ant/ and + PV in [ >=1.0 or <=2.3 and =2.0.* ] and + IUSE in [ java or junit ] + + +-- + with >=dev-java/ant-1.0* + IUSE in [ java or junit ] and + SLOT in [ >=1.0 ] + + +---------- + +old cruft: + + SingleVer ::= ( Operator )? ( Category / ) PackageName ( - Version )? + Operator ::= = | > | >= | < | <= | ~ | ! + Category ::= PackageName + PackageName ::= NamePart ( - NamePart )+ + NamePart ::= [a-zA-Z+]+ + Version ::= VersionPart ( - VersionPart )+ ( _ VersionSuffix )? ( - Revision )? + VersionSuffix ::= ( pre | rc | beta | alpha ) ( Number ) ? + + old style: >=dev-java/ant-1.0* + + diff --git a/trunk/src/equery/tests/common-functions.sh b/trunk/src/equery/tests/common-functions.sh new file mode 100644 index 0000000..125517f --- /dev/null +++ b/trunk/src/equery/tests/common-functions.sh @@ -0,0 +1,43 @@ +#! /bin/bash +# +# Copyright (c) 2004, Karl Trygve Kalleberg +# Copyright (c) 2004, Gentoo Foundation +# +# Licensed under the GNU General Public License, v2 + +function tempfilename() { + fn=$(date "+%s") + if [ ! -f ${fn}.tmp ] ; then + echo ${fn}.tmp + fi +} + +function report_pass() { + printf "%-40s - passed\n" ${1} +} + +function report_failure() { + printf "%-40s - FAILED!\n" ${1} +} + +function assert_samefile() { + diff $2 $3 && report_pass $1 || report_failure $1 +} + +function assert_eq() { + if [ $2 -eq $3 ] ; then + report_pass $1 + else + printf "FAIL: $2 ! -eq $3\n" + report_failure $1 + fi +} + +function assert_ge() { + if [ $2 -ge $3 ] ; then + report_pass $1 + else + printf "FAIL: $2 ! -ge $3\n" + report_failure $1 + fi +} \ No newline at end of file diff --git a/trunk/src/equery/tests/test-belongs-help.out b/trunk/src/equery/tests/test-belongs-help.out new file mode 100644 index 0000000..0d2f583 --- /dev/null +++ b/trunk/src/equery/tests/test-belongs-help.out @@ -0,0 +1,11 @@ +List all packages owning a particular set of files + +Note: Normally, only one package will own a file. If multiple packages own the same file, it usually consitutes a problem, and should be reported. + +Syntax: + belongs filename + is either of: + -c, --category cat - only search in category cat + -f, --full-regex - supplied query is a regex + -e, --earlyout - stop when first match is found + diff --git a/trunk/src/equery/tests/test-changes-help.out b/trunk/src/equery/tests/test-changes-help.out new file mode 100644 index 0000000..e69de29 diff --git a/trunk/src/equery/tests/test-check-help.out b/trunk/src/equery/tests/test-check-help.out new file mode 100644 index 0000000..1e6afcf --- /dev/null +++ b/trunk/src/equery/tests/test-check-help.out @@ -0,0 +1,3 @@ +Check package's files against recorded MD5 sums and timestamps +Syntax: + size pkgspec diff --git a/trunk/src/equery/tests/test-depends-help.out b/trunk/src/equery/tests/test-depends-help.out new file mode 100644 index 0000000..356cd53 --- /dev/null +++ b/trunk/src/equery/tests/test-depends-help.out @@ -0,0 +1,8 @@ +List all direct dependencies matching a query pattern +Syntax: + depends pkgspec + is either of: + -d, --direct - search direct dependencies only (default) + -D, --indirect - search indirect dependencies (VERY slow) + -i, --only-installed - search installed in installed packages only + diff --git a/trunk/src/equery/tests/test-depgraph-help.out b/trunk/src/equery/tests/test-depgraph-help.out new file mode 100644 index 0000000..5b9fd22 --- /dev/null +++ b/trunk/src/equery/tests/test-depgraph-help.out @@ -0,0 +1,7 @@ +Display a dependency tree for a given package + +Syntax: + depgraph pkgspec + is either of: + -U, --no-useflags - do not show USE flags + -l, --linear - do not use fancy formatting diff --git a/trunk/src/equery/tests/test-files-help.out b/trunk/src/equery/tests/test-files-help.out new file mode 100644 index 0000000..846151f --- /dev/null +++ b/trunk/src/equery/tests/test-files-help.out @@ -0,0 +1,11 @@ +List files owned by a particular package + +Syntax: + files packagename<-version> + +Note: category and version parts are optional. + + is either of: + --timestamp - append timestamp + --md5sum - append md5sum + --type - prepend file type diff --git a/trunk/src/equery/tests/test-files.sh b/trunk/src/equery/tests/test-files.sh new file mode 100755 index 0000000..b0223dc --- /dev/null +++ b/trunk/src/equery/tests/test-files.sh @@ -0,0 +1,55 @@ +#! /bin/bash +# +# Copyright (c) 2004, Karl Trygve Kalleberg +# Copyright (c) 2004, Gentoo Foundation +# +# Licensed under the GNU General Public License, v2 + +. common-functions.sh + +tmpfile=$(tempfilename) + +strip_versioned_files() { + grep -v "/usr/share/doc" +} + +test_files() { + equery files bash > ${tmpfile} + + x=$(grep man ${tmpfile} | wc -l) + assert_ge ${FUNCNAME} $x 5 + + x=$(cat ${tmpfile} | wc -l) + assert_ge ${FUNCNAME} $x 25 +} + +test_files_timestamp() { + equery files --timestamp bash > ${tmpfile} +} + +test_files_md5sum() { + equery files --md5sum bash > ${tmpfile} +} + +test_files_type() { + + equery files --type bash > ${tmpfile} + + x=$(grep "file.*/bin/bash$" ${tmpfile} | wc -l) + assert_eq ${FUNCNAME} $x 1 + + x=$(grep "symlink.*/bin/rbash" ${tmpfile} | wc -l) + assert_eq ${FUNCNAME} $x 1 + + x=$(grep "dir.*/usr/share/man" ${tmpfile} | wc -l) + assert_ge ${FUNCNAME} $x 1 +} + +# Run tests + +test_files +test_files_timestamp +test_files_md5sum +test_files_type + +rm ${tmpfile} \ No newline at end of file diff --git a/trunk/src/equery/tests/test-glsa-help.out b/trunk/src/equery/tests/test-glsa-help.out new file mode 100644 index 0000000..e69de29 diff --git a/trunk/src/equery/tests/test-hasuses-help.out b/trunk/src/equery/tests/test-hasuses-help.out new file mode 100644 index 0000000..1a05645 --- /dev/null +++ b/trunk/src/equery/tests/test-hasuses-help.out @@ -0,0 +1,9 @@ +List all packages with a particular USE flag +Syntax: + list useflag + is either of: + -i, --installed - search installed packages (default) + -I, --exclude-installed - do not search installed packages + -p, --portage-tree - also search in portage tree (/usr/portage) + -o, --overlay-tree - also search in overlay tree (/usr/local/portage /usr/local/overlays/gentoo-boblycat) + diff --git a/trunk/src/equery/tests/test-help.out b/trunk/src/equery/tests/test-help.out new file mode 100644 index 0000000..26517f4 --- /dev/null +++ b/trunk/src/equery/tests/test-help.out @@ -0,0 +1,21 @@ +Usage: equery command +where is one of + -q, --quiet - minimal output + -C, --nocolor - turn off colours + -h, --help - this help screen + -V, --version - display version info +where command(short) is one of + belongs(b) files... - list all packages owning files... + changes(c) - not implemented yet + check(k) pkgspec - check MD5sums and timestamps of pkgspec's files + depends(d) pkgspec - list all direct dependencies matching pkgspec + depgraph(g) pkgspec - display a dependency tree for pkgspec + files(f) pkgspec - list files owned by pkgspec + glsa(a) - not implemented yet + hasuses(h) pkgspec - list all packages with useflag + list(l) pkgspec - list all packages matching pkgspec + size(s) pkgspec - print size of files contained in package pkgspec + stats(t) - not implemented yet + uses(u) pkgspec - display USE flags for pkgspec + which(w) pkgspec - print full path to ebuild for package pkgspec + diff --git a/trunk/src/equery/tests/test-help.sh b/trunk/src/equery/tests/test-help.sh new file mode 100755 index 0000000..618aac1 --- /dev/null +++ b/trunk/src/equery/tests/test-help.sh @@ -0,0 +1,105 @@ +#! /bin/sh +# +# Copyright (c) 2004, Karl Trygve Kalleberg +# Copyright (c) 2004, Gentoo Foundation +# +# Licensed under the GNU General Public License, v2 + +. common-functions.sh + +tmpfile=$(tempfilename) + +test_equery_help() { + equery --help > ${tmpfile} + assert_samefile ${FUNCNAME} ${tmpfile} test-help.out + +} + +test_belongs_help() { + equery belongs --help > ${tmpfile} + assert_samefile ${FUNCNAME} ${tmpfile} test-belongs-help.out +} + +test_changes_help() { + equery changes --help > ${tmpfile} + assert_samefile ${FUNCNAME} ${tmpfile} test-changes-help.out +} + +test_check_help() { + equery check --help > ${tmpfile} + assert_samefile ${FUNCNAME} ${tmpfile} test-check-help.out +} + +test_depends_help() { + equery depends --help > ${tmpfile} + assert_samefile ${FUNCNAME} ${tmpfile} test-depends-help.out +} + +test_depgraph_help() { + equery depgraph --help > ${tmpfile} + assert_samefile ${FUNCNAME} ${tmpfile} test-depgraph-help.out +} + +test_files_help() { + equery files --help > ${tmpfile} + assert_samefile ${FUNCNAME} ${tmpfile} test-files-help.out +} + +test_glsa_help() { + equery glsa --help > ${tmpfile} + assert_samefile ${FUNCNAME} ${tmpfile} test-glsa-help.out +} + +test_hasuses_help() { + equery hasuses --help > ${tmpfile} + assert_samefile ${FUNCNAME} ${tmpfile} test-hasuses-help.out +} + +test_list_help() { + equery list --help > ${tmpfile} + assert_samefile ${FUNCNAME} ${tmpfile} test-list-help.out +} + +test_size_help() { + equery size --help > ${tmpfile} + assert_samefile ${FUNCNAME} ${tmpfile} test-size-help.out +} + +test_stats_help() { + equery stats --help > ${tmpfile} + assert_samefile ${FUNCNAME} ${tmpfile} test-stats-help.out +} + +test_uses_help() { + equery uses --help > ${tmpfile} + assert_samefile ${FUNCNAME} ${tmpfile} test-uses-help.out +} + +test_which_help() { + equery which --help > ${tmpfile} + assert_samefile ${FUNCNAME} ${tmpfile} test-which-help.out +} + + +# run tests + +if [ "`hostname`" != "sky" ] ; then + echo "Testing framework is beta and machine dependent; some tests will fail!" +fi + +test_equery_help +test_belongs_help +test_check_help +test_changes_help +test_depends_help +test_depgraph_help +test_files_help +test_glsa_help +test_hasuses_help +test_list_help +test_size_help +test_stats_help +test_uses_help +test_which_help + +rm -f *.tmp \ No newline at end of file diff --git a/trunk/src/equery/tests/test-list-help.out b/trunk/src/equery/tests/test-list-help.out new file mode 100644 index 0000000..82d1fb0 --- /dev/null +++ b/trunk/src/equery/tests/test-list-help.out @@ -0,0 +1,9 @@ +List all packages matching a query pattern +Syntax: + list pkgspec + is either of: + -i, --installed - search installed packages (default) + -I, --exclude-installed - do not search installed packages + -p, --portage-tree - also search in portage tree (/usr/portage) + -o, --overlay-tree - also search in overlay tree (/usr/local/portage /usr/local/overlays/gentoo-boblycat) + diff --git a/trunk/src/equery/tests/test-size-help.out b/trunk/src/equery/tests/test-size-help.out new file mode 100644 index 0000000..c0c63a4 --- /dev/null +++ b/trunk/src/equery/tests/test-size-help.out @@ -0,0 +1,6 @@ +Print size total size of files contained in a given package +Syntax: + size pkgspec + is either of: + -b, --bytes - report size in bytes + diff --git a/trunk/src/equery/tests/test-stats-help.out b/trunk/src/equery/tests/test-stats-help.out new file mode 100644 index 0000000..e69de29 diff --git a/trunk/src/equery/tests/test-uses-help.out b/trunk/src/equery/tests/test-uses-help.out new file mode 100644 index 0000000..d350e00 --- /dev/null +++ b/trunk/src/equery/tests/test-uses-help.out @@ -0,0 +1,7 @@ +Display USE flags for a given package + +Syntax: + uses pkgspec + is either of: + -a, --all - include non-installed packages + diff --git a/trunk/src/equery/tests/test-which-help.out b/trunk/src/equery/tests/test-which-help.out new file mode 100644 index 0000000..8bf337e --- /dev/null +++ b/trunk/src/equery/tests/test-which-help.out @@ -0,0 +1,3 @@ +Print full path to ebuild for a given package +Syntax: + size pkgspec