]> asedeno.scripts.mit.edu Git - PuTTY.git/commitdiff
cmdgen: rescue test suite from bit rot.
authorSimon Tatham <anakin@pobox.com>
Wed, 30 Mar 2016 07:25:25 +0000 (08:25 +0100)
committerSimon Tatham <anakin@pobox.com>
Wed, 30 Mar 2016 07:34:14 +0000 (08:34 +0100)
cmdgen.c has contained code for ages to build a test main() if you
compile with -DTEST_CMDGEN. But it's painful to do so manually, since
you've still got to link in all the same supporting objects, and also
nobody can have actually done that for a while because the stub test
code hasn't been kept up to date with changes in the internal APIs
(specifically prompt_t).

Now we have the ability to include our test programs in Recipe as [UT]
or [XT] so as to leave them out of 'make install', that seems like a
useful thing to do with cmdgen's test suite. So here's a Recipe change
that builds it as 'cgtest', plus fixes for compiler warnings and bit
rot. Pleasantly, the test suite still _passes_ after those are fixed.

.gitignore
Recipe
cgtest.c [new file with mode: 0644]
cmdgen.c

index bbb2cc09f1cec4b7952fadab0bd19b7375da4b84..e9ffff305fbcf46887744dfc9767464e759eee23 100644 (file)
@@ -43,6 +43,7 @@
 /unix/Pterm.app
 /fuzzterm
 /testbn
+/cgtest
 /*.DSA
 /*.RSA
 /*.cnt
diff --git a/Recipe b/Recipe
index 52fe3f4e2581b0a0b2349bcd4d8b6d5ba2832824..59ac7d56155ed1efcfb3ec19de41d4152ba05062 100644 (file)
--- a/Recipe
+++ b/Recipe
@@ -311,10 +311,12 @@ puttytel : [X] GTKTERM uxmisc misc ldisc settings uxsel U_BE_NOSSH
 plink    : [U] uxplink uxcons NONSSH UXSSH U_BE_ALL logging UXMISC uxsignal
          + ux_x11 noterm
 
-puttygen : [U] cmdgen sshrsag sshdssg sshprime sshdes sshbn sshmd5 version
+PUTTYGEN_UNIX = sshrsag sshdssg sshprime sshdes sshbn sshmd5 version
          + sshrand uxnoise sshsha misc sshrsa sshdss uxcons uxstore uxmisc
          + sshpubk sshaes sshsh256 sshsh512 IMPORT puttygen.res time tree234
          + uxgen notiming conf sshecc sshecdsag
+puttygen : [U] cmdgen PUTTYGEN_UNIX
+cgtest   : [UT] cgtest PUTTYGEN_UNIX
 
 pscp     : [U] pscp uxsftp uxcons UXSSH BE_SSH SFTP wildcard UXMISC
 psftp    : [U] psftp uxsftp uxcons UXSSH BE_SSH SFTP wildcard UXMISC
diff --git a/cgtest.c b/cgtest.c
new file mode 100644 (file)
index 0000000..095ce72
--- /dev/null
+++ b/cgtest.c
@@ -0,0 +1,6 @@
+/*
+ * cgtest.c: stub file to compile cmdgen.c in self-test mode
+ */
+
+#define TEST_CMDGEN
+#include "cmdgen.c"
index 4e83336c9f496e6c6dc6dfee80a457c52c5b5f01..ac56ab3e58c48f922adc5290b4a8a2a9b9c057b0 100644 (file)
--- a/cmdgen.c
+++ b/cmdgen.c
@@ -19,7 +19,7 @@
 #ifdef TEST_CMDGEN
 /*
  * This section overrides some definitions below for test purposes.
- * When compiled with -DTEST_CMDGEN:
+ * When compiled with -DTEST_CMDGEN (as cgtest.c will do):
  * 
  *  - Calls to get_random_data() are replaced with the diagnostic
  *    function below (I #define the name so that I can still link
@@ -52,8 +52,7 @@ int console_get_userpass_input(prompts_t *p, unsigned char *in, int inlen)
     int ret = 1;
     for (i = 0; i < p->n_prompts; i++) {
        if (promptsgot < nprompts) {
-           assert(strlen(prompts[promptsgot]) < p->prompts[i]->result_len);
-           strcpy(p->prompts[i]->result, prompts[promptsgot++]);
+           p->prompts[i]->result = dupstr(prompts[promptsgot++]);
        } else {
            promptsgot++;           /* track number of requests anyway */
            ret = 0;
@@ -1193,7 +1192,7 @@ char *cleanup_fp(char *s)
     s += strspn(s, " \n\t");
     s += strcspn(s, " \n\t");
 
-    return dupprintf("%.*s", s - p, p);
+    return dupprintf("%.*s", (int)(s - p), p);
 }
 
 char *get_fp(char *filename)