[Portland] xdg-utils proof of concept

Bryce Harrington bryce at osdl.org
Wed Apr 5 03:35:21 EEST 2006


On Wed, Mar 15, 2006 at 05:04:08PM -0600, Jeremy White wrote:
> First, this is almost completely untested; that worries me.
> 
> Along those lines, I think there needs to be some sort of test
> mechanism put in place.  I'm not entirely sure what that should be,
> as a lot of the testing needs user interaction (e.g. did a menu appear?).
> I'm toying with using CxTest for that (www.cxtest.org), but that
> may be overkill.

What do you think of this approach?  The attached patch adds a 'make
test' target to the makefile system, and I stubbed out a couple simple
tests for two of the commands.  If this approach looks ok, I can go
ahead and flesh these tests further and add tests for the other
commands.  It's nothing fancy, but may be sufficient for just getting
some limited testing in place.  I'm not sure about stuff that requires
user interaction, though, but imagine there are ways to automate even
that... 

Anyway, if this patch looks ok I can commit it.

Bryce


Index: Makefile.in
===================================================================
RCS file: /cvs/portland/portland/xdg-utils/Makefile.in,v
retrieving revision 1.3
diff -u -u -r1.3 Makefile.in
--- Makefile.in	31 Mar 2006 05:48:41 -0000	1.3
+++ Makefile.in	5 Apr 2006 00:29:50 -0000
@@ -1,8 +1,10 @@
-SUBDIRS = scripts
+SUBDIRS = scripts tests
 
 all:		$(SUBDIRS)
 install:	$(SUBDIRS:%=%/__install__)
 uninstall:	$(SUBDIRS:%=%/__uninstall__)
+test:		dummy
+	cd tests && $(MAKE) test
 clean:		$(SUBDIRS:%=%/__clean__)
 distclean:	clean $(SUBDIRS:%=%/__distclean__)
 	rm -f config.* Makefile
Index: configure
===================================================================
RCS file: /cvs/portland/portland/xdg-utils/configure,v
retrieving revision 1.2
diff -u -u -r1.2 configure
--- configure	31 Mar 2006 02:47:58 -0000	1.2
+++ configure	5 Apr 2006 00:29:51 -0000
@@ -1404,7 +1404,7 @@
 fi
 
 
-                    ac_config_files="$ac_config_files Makefile scripts/Makefile"
+                              ac_config_files="$ac_config_files Makefile scripts/Makefile tests/Makefile"
 
 cat >confcache <<\_ACEOF
 # This file is a shell script that caches the results of configure
@@ -1959,6 +1959,7 @@
   # Handling of arguments.
   "Makefile" ) CONFIG_FILES="$CONFIG_FILES Makefile" ;;
   "scripts/Makefile" ) CONFIG_FILES="$CONFIG_FILES scripts/Makefile" ;;
+  "tests/Makefile" ) CONFIG_FILES="$CONFIG_FILES tests/Makefile" ;;
   *) { { echo "$as_me:$LINENO: error: invalid argument: $ac_config_target" >&5
 echo "$as_me: error: invalid argument: $ac_config_target" >&2;}
    { (exit 1); exit 1; }; };;
Index: configure.ac
===================================================================
RCS file: /cvs/portland/portland/xdg-utils/configure.ac,v
retrieving revision 1.2
diff -u -u -r1.2 configure.ac
--- configure.ac	31 Mar 2006 02:47:58 -0000	1.2
+++ configure.ac	5 Apr 2006 00:29:51 -0000
@@ -8,5 +8,6 @@
 AC_CONFIG_FILES([
     Makefile
     scripts/Makefile
+    tests/Makefile
 ])
 AC_OUTPUT
Index: tests/Makefile.in
===================================================================
RCS file: tests/Makefile.in
diff -N tests/Makefile.in
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ tests/Makefile.in	5 Apr 2006 00:29:51 -0000
@@ -0,0 +1,46 @@
+MKDIR      	= mkdir -p
+RMDIR      	= rmdir
+INSTALL         = @INSTALL@ $(INSTALL_FLAGS)
+INSTALL_PROGRAM = @INSTALL_PROGRAM@ $(INSTALL_PROGRAM_FLAGS)
+INSTALL_LIBRARY = @INSTALL_PROGRAM@ $(INSTALL_PROGRAM_FLAGS)
+INSTALL_SCRIPT  = @INSTALL_SCRIPT@ $(INSTALL_SCRIPT_FLAGS)
+INSTALL_DATA    = @INSTALL_DATA@ $(INSTALL_DATA_FLAGS)
+XMLTO           = @XMLTO@
+
+prefix          = @prefix@
+exec_prefix     = @exec_prefix@
+bindir          = @bindir@
+mandir          = @mandir@
+
+TESTS		= \
+    t.xdg-menu \
+    t.xdg-desktop \
+    t.xdg-email \
+    t.xdg-mime \
+    t.xdg-su \
+    t.xdg-open \
+    t.xdg-copy
+
+all:
+
+test:	$(TESTS)
+	for x in $(TESTS) ; do \
+        	./$$x ; \
+        done
+
+
+release:	tests
+	rm -f *~ HACKING
+	rm -rf desc/
+
+distclean: clean
+	rm -f Makefile
+
+clean:
+
+tests-clean:
+
+install:
+
+uninstall:
+
Index: tests/t.xdg-copy
===================================================================
RCS file: tests/t.xdg-copy
diff -N tests/t.xdg-copy
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ tests/t.xdg-copy	5 Apr 2006 00:29:51 -0000
@@ -0,0 +1,27 @@
+#!/bin/sh
+
+# Test that running with no args returns usage
+# Test that running with 1 arg returns usage
+# Test that running with "--help" returns usage
+
+source="/tmp/xdg-copy.test"
+dest="$source-dest"
+
+echo "TESTING 123" > $source
+
+if [ -e $dest ]; then
+    rm $dest || ( echo "Existing file $dest could not be removed" && exit 1 )
+fi
+
+### COPY existing file properly ###
+xdg-copy "$source" "$dest"
+err=$?
+if [ $err != 0 ]; then
+    echo "FAIL  xdg-copy     # xdg-copy returned $err instead of 0 expected"
+elif [ ! -e "$dest" ]; then
+    echo "FAIL  xdg-copy     # xdg-copy failed to create dest file $dest"
+else
+    echo "PASS  xdg-copy"
+    rm "$dest"
+fi
+
Index: tests/t.xdg-desktop
===================================================================
RCS file: tests/t.xdg-desktop
diff -N tests/t.xdg-desktop
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ tests/t.xdg-desktop	5 Apr 2006 00:29:51 -0000
@@ -0,0 +1,26 @@
+#!/bin/sh
+
+file="/tmp/Test_File.txt"
+vendor_id="Portland Project"
+
+echo $vendor_id > $file
+
+xdg-desktop --install $file
+err=$?
+if [ $err != 0 ]; then
+    echo "FAIL  xdg-desktop install    # Gave exit code $err; expected 0"
+else
+    echo "PASS  xdg-desktop install"
+fi
+
+xdg-desktop --uninstall $file
+err=$?
+if [ $err != 0 ]; then
+    echo "FAIL  xdg-desktop uninstall  # Gave exit code $err; expected 0"
+else
+    echo "PASS  xdg-desktop uninstall"
+fi
+
+exit 0
+
+




More information about the Portland mailing list