Click here to Skip to main content
14,637,542 members
Rate this:
Please Sign up or sign in to vote.
See more:
The test method names take the form:
public void testBirdCanFly()
public void testHumanCanEat()
When test running, the name is displayed the name in English, thus:
 "Bird Can Fly"
 "Human Can Eat" 

What I have tried:

Can any one suggest how this can be achieved in c++ 
Updated 11-Jul-20 7:01am
Richard MacCutchan 11-Jul-20 4:16am
Are you talking about a program that will read the source file containing these functions, or something else?
Rate this:
Please Sign up or sign in to vote.

Solution 1

We are more than willing to help those that are stuck: but that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for us to do it all for you.

So we need you to do the work, and we will help you when you get stuck. That doesn't mean we will give you a step by step solution you can hand in!
Start by explaining where you are at the moment, and what the next step in the process is. Then tell us what you have tried to get that next step working, and what happened when you did.
Rate this:
Please Sign up or sign in to vote.

Solution 2

If all you need is the function name, the C++ standard defines func[^] as part of the preprocessor. (Sorry, func is preceded and followed by two underscores, but they get interpreted as Markdown when I post this, and I don't know how to display them because the escape character doesn't work. Grrr!) Anyway, func gets replaced by a C-string for the current function's name, which you can use to construct a std::string, which you can then parse.

C++ does not support introspection, so if you actually want to parse a function signature, which includes its return type and arguments, you would have to parse the source code.
Rate this:
Please Sign up or sign in to vote.

Solution 3

There are lots of ways this kind of thing can be implemented. What makes you think they are "parsing the method signature"? It could be just a text string set in that function. You could also do something like this :
#define FunctionMessage(a)  DisplayFuncMsg( a, __FUNCTION__, __FILE__, __LINE__ );

using PCSTR = const char *;

void DisplayFuncMsg( PCSTR text, PCSTR functionName, PCSTR fileName, int lineNumber )
    std::cout << "In function " << functionName
              << " at line " << lineNumber
              << " of " << fileName
              << std::endln;

    std::cout << "message : \"" << text << "\"" << std::endln;

    // one algorithm to parse function signature (functionName) :
    // remove the test prefix, if it exists
    // insert a space between words separate according to capitalized letters

void testDoSomethingHere()
    FunctionMessage( "some text message or another" );

    // do some other stuff here

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100