#15 C++ issue: cannot use literal str as test name

Unstable_(example)
wont-fix
None
5
2015-02-10
2011-02-02
Anonymous
No

CU_TestInfo::pName is defined as a char*. As a result, no correct code can assign a string litteral to it.
This is especially annoying for preprocessor code like:

define TEST(func) { #func, func}

Since there's no way to avoid using a litteral string.

Here's a patch for it:

--- CUnit-2.1-0/CUnit/Headers/TestDB.h~ 2006-01-29 19:48:26.000000000 -0800
+++ CUnit-2.1-0/CUnit/Headers/TestDB.h 2011-02-01 16:31:54.000000000 -0800
@@ -237,7 +237,7 @@
* a CU_suite_info_t variable.
/
typedef struct CU_TestInfo {
- char
pName; /< Test name. /
+ const char
pName;/
< Test name. /
CU_TestFunc pTestFunc; /< Test function. /
} CU_TestInfo;
typedef CU_TestInfo
CU_pTestInfo; /
< Pointer to CU_TestInfo type.
/

Discussion

  • this isn't working for c:

    TestDB.c: In function ‘CU_set_suite_name’:
    TestDB.c:214: warning: passing argument 1 of ‘free’ discards qualifiers from pointer target type
    /usr/include/stdlib.h:488: note: expected ‘void ’ but argument is of type ‘const char
    TestDB.c:216: warning: passing argument 1 of ‘strcpy’ discards qualifiers from pointer target type
    /usr/include/string.h:128: note: expected ‘char * restrict’ but argument is of type ‘const char
    TestRun.c: In function ‘CU_get_run_results_string’:
    TestRun.c:614: warning: implicit declaration of function ‘snprintf’
    TestDB.c: In function ‘create_suite’:
    TestDB.c:672: warning: passing argument 1 of ‘strcpy’ discards qualifiers from pointer target type
    /usr/include/string.h:128: note: expected ‘char * restrict’ but argument is of type ‘const char

    TestDB.c: In function ‘cleanup_suite’:
    TestDB.c:720: warning: passing argument 1 of ‘free’ discards qualifiers from pointer target type
    /usr/include/stdlib.h:488: note: expected ‘void ’ but argument is of type ‘const char

     
  • Anil Kumar
    Anil Kumar
    2015-02-10

    • status: open --> wont-fix
    • assigned_to: Martin Gerhardy
    • Group: --> Unstable_(example)
     


Anonymous


Cancel   Add attachments