From: Mark Probert Date: 2005-03-30T07:11:05+09:00 Subject: rake help Hi .. I have just started using the excellent Rake tool (thanks, Jim!) and I am at a bit of a loss on how to proceed. I am attempting to create unit test for some C++ code I am creating, using the cxxtest tool. cxxtest has its tests contained in a .h file. These are then parsed by the tool to give your .cpp file. This is then complied and linked with the object file. So, assuming I have my code in foo.cpp, my tests in foo_test.h, then the sequence looks like: $ c++ -c -o foo.o foo.cpp $ cxxtest.pl -o foo_test.cpp foo_test.h $ c++ -o foo_test foo_test.cpp foo.o So, there are two issues that I am having problems with. The first is turning the .h into a .cpp. The second is how to get the test to conditionally depend on foo.o. I only want to create foo.o if it isn't there. If it exists, then it will do for the build. In reality, there will be multiple classes in each .o file, yet a unit test per class. Anyway, here is my rakefile, which isn't quite right. Giving: $ rake c++ -o unittest unittest scanner.o c++: unittest: No such file or directory rake aborted! Many thanks, -m. # -!- Ruby -!- # # Rakefile for cocor_cpp # LINK_OBJ = "scanner.o" task :default => [:unittest] # -------- # Unit test harness for cocor # def ext(fn, newext) fn.sub(/\.[^.]+$/, newext) end UT_SRC = [ "ts_buffer.h" ] UT_CPP = UT_SRC.collect { |fn| ext(fn, ".cpp") } UT_CPP.each do |utcpp| utsrc = ext(utcpp, ".h") file utcpp => [utsrc] do |t| cxxopt = "--have-eh --error-printer" sh( "cxxtestgen.pl #{cxxopt} -o #{utcpp} #{utsrc}" ) end end task :unittest => UT_CPP do |t| exe = File.basename(t.name, '.*') sh( "c++ -o #{exe} #{t.name} #{LINK_OBJ}" ) end -- -mark. (probertm at acm dot org)