]> granicus.if.org Git - libevent/commitdiff
Fix tinytest invocation from windows shell
authorEd Day <edday2000@gmail.com>
Sat, 11 Jun 2011 04:49:24 +0000 (00:49 -0400)
committerNick Mathewson <nickm@torproject.org>
Sat, 11 Jun 2011 05:31:59 +0000 (01:31 -0400)
Original post:

  This post is in response to a posting last December on a Windows
  regression fork failure ([Libevent-users] Re: Libevent 2.0.10-stable
  is released by Dongsheng Song).  I noticed the question was not
  answered and I recently experienced the same error myself when
  trying to run the Windows regression tests myself.

  I checked the return status from the CreateProcess call and found it
  was "file not found".  This led me to look at the command-line I was
  using which was .\regress in a Visual Studio 2008 command prompt
  window.  Windows could not find the file because it did not have the
  .exe extension on the end.  The code that builds the command should
  be modified to ensure the extension is present.

test/tinytest.c

index d0b77f74255f5b54624d4725ed59606bddf5c8b0..87d1fc3b4c3be9aa78fb0a309b3e1de7582a4044 100644 (file)
@@ -67,7 +67,7 @@ const char *cur_test_name = NULL;
 
 #ifdef WIN32
 /** Pointer to argv[0] for win32. */
-static const char *commandname = NULL;
+static char *commandname = NULL;
 #endif
 
 static void usage(struct testgroup_t *groups, int list_groups)
@@ -291,7 +291,19 @@ tinytest_main(int c, const char **v, struct testgroup_t *groups)
        int i, j, n=0;
 
 #ifdef WIN32
-       commandname = v[0];
+        const char* sp = strrchr (v[0], '.');
+        if (0 != sp) {
+           if (0 != stricmp (sp, ".exe")) { /* not exe extension */
+              sp = 0;
+           }
+        }
+        if (0 == sp) {
+           commandname = (char*) malloc (strlen(v[0]) + 5);
+           strcpy (commandname, v[0]);
+           strcat (commandname, ".exe");
+        }
+        else
+           commandname = strdup (v[0]);
 #endif
        for (i=1; i<c; ++i) {
                if (v[i][0] == '-') {
@@ -314,6 +326,7 @@ tinytest_main(int c, const char **v, struct testgroup_t *groups)
                                usage(groups, 1);
                        } else {
                                printf("Unknown option %s.  Try --help\n",v[i]);
+                                free (commandname);
                                return -1;
                        }
                } else {
@@ -327,6 +340,7 @@ tinytest_main(int c, const char **v, struct testgroup_t *groups)
                        }
                        if (!_tinytest_set_flag(groups, test, flag)) {
                                printf("No such test as %s!\n", v[i]);
+                                free (commandname);
                                return -1;
                        }
                }
@@ -354,6 +368,8 @@ tinytest_main(int c, const char **v, struct testgroup_t *groups)
        else if (opt_verbosity >= 1)
                printf("%d tests ok.  (%d skipped)\n", n_ok, n_skipped);
 
+        free (commandname);
+
        return (n_bad == 0) ? 0 : 1;
 }