[Git][ghc/ghc][wip/T19626] 3 commits: Move test to separate dir

Alex D (@nineonine) gitlab at gitlab.haskell.org
Sat Dec 17 06:52:09 UTC 2022



Alex D pushed to branch wip/T19626 at Glasgow Haskell Compiler / GHC


Commits:
38f99ab2 by nineonine at 2022-12-16T18:05:50-08:00
Move test to separate dir

- - - - -
be11df60 by nineonine at 2022-12-16T22:32:14-08:00
Factor our test util file

- - - - -
0fe88e36 by nineonine at 2022-12-16T22:52:02-08:00
Simplify testing utils

- - - - -


7 changed files:

- testsuite/tests/rts/OptParseTest.c → testsuite/tests/rts/OptParse/OptParseTest.c
- testsuite/tests/rts/OptParseTest.stderr → testsuite/tests/rts/OptParse/OptParseTest.stderr
- testsuite/tests/rts/OptParseTest.stdout → testsuite/tests/rts/OptParse/OptParseTest.stdout
- + testsuite/tests/rts/OptParse/OptParseTestUtil.c
- + testsuite/tests/rts/OptParse/OptParseTestUtil.h
- + testsuite/tests/rts/OptParse/all.T
- testsuite/tests/rts/all.T


Changes:

=====================================
testsuite/tests/rts/OptParseTest.c → testsuite/tests/rts/OptParse/OptParseTest.c
=====================================
@@ -1,127 +1,11 @@
 #include <stdio.h>
 #include "Rts.h"
+#include "OptParseTestUtil.h"
 
 #define SAFE true
 #define UNSAFE false
 
-static bool ERROR = false;
-
-static void _TEST( char* flagToTest
-                 , int expectedFlagKey
-                 , char* expectedLongName
-                 , char* expectedShortName
-                 , RtsFlagValueType expectedFlagValueType
-                 , bool safe
-                 , RtsFlagValue expectedValue
-                 ) {
-     debugBelch("\n(TEST) input: %s\n", flagToTest);
-     printf("\n(TEST) input: %s\n", flagToTest);
-     RtsFlagValue flagValue = parseArg(flagToTest, &ERROR);
-     CHECK(!ERROR);
-     RtsFlagName flag = rtsFlags[flagValue.key];
-
-     printf("%i: %s %s %s\n", flagValue.key , flag.longName, flag.shortName, safe ? "SAFE": "UNSAFE");
-     debugBelch("%i: %s %s %s\n", flagValue.key , flag.longName, flag.shortName, safe ? "SAFE": "UNSAFE");
-     CHECK(flagValue.key == expectedFlagKey);
-     CHECK(flag.longName == expectedLongName);
-     CHECK(flag.shortName == expectedShortName);
-     CHECK(flag.valueType == expectedFlagValueType);
-     CHECK(flag.optionSafe == safe);
-     RtsFlagValueType valueTy = flag.valueType;
-     if (valueTy == BOOL) {
-          CHECK(expectedValue.as.boolean == flagValue.as.boolean);
-          printf("\tvalue: %s\n", flagValue.as.boolean ? "true" : "false");
-     }
-     if (valueTy == ENUM) {
-          CHECK(expectedValue.as._enum == flagValue.as._enum);
-          printf("\tvalue: %i\n", flagValue.as._enum);
-     }
-     if (valueTy == DOUBLE) {
-          debugBelch("expected: %f actual: %f\n", expectedValue.as._double, flagValue.as._double);
-          CHECK(expectedValue.as._double == flagValue.as._double);
-          printf("\tvalue: %f\n", flagValue.as._double);
-     }
-     if (valueTy == STGWORD64) {
-          debugBelch("expected: %" FMT_Word64 " actual: %" FMT_Word64 "\n", expectedValue.as.stgWord64, flagValue.as.stgWord64);
-          printf("\tvalue: %" FMT_Word64 "\n", flagValue.as.stgWord64);
-     //   CHECK(expectedValue.as.stgWord64 == flagValue.as.stgWord64);
-     }
-}
-
-static void _FAIL_TEST(char* flagToTest) {
-    debugBelch("\n(FAIL_TEST) input: %s\n", flagToTest);
-    RtsFlagValue flagValue = parseArg(flagToTest, &ERROR);
-    CHECK(ERROR);
-    ERROR = false;
-}
-
-static void _VOID_FLAG_TEST(const RtsFlagKey i)
-{
-     RtsFlagName name = rtsFlags[i];
-     char buffer[100];
-     snprintf(buffer, sizeof(buffer), "--%s", name.longName);
-    _TEST( buffer, i, name.longName, name.shortName
-        , name.valueType, name.optionSafe, NO_VAL(i));
-    snprintf(buffer, sizeof(buffer), "-%s", name.shortName);
-    _TEST( buffer, i, name.longName, name.shortName
-        , name.valueType, name.optionSafe, NO_VAL(i));
-    snprintf(buffer, sizeof(buffer), "-%s=", name.longName);
-    _FAIL_TEST(buffer);
-    snprintf(buffer, sizeof(buffer), "--%s=123G", name.longName);
-    _FAIL_TEST(buffer);
-    snprintf(buffer, sizeof(buffer), "--%s=false", name.longName);
-    _FAIL_TEST(buffer);
-    snprintf(buffer, sizeof(buffer), "--%s=true", name.longName);
-    _FAIL_TEST(buffer);
-    snprintf(buffer, sizeof(buffer), "-%s=", name.shortName);
-    _FAIL_TEST(buffer);
-    snprintf(buffer, sizeof(buffer), "-%s3621", name.shortName);
-    _FAIL_TEST(buffer);
-    snprintf(buffer, sizeof(buffer), "-%s=3622", name.shortName);
-    _FAIL_TEST(buffer);
-    snprintf(buffer, sizeof(buffer), "-%s=true", name.shortName);
-    _FAIL_TEST(buffer);
-    snprintf(buffer, sizeof(buffer), "-%s=", name.shortName);
-    _FAIL_TEST(buffer);
-    snprintf(buffer, sizeof(buffer), "-%s3622", name.shortName);
-    _FAIL_TEST(buffer);
-    snprintf(buffer, sizeof(buffer), "-%s=3600", name.shortName);
-    _FAIL_TEST(buffer);
-}
-
-static void _BOOL_FLAG_TEST(const RtsFlagKey i)
-{
-     RtsFlagName name = rtsFlags[i];
-     char buffer[100];
-     if (name.longName != NULL) {
-          snprintf(buffer, sizeof(buffer), "--%s", name.longName);
-          _TEST( buffer, i
-               , name.longName, name.shortName
-               , BOOL, name.optionSafe, BOOL_VAL(i, true));
-          snprintf(buffer, sizeof(buffer), "--%s=yes", name.longName);
-          _TEST( buffer, i
-               , name.longName, name.shortName
-               , BOOL, name.optionSafe, BOOL_VAL(i, true));
-          snprintf(buffer, sizeof(buffer), "--%s=no", name.longName);
-          _TEST( buffer, i
-               , name.longName, name.shortName
-               , BOOL, name.optionSafe, BOOL_VAL(i, false));
-          snprintf(buffer, sizeof(buffer), "--%s=", name.longName);
-          _FAIL_TEST(buffer);
-          snprintf(buffer, sizeof(buffer), "--%s=foo", name.longName);
-          _FAIL_TEST(buffer);
-          snprintf(buffer, sizeof(buffer), "--%s=1", name.longName);
-          _FAIL_TEST(buffer);
-          snprintf(buffer, sizeof(buffer), "--%sjhgl", name.longName);
-          _FAIL_TEST(buffer);
-     }
-     if (name.shortName != NULL) {
-          snprintf(buffer, sizeof(buffer), "-%s", name.shortName);
-          _TEST( buffer, i
-               , name.longName, name.shortName
-               , BOOL, name.optionSafe, BOOL_VAL(i, true));
-     }
-}
+bool ERROR = false;
 
 int main (int argc, char *argv[])
 {


=====================================
testsuite/tests/rts/OptParseTest.stderr → testsuite/tests/rts/OptParse/OptParseTest.stderr
=====================================


=====================================
testsuite/tests/rts/OptParseTest.stdout → testsuite/tests/rts/OptParse/OptParseTest.stdout
=====================================


=====================================
testsuite/tests/rts/OptParse/OptParseTestUtil.c
=====================================
@@ -0,0 +1,112 @@
+#include <stdio.h>
+#include "Rts.h"
+#include "OptParseTestUtil.h"
+
+char CMP_BUF[100];
+extern bool ERROR;
+
+#define FAIL_TEST(...) \
+    do { \
+        snprintf(CMP_BUF, sizeof(CMP_BUF), __VA_ARGS__); \
+        _FAIL_TEST(CMP_BUF); \
+    } while (false)
+
+void _TEST( char* flagToTest
+          , int expectedFlagKey
+          , char* expectedLongName
+          , char* expectedShortName
+          , RtsFlagValueType expectedFlagValueType
+          , bool safe
+          , RtsFlagValue expectedValue
+          ) {
+    debugBelch("\n(TEST) input: %s\n", flagToTest);
+    printf("\n(TEST) input: %s\n", flagToTest);
+    RtsFlagValue flagValue = parseArg(flagToTest, &ERROR);
+    CHECK(!ERROR);
+    RtsFlagName flag = rtsFlags[flagValue.key];
+
+    printf("%i: %s %s %s\n", flagValue.key , flag.longName, flag.shortName, safe ? "SAFE": "UNSAFE");
+    debugBelch("%i: %s %s %s\n", flagValue.key , flag.longName, flag.shortName, safe ? "SAFE": "UNSAFE");
+    CHECK(flagValue.key == expectedFlagKey);
+    CHECK(flag.longName == expectedLongName);
+    CHECK(flag.shortName == expectedShortName);
+    CHECK(flag.valueType == expectedFlagValueType);
+    CHECK(flag.optionSafe == safe);
+    RtsFlagValueType valueTy = flag.valueType;
+    if (valueTy == BOOL) {
+        printf("\tvalue: %s\n", flagValue.as.boolean ? "true" : "false");
+        CHECK(expectedValue.as.boolean == flagValue.as.boolean);
+    }
+    if (valueTy == ENUM) {
+        printf("\tvalue: %i\n", flagValue.as._enum);
+        CHECK(expectedValue.as._enum == flagValue.as._enum);
+    }
+    if (valueTy == DOUBLE) {
+        debugBelch("expected: %f actual: %f\n", expectedValue.as._double, flagValue.as._double);
+        printf("\tvalue: %f\n", flagValue.as._double);
+        CHECK(expectedValue.as._double == flagValue.as._double);
+    }
+    if (valueTy == STGWORD64) {
+        debugBelch("expected: %" FMT_Word64 " actual: %" FMT_Word64 "\n", expectedValue.as.stgWord64, flagValue.as.stgWord64);
+        printf("\tvalue: %" FMT_Word64 "\n", flagValue.as.stgWord64);
+        CHECK(expectedValue.as.stgWord64 == flagValue.as.stgWord64);
+    }
+}
+
+void _FAIL_TEST(char* flagToTest)
+{
+    debugBelch("\n(FAIL_TEST) input: %s\n", flagToTest);
+    RtsFlagValue flagValue = parseArg(flagToTest, &ERROR);
+    CHECK(ERROR);
+    ERROR = false;
+}
+
+void _VOID_FLAG_TEST(const RtsFlagKey i)
+{
+    RtsFlagName name = rtsFlags[i];
+    char buffer[100];
+    snprintf(buffer, sizeof(buffer), "--%s", name.longName);
+    _TEST( buffer, i, name.longName, name.shortName
+        , name.valueType, name.optionSafe, NO_VAL(i));
+    snprintf(buffer, sizeof(buffer), "-%s", name.shortName);
+    _TEST( buffer, i, name.longName, name.shortName
+        , name.valueType, name.optionSafe, NO_VAL(i));
+    FAIL_TEST("-%s=",       name.longName);
+    FAIL_TEST("--%s=123G",  name.longName);
+    FAIL_TEST("--%s=false", name.longName);
+    FAIL_TEST("--%s=true",  name.longName);
+    FAIL_TEST("-%s=",       name.shortName);
+    FAIL_TEST("-%s3621",    name.shortName);
+    FAIL_TEST("-%s=3622",   name.shortName);
+    FAIL_TEST("-%s=true",   name.shortName);
+    FAIL_TEST("-%s=",       name.shortName);
+    FAIL_TEST("-%s3622",    name.shortName);
+    FAIL_TEST("-%s=3600",   name.shortName);
+}
+
+void _BOOL_FLAG_TEST(const RtsFlagKey i)
+{
+    RtsFlagName name = rtsFlags[i];
+    char buffer[100];
+    if (name.longName != NULL) {
+        snprintf(buffer, sizeof(buffer), "--%s", name.longName);
+        _TEST( buffer, i
+            , name.longName, name.shortName
+            , BOOL, name.optionSafe, BOOL_VAL(i, true));
+        snprintf(buffer, sizeof(buffer), "--%s=yes", name.longName);
+        _TEST( buffer, i
+            , name.longName, name.shortName
+            , BOOL, name.optionSafe, BOOL_VAL(i, true));
+        snprintf(buffer, sizeof(buffer), "--%s=no", name.longName);
+        _TEST( buffer, i
+            , name.longName, name.shortName
+            , BOOL, name.optionSafe, BOOL_VAL(i, false));
+        FAIL_TEST("--%s=",    name.longName);
+        FAIL_TEST("--%s=foo", name.longName);
+        FAIL_TEST("--%s=1",   name.longName);
+        FAIL_TEST("--%sjhgl", name.longName);
+    }
+    if (name.shortName != NULL) {
+        FAIL_TEST("-%s", name.shortName);
+    }
+}


=====================================
testsuite/tests/rts/OptParse/OptParseTestUtil.h
=====================================
@@ -0,0 +1,14 @@
+#include "Rts.h"
+
+void _TEST( char* flagToTest
+          , int expectedFlagKey
+          , char* expectedLongName
+          , char* expectedShortName
+          , RtsFlagValueType expectedFlagValueType
+          , bool safe
+          , RtsFlagValue expectedValue
+          );
+
+void _FAIL_TEST(char* flagToTest);
+void _VOID_FLAG_TEST(const RtsFlagKey i);
+void _BOOL_FLAG_TEST(const RtsFlagKey i);


=====================================
testsuite/tests/rts/OptParse/all.T
=====================================
@@ -0,0 +1 @@
+test('OptParseTest', [ [extra_files(['OptParseTestUtil.c', 'OptParseTestUtil.h']), c_src], only_ways(['normal','threaded1', 'threaded2']) ], compile_and_run, ['OptParseTestUtil.c'])


=====================================
testsuite/tests/rts/all.T
=====================================
@@ -564,5 +564,3 @@ test('decodeMyStack_emptyListForMissingFlag',
   , ignore_stderr
   , js_broken(22261) # cloneMyStack# not yet implemented
   ], compile_and_run, [''])
-
-test('OptParseTest', [ c_src, only_ways(['normal','threaded1', 'threaded2']) ], compile_and_run, [''])



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/96ebcc7487fb1d0c50d8b23325c871003ad44017...0fe88e36e435f22371cff1b925d2eb185b1d0d39

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/96ebcc7487fb1d0c50d8b23325c871003ad44017...0fe88e36e435f22371cff1b925d2eb185b1d0d39
You're receiving this email because of your account on gitlab.haskell.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20221217/fb636840/attachment-0001.html>


More information about the ghc-commits mailing list