Commits

Greg Ward  committed 1d0c861

Only run svn tests if vcprompt supports the required svn version.

- add list of features built-in to the binary (defined in vcprompt.c,
influenced by config.h)
- add a "show features" (-F) option
- use it in test-svn to decide whether or not to run the svn tests

  • Participants
  • Parent commits f901326

Comments (0)

Files changed (5)

File src/common.h

     int show_unknown;                   /* show ? if unknown files? */
     int show_modified;                  /* show + if local changes? */
     unsigned int timeout;               /* timeout in milliseconds */
+    int show_features;                  /* list builtin features */
 } options_t;
 
 /* What we figured out by analyzing the working dir: info that

File src/vcprompt.c

  * (at your option) any later version.
  */
 
+#include "../config.h"
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include "bzr.h"
 */
 
+static char* features[] = {
+    /* Some version control systems don't change their working copy
+       format every couple of versions (or they are just
+       unmaintained), so we don't need versioned feature strings. */
+    "cvs",
+    "hg",
+    "git",
+    "fossil",
+
+    /* Support for Subversion up to 1.6 is unconditional, because those
+       versions don't require any additional libraries. Subversion >= 1.7
+       requires SQLite, so it's conditional. */
+    "svn-1.3",
+    "svn-1.4",
+    "svn-1.5",
+    "svn-1.6",
+#if HAVE_SQLITE3_H
+    "svn-1.7",
+#endif
+    0,
+};
+
 #define DEFAULT_FORMAT "[%n:%b] "
 
 void
 parse_args(int argc, char** argv, options_t *options)
 {
     int opt;
-    while ((opt = getopt(argc, argv, "hf:dt:")) != -1) {
+    while ((opt = getopt(argc, argv, "hf:dt:F")) != -1) {
         switch (opt) {
             case 'f':
                 options->format = optarg;
             case 't':
                 options->timeout = strtol(optarg, NULL, 10);
                 break;
+            case 'F':
+                options->show_features = 1;
+                break;
             case 'h':
             default:
                 printf("usage: %s [-h] [-d] [-t timeout_ms] [-f FORMAT]\n", argv[0]);
 }
 
 void
+show_features(void)
+{
+    for (char **f = features; *f != NULL; f++) {
+        puts(*f);
+    }
+}
+
+void
 parse_format(options_t *options)
 {
     size_t i;
         .show_revision = 0,
         .show_unknown  = 0,
         .show_modified = 0,
+        .show_features = 0,
     };
 
     parse_args(argc, argv, &options);
+    if (options.show_features) {
+        show_features();
+        return 0;
+    }
+
     parse_format(&options);
     set_options(&options);
 

File tests/common.sh

         die "vcprompt executable not found (expected $vcprompt)"
 }
 
+# Check if some feature was built in to the current vcprompt binary;
+# exit with a message if not.
+check_feature()
+{
+    feature=$1
+    msg=$2
+    if ! $vcprompt -F | fgrep -q -x -e "$feature"; then
+        echo $msg
+        exit 0
+    fi
+}
+
 setup()
 {
     tmpdir=`mktemp -d /tmp/vcprompt.XXXXXX`

File tests/test-svn

         "svn --version" \
         "svn, version " \
         "svn not found: skipping this test script"
+    need=`svn --version | head -n1 | sed 's/, version /-/; s/\.[0-9]* .*//'`
+    check_feature $need "$need not built in: skipping this test script"
 }
 
 find_svnrepo()
     assert_vcprompt "rev num on branch" "4" "%r"
 }
 
+find_vcprompt
 check_svn
-find_vcprompt
 find_svnrepo
 setup
 
 .B vcprompt.
 If it fires, no partial information will be printed; the entire
 operation fails.
+.IP -F
+List features built-in to this
+.B vcprompt
+binary and terminate (mainly for testing).
 
 .SH FORMAT STRINGS