Added unit tests for --help
authorkarltk <karltk@gentoo.org>
Thu, 30 Sep 2004 14:12:31 +0000 (14:12 -0000)
committerkarltk <karltk@gentoo.org>
Thu, 30 Sep 2004 14:12:31 +0000 (14:12 -0000)
svn path=/; revision=144

19 files changed:
trunk/src/equery/ChangeLog
trunk/src/equery/TODO
trunk/src/equery/tests/common-functions.sh [new file with mode: 0644]
trunk/src/equery/tests/test-belongs-help.out [new file with mode: 0644]
trunk/src/equery/tests/test-changes-help.out [new file with mode: 0644]
trunk/src/equery/tests/test-check-help.out [new file with mode: 0644]
trunk/src/equery/tests/test-depends-help.out [new file with mode: 0644]
trunk/src/equery/tests/test-depgraph-help.out [new file with mode: 0644]
trunk/src/equery/tests/test-files-help.out [new file with mode: 0644]
trunk/src/equery/tests/test-files.sh [new file with mode: 0755]
trunk/src/equery/tests/test-glsa-help.out [new file with mode: 0644]
trunk/src/equery/tests/test-hasuses-help.out [new file with mode: 0644]
trunk/src/equery/tests/test-help.out [new file with mode: 0644]
trunk/src/equery/tests/test-help.sh [new file with mode: 0755]
trunk/src/equery/tests/test-list-help.out [new file with mode: 0644]
trunk/src/equery/tests/test-size-help.out [new file with mode: 0644]
trunk/src/equery/tests/test-stats-help.out [new file with mode: 0644]
trunk/src/equery/tests/test-uses-help.out [new file with mode: 0644]
trunk/src/equery/tests/test-which-help.out [new file with mode: 0644]

index d83bef14d8e30ee3e488ffdfb8ceaca0f7164f28..10fd9c8c30235ab655043b91a2e933337a9958be 100644 (file)
@@ -1,3 +1,6 @@
+2004-09-30 Karl Trygve Kalleberg <karltk@gentoo.org>
+       * Added unit tests for --help
+
 2004-09-27 Karl Trygve Kalleberg <karltk@gentoo.org>
        * Added short commands
        * Fixed copyright dates
index 05738c6c6e8bde9afdd7c61cd5cbb5e431e28c9f..7db2b399a30d466e2890e7a82782cecf849488f8 100644 (file)
@@ -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 (file)
index 0000000..125517f
--- /dev/null
@@ -0,0 +1,43 @@
+#! /bin/bash
+#
+# Copyright (c) 2004, Karl Trygve Kalleberg <karltk@gentoo.org>
+# 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 (file)
index 0000000..0d2f583
--- /dev/null
@@ -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 <local-opts> filename
+<local-opts> 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 (file)
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 (file)
index 0000000..1e6afcf
--- /dev/null
@@ -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 (file)
index 0000000..356cd53
--- /dev/null
@@ -0,0 +1,8 @@
+List all direct dependencies matching a query pattern
+Syntax:
+  depends <local-opts> pkgspec
+<local-opts> 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 (file)
index 0000000..5b9fd22
--- /dev/null
@@ -0,0 +1,7 @@
+Display a dependency tree for a given package
+
+Syntax:
+  depgraph <local-opts> pkgspec
+<local-opts> 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 (file)
index 0000000..846151f
--- /dev/null
@@ -0,0 +1,11 @@
+List files owned by a particular package
+
+Syntax:
+  files <local-opts> <cat/>packagename<-version>
+
+Note: category and version parts are optional. 
+
+<local-opts> 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 (executable)
index 0000000..b0223dc
--- /dev/null
@@ -0,0 +1,55 @@
+#! /bin/bash
+#
+# Copyright (c) 2004, Karl Trygve Kalleberg <karltk@gentoo.org>
+# 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 (file)
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 (file)
index 0000000..1a05645
--- /dev/null
@@ -0,0 +1,9 @@
+List all packages with a particular USE flag
+Syntax:
+  list <local-opts> useflag
+<local-opts> 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 (file)
index 0000000..26517f4
--- /dev/null
@@ -0,0 +1,21 @@
+Usage: equery <global-opts> command <local-opts>
+where <global-opts> 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) <local-opts> files... - list all packages owning files...
+ changes(c)  - not implemented yet
+ check(k) pkgspec - check MD5sums and timestamps of pkgspec's files
+ depends(d) <local-opts> pkgspec - list all direct dependencies matching pkgspec
+ depgraph(g) <local-opts> pkgspec - display a dependency tree for pkgspec
+ files(f) <local-opts> pkgspec - list files owned by pkgspec
+ glsa(a)  - not implemented yet
+ hasuses(h) <local-opts> pkgspec - list all packages with useflag
+ list(l) <local-opts> pkgspec - list all packages matching pkgspec
+ size(s) <local-opts> pkgspec - print size of files contained in package pkgspec
+ stats(t)  - not implemented yet
+ uses(u) <local-opts> 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 (executable)
index 0000000..618aac1
--- /dev/null
@@ -0,0 +1,105 @@
+#! /bin/sh
+#
+# Copyright (c) 2004, Karl Trygve Kalleberg <karltk@gentoo.org>
+# 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 (file)
index 0000000..82d1fb0
--- /dev/null
@@ -0,0 +1,9 @@
+List all packages matching a query pattern
+Syntax:
+  list <local-opts> pkgspec
+<local-opts> 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 (file)
index 0000000..c0c63a4
--- /dev/null
@@ -0,0 +1,6 @@
+Print size total size of files contained in a given package
+Syntax:
+  size <local-opts> pkgspec
+<local-opts> 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 (file)
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 (file)
index 0000000..d350e00
--- /dev/null
@@ -0,0 +1,7 @@
+Display USE flags for a given package
+
+Syntax:
+  uses <local-opts> pkgspec
+<local-opts> 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 (file)
index 0000000..8bf337e
--- /dev/null
@@ -0,0 +1,3 @@
+Print full path to ebuild for a given package
+Syntax:
+  size pkgspec