Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parsing C++ to generate unit test stubs

I've recently been trying to create units tests for some legacy code.

I've been taking the approach of using the linker to show me which functions cause link errors, greping the source to find the definition and creating a stub from that.

Is there an easier way? Is there some kind of C++ parser that can give me class definitions, in some easy to use form, from which I can generate stubs?

like image 434
Dave Hillier Avatar asked Oct 25 '08 08:10

Dave Hillier


2 Answers

You may want to investigate http://os.inf.tu-dresden.de/vfiasco/related.html#parsing. But C++ parsing is hard.

On the other hand, maybe ctags or something similar can extract class definitions...

You may also try to write your own simple (?) parser to generate class stubs from header files...

I tried to give you some pointers. As you see, the problem is not easy. But hopefully you can automate at least some part of it.

like image 82
Paweł Hajdan Avatar answered Nov 05 '22 21:11

Paweł Hajdan


Gcc XML is used in some projects, such as automatic FFI for Common Lisp. It ties into the G++ compiler to generate XML representing the source. From there, any XML processing tool could help you reach your goal.

like image 43
Dwight Holman Avatar answered Nov 05 '22 21:11

Dwight Holman