Phil:

As a C/C++ guy at heart, I have given some thought to this problem (i.e.,
that of using Ruby to generate unit tests for other languages like, oh, say
C and C++). In fact, it's one of the core themes of the book I'm working on
with Rich Kilmer and Dana Moore: Ruby as a software engineering toolsmith
language.

One approach (the one toward which I lean) is to generate the C++ classes
using Ruby as a sort of code specification language. I'm calling the package
RuGen, and it will have an assortment of code generators one day, but
upfront I'm working on code generators for Java and C++. The beauty of this
approach is it becomes unnecessary to parse a C++ file to determine what to
test, because you already have all of the metadata about the code you need
to a.) generate the code (or at least the complete skeleton/interface
thereof) and b.) generate the test code for the generated code, treating the
interface as a "black box". (I'm writing a separate package, RuLog, to
provide the logic/inference capabilities necessary to create meaningful and
comprehensive test cases from the spec).

RuGen is still in the design/prototype phase, but the idea is fairly clear
in my head, in terms of how it will work. Rather than create a bunch of
specific language parsers, have one specification language (in much the same
way that Ruby/DL is a specification language for dynamic loading of external
libraries) and a number of generators that are capable of translating the
spec to code in a more or less plug'n'play, or, if I ever get around to
slapping a GUI on it, a point'n'click fashion.

Hopefully I'll have something working soon - I'm probably going to do the
Java generator first, though. But it should serve as an example to everybody
else how to build a code generator for the RuGen package (RuGen providing
the high-level abstractions needed to tie all the plug-in pieces together).

All thoughts, comments, suggestions welcome.

:)

Bob Calco

% -----Original Message-----
% From: Phil Tomson [mailto:ptkwt / shell1.aracnet.com]
% Sent: Sunday, May 26, 2002 2:00 PM
% To: ruby-talk ML
% Subject: using test::unit for C++ unit tests
%
%
% I'm going to be starting on a C++ development project for a contract I'm
% doing and I'd like to use the 'test-first' philosophy and develop unit
% tests first.  Has anyone adapted any of Ruby's unit testing frameworks to
% do unit testing for C++ classes?
%
% I'm thinking that there could be a couple of approaches:
% 1) make the C++ libraries Ruby extensions and instaniate the C++ objects
% and pass messages to them on the Ruby side.
% 2) make some kind of wrapper class (in C++) that gets used to instantiate
% and call methods and then returns some error code.  Compile this wrapper
% into an executable binary that gets called from Ruby with error codes
% being passed back:
% errors = 'exercise <some params>'
%
% 3) a variation on #2 that uses expect.rb.
%
%
% While #1 seems perhaps to be the cleanest choice, we don't have much time
% to set all of this up, so creating the extensions might take longer than
% what we'd like.
%
% Can anyone who has done this offer some pointers?
%
% Phil
%