CppUnit and Vim 56

Posted by tottinger Fri, 04 May 2007 02:54:00 GMT

I’m playing with ways to make CPPUNIT and VIM a bit more agile for my C++ teams.

I’ve been hearing about great lengths people go to, flipping back and forth between .h and cpp for the tests or writing perl scripts to coalesce them together. I’m too simple-minded for that. I figure nobody wants to #include my tests, so I don’t need a .h. I do it all in the .cpp file, all inline. It works fine. This way, everything is in one place. I don’t have to jump up to the header file to add a protoype and then down to the implementation to add the CPPUNIT_TEST line, and then back down to my code to enter it. I have no .h, so no prototype. Inline makes it a bit more like pyunit or junit.

I grokked the CompilerOutputter pretty quick. If you use the quickfix mode (and esp if you use :cw) you will definitely want the CompilerOutputter. I like the way it helps me move from testing error to testing error (err.. if there were ever more than one), just as it does with compile errors (errr. if they happen. They do). I set up my makefiles to run the tests, so there’s no additional step required. That’s handy. I also have the makefile run ctags to make my navigation nice and easy.

Still, adding and removing tests takes some effort. I figure VIM can take up the slack. I have macros to start up a new test file (F2), to add a test class(F11), to register a function(F12), and to delete a function and its CPPUNIT_TEST line (F9) .

I also abbreviate most of the macros that I would otherwise have to type. I am thinking about remapping them maybe to more memorable values, but it helps.

There are probably a lot more elegant ways to do this. I can’t wait to hear about them.

 " Add methods to help create CPPUNIT classes
function! NewCppUnitFile()
    call NewCppUnitClass()
    0r~/.cppunit_file_template.vim
endfunction

function! NewCppUnitClass() 
    r~/.cppunit_class_template.vim
    let name = input("Name your new test class: ")
    exec "%s/@@@NAMEHERE@@@/" . name . "/g" 
endfunction

nmap <F2> :call NewCppUnitFile()<CR>
nmap <F9>  ^f(b*ddN0d/{<CR>d%
nmap <F11> G:call NewCppUnitClass()<CR>
nmap <F12> ebmz"zyw?CPPUNIT_TEST_SUITE_END(<CR>OCPPUNIT_TEST(<C-R>z);<ESC>'z

" CPPUnit abbreviations
ab cas CPPUNIT_ASSERT
ab cam CPPUNIT_ASSERT_MESSAGE
ab cfa CPPUNIT_FAIL
ab caf CPPUNIT_FAIL
ab cae CPPUNIT_ASSERT_EQUAL
ab cat CPPUNIT_ASSERT_THROW
ab cde CPPUNIT_ASSERT_DOUBLES_EQUAL

The current rhythm is to open a new file and press F2. F2 calls NewCppUnitFile, which sucks in my file header template. It’s pretty bare, but it can be edited to taste. Mostly it helps me remember what to include.

    #include <cppunit/TestFixture.h>
    #include <cppunit/extensions/HelperMacros.h>

Then I give the name of my first test class. I get a starter class. I can then add it to the makefile (note to self: automate the makefile bit). the starter template I have has a dummy test, so I can run it and see if it fails. Failing means it’s being built and run.

    class @@@NAMEHERE@@@: public CPPUNIT_NS::TestFixture {
        CPPUNIT_TEST_SUITE(@@@NAMEHERE@@@);
        CPPUNIT_TEST(shouldFailAsEvidenceThisMethodIsRegistered);  // DELETEME?
        CPPUNIT_TEST_SUITE_END();

        public:
            void setUp() {
            }
            void tearDown() {
            }
        protected:
            void shouldFailAsEvidenceThisMethodIsRegistered() { // DELETEME?
                CPPUNIT_FAIL("This function is registered and can be deleted");
            }
    };
    CPPUNIT_TEST_SUITE_REGISTRATION(@@@NAMEHERE@@@);

Substitution is automagical. the @@NAMEHERE@@ is the magic pattern being replaced with test names.

A nice thing about macros is that they’re atomic. If I hate the name I gave my test, I press ‘u’ for undo, and it vanishes. Back to empty file. :-)

If the ”:mak” works and I get the inevitable failure in the “shouldFail” method, I put my cursor on the “void shouldFail…” line and press F9. In the wink of an eye, the method and its CPPUNIT_TEST line both vanish. Again, macros are atomic, so if I delete the wrong thing, I just press ‘u’ for undo and both the function and its registration reappear.

No flipping between files, no scrolling up and down. We have software to do that now.

I add a method under “protected”. I put the mouse on the method name and press F12 to add the CPPUNIT_TEST for it above. I add some more text. When I get to the part where I need to assert, I use one of the abbreviations. If I’m in insert mode and type “cae(” I get “CPPUNIT_ASSERT_EQUALS(”. I don’t have to remember whether it ends in an S or not. I actually struggle with that, sad thing that I am.

I can press F11 to create more test classes. I like to keep a test class for every circumstance (setup) I am using. I don’t mind at all having multiple tests per .cpp file. I like to group the tests together in files. After all, quickfix knows where the code is. This is actually one of the reasons I like to keep using CppUnit. I’ll have to tell the others someday.

Well, that’s how I do it. You don’t have to, but you could try it. If you find any errors, or glaring omissions, please mail them to me or comment here. In return, I will claim my actual scripts are perfect and blame it on the web master. ;-)

Comments

Leave a response

  1. Avatar
    Philipp Sieweck about 10 hours later:

    A nice way to quickly insert smart templates is the snippets vimscript (http://www.vim.org/scripts/script.php?script_id=1318). Now you have a Textmate-like template system. It would be cool to define some snippets for cppunit or other unittesting frameworks.

  2. Avatar
    jingjia over 3 years later:

    MTS Converter can help you to convert mts files easily and quickly, and it is very easy to use. if you are in need, you can download it and experience by yourself.

    Main Features of MTS Converter

    • Convert AVC HD(.MTS) to all standard video formats like AVI, WMV, MPG, MOV, DVD, etc and various audio files like AAC, AC3, MP3, WAV, WMA, etc.
    • Support batch conversion, you can import more input mts files to the file playlist
    • Provide rich profiles, customize and save your profile for future use
    • Capture current pictures by click “snapshot” and save the current image to snapshot folder
    • Supports extract audio, pictures from video
    • Split one source file to several
  3. Avatar
    valadarrel over 3 years later:

    Convert PDF files with high quality – transfer, backup, copy, import and export PDF files For many Apple users, to have a multi-performance support tool is a great thing. But even if you have all the iPad, iPhone, iPhone Touch of multi-tools, you will certainly encounter a lot of trouble. For example, some people may be using your iPad, but do not know how to use it to read e-books, some people will want to convert PDF to ePub , or transfer ePub files from your computer to the iPad, But do not know what tools to use, how to do it, some people still want to burn, copy, backup ePub files, but do not know how to enable them to maintain a high quality, something like this is really too much.

    But after you finish reading this article, you will not worry about these things, then you will know how to go for your iPad, iPhone, iPod Touch use professional tools to meet some of you common and uncommon problems. Now I will recommend you the best tools and the best way to do these things. You can use the powerful iPad Mate to rip your DVD, movie, music, and audio files to iPad, backup ePub files for your iPad and export ePub files from iPad, convert PDF files to ePub for you to watch eBooks like a PDF to ePub Converter . Also you can use the best iPad Manager for ePub to transfer your ePub files from your iPad and PC without losing them.

  4. Avatar
    goodymary over 3 years later:

    Mac iPad Video Converter is iPad Video Converter working on Mac OS X. It is specially-designed video converter to convert any popular video file (You tube, TS, TOD, MKV, MTS, AVI, FLV, WMV, MPG, M4V, RM, MOV, etc.) to iPad video MP4, MPEG, H.264 on Mac with high speed and great quality. When you free download videos from youtube.com and you want to enjoy them on your iPad. Here Mac YouTube to iPad Converter is suitable for you. You can convert any YouTube videos to iPad MP4 video formats. Mac AVI to iPad Converter is necessary for us to have a try, which can help you convert all AVI videos and other popular video formats like WMV, 3GP, MPEG, VOB, FLV, Xvid to iPad supported MP4 video format. Mac MOV to iPad Converter is your best choice to convert MOV files to iPad MP4

  5. Avatar
    Cazare over 3 years later:

    I’m using CppUnit. It’s not great, but what is? CppUTest is easier to use, but not that much easier. With a few vim macros to ease the pain, CppUnit is fine. Hoteluri Bucuresti

  6. Avatar
    The North Face jackets over 3 years later:

    a href=”http://www.icanshopping.com/”>moncler outlet Sale Cheap Moncler doudoune jackets, Discount moncler and The North Face jackets. you also can buy Moncler sale online with Free Delivery to your door right Now !

  7. Avatar
    moncler over 4 years later:

    I don’t have to jump up to the header file to add a protoype and then down to the implementation to add the PPUNIT_TEST line, and then back down to my code to enter it. I have no .h, so no prototype. Inline makes it a bit more like pyunit or junit.

  8. Avatar
    chanel store over 4 years later:

    Here is very different. Thank you

  9. Avatar
    Beats Headphones over 4 years later:

    and then down to the implementation to add the PPUNIT_TEST line, and then back down to my code to enter it. I have no .h, so no prototype. Inline makes it a bit more like pyunit or junit.

  10. Avatar
    Pandora over 4 years later:

    so there’s no additional step required. That’s handy. I also have the makefile run ctags to make my navigation nice and easy.

  11. Avatar
    pandora over 4 years later:

    The best thing about purchasing on the internet is you are free to see anything your gifts, where in a store it could be challenging to kind nevertheless his or her products to discover what’s right. Parents adore items which are unique. Attempt to found the mom employing a reward which is individualized, as an representation an engagement ring utilizing their title personalized inside it. Rare metal rings lead to wonderful items given that they immortalize your current mom?¡¥s identify inside gold. A new gold pendant and also a pendant produces a amazing items for the mum, along with presents that happen to be most often ignored .

  12. Avatar
    Women's handbags over 4 years later:

    perfect programme,I think i will use it for later.thanks for shareing.

  13. Avatar
    Criminal Records over 4 years later:

    This is actually one of the reasons I like to keep using CppUnit. I’ll have to tell the others someday.

  14. Avatar
    Tenant Screening over 4 years later:
  15. Avatar
    fei xue over 4 years later:

    VLC to DVD Creator is an easy-to-use DVD authoring software and the best VLC to DVD converter to convert VLC to DVD, burn DVD disc, DVD folder and ISO file from all popular media formats like MP4, AVI, WMV, MOV, MPG, MPEG, DAT, MKV, FLV etc. This Powerful VLC to DVD software also allows you to customize your DVD movie by editing the video effects and selecting menu template, transition effect. VLC to MPEG VLC to FLV VLC to MKV VLC to AVI VLC to WAV VLC Converter for Mac

  16. Avatar
    cable ties over 4 years later:

    perfect concept of the topic.

  17. Avatar
    dswehfhh over 4 years later:

    We are the professional jacket manufacturer, jacket supplier, jacket factory, welcome you to custom jacket.

  18. Avatar
    Designer Sunglasses over 4 years later:

    At fashion-world4u you find Imitation

  19. Avatar
    cheap true religion los angeles over 4 years later:

    hni

    The straight jeans trousers mens jeans on salefolded up look, put the pants into the pant low price true religion jeansfor summer and fall,
  20. Avatar
    clothing manufacturer over 4 years later:

    Here is very different. Thank you

  21. Avatar
    sexy dress for sale over 4 years later:

    Here is very different. Thank you

  22. Avatar
    ipad bag over 4 years later:

    TopCombine Follow ipad bag the detail tips below, you can increase the laptop battery life of a year or more. Game Controllers first thing you should care about the USB Gadgets END!??

  23. Avatar
    Marky Martell over 4 years later:

    I like this post. A really good one. Thanks guys. roof sarasota

  24. Avatar
    oakley sunglasses cheapest over 4 years later:

    Way to stay positive and stick with something you love!

  25. Avatar
    oakley sunglasses cheapest over 4 years later:

    Way to stay positive and stick with something you love!

  26. Avatar
    okey oyunu oyna over 4 years later:

    very good.

    Okey oynamak hiç bu kadar zevkli olmadi. Online ve 3 boyutlu okey oyunu oyna ve turnuvalara sende katil.

  27. Avatar
    real estate advertising over 4 years later:

    I love reading your post

  28. Avatar
    real estate advertising over 4 years later:

    Thank you for sharing your information :-)

  29. Avatar
    real estate advertising over 4 years later:

    Very informative article Thank you :-)

  30. Avatar
    mts converter over 4 years later:

    Here MTS Converter can easily Convert MTS files to popular formats like MTS to AVI Converter, MTS to DVD Converter , supports convert MTS to MP4, and convert mts to mp4, Moreover, you can try MTS to mov Converter to convert MTS to WMV and Edit MTS files, like join mts, cut mts, free download avchd converter now! supports MTS Converter Mac !

  31. Avatar
    Jewellery over 4 years later:

    Online UK costume and fashion jewellery shop with, d

  32. Avatar
    beats by dr dre headphones over 4 years later:

    I attempted these monster beats dr dre headphones out in several genres thinking about which i listen to an eclectic mix Beats By Dr Dre. a washing cloth as well as the manual. Do not purchase any beats by dr dre solo purple products inside the internet unless you’re getting from an Authorized internet DealerBeats By Dre Just Solo. We are reliable provide good beats by dr dre headphones by reduced price.

  33. Avatar
    Injection Mold over 4 years later:

    Intertech Machinery Inc. provides the most precise Injection Mould andRubber Molds from Taiwan. With applying excellent unscrewing device in molds, Intertech is also very professional for making flip top Cap Molds in the world.

  34. Avatar
    beats by dre store over 4 years later:

    With applying excellent unscrewing device in molds, Intertech is also very professional high quality headphones new design headphones

  35. Avatar
    what is an iva over 4 years later:

    Thanks a lot for this opportunity to know this information. I am happy to find worth reading article.

  36. Avatar
    bagsupplyer over 4 years later:

    Thank you very much.Waiting for update. Discount designer Men Gucci short pants from China for wholesale at on line store

  37. Avatar
    Diablo3 over 4 years later:

    it needs a bokmark so i can come back to it later ,nice stuff

  38. Avatar
    Men's Polo Big Pony Shirts over 4 years later:

    Pretty good post. I just stumbled upon your blog and wanted to say that I have really enjoyed reading your post

  39. Avatar
    christianlouboutin over 4 years later:

    All among us realise that if you MBT boots or shoes within get hold of, Jimmy Choo Sandaleseducation-women’ vertisements mbt tunisha providing may easily really encourages lymphatic circulation,Jimmy Choo Bottines you’ chemical in all probability more significant receive boots or shoes clearance retail store as a result of MBT while it a good number of at no cost submitting in combination with MBT boots or shoes are almost always pay for and also profit designed notnaxcanada goose outlet.

    A particular low-priced MBT Nama Boots and shoes out of a number of online space boots and shoes plus boot footwear MBT great bargains preferred now in now would be to simply and even safely mbt sandals pay for consumers pay for progressively more over the internetcanada goose jakke, have MBT footwear and remaining grown to be a sample. MBT boots providing now, ways to explain any one prevent
    the north face

    ? Brand-new assumed to test a person's MBT boots pay for, generate a test? My wife and i reassurance any one, we have a special working experience
    North Face Denali Jakker Kvinder hoodie

    .
  40. Avatar
    african Mango dr oz over 4 years later:

    Corporations are challenging existing business models as they seek ways to speed innovation, focus on their core competencies, and scale to capitalize on opportunities and outpace competitors.

  41. Avatar
    Tips For Bowling over 4 years later:

    General statements omit what we really want to know. Example: some horses run faster than others.

  42. Avatar
    alwadifa over 5 years later:

    I liked you blog so im going bookmark it with my prefered websites, you have posted an amazing posts so thank you I liked you blog so im going bookmark it with my prefered websites, you have posted an amazing posts so thank you

  43. Avatar
    christian louboutin over 5 years later:

    The professional design make you foot more comfortable. Even more tantalizing,this pattern make your legs look as long as you can,it will make you looked more attractive.Moveover,it has reasonable price.If you are a popular woman,do not miss it.

    Technical details of Christian Louboutin Velours Scrunch Suede Boots Coffee:

    Color: Coffee
    Material: Suede
    4(100mm) heel
    Signature red sole x

    Fashion, delicate, luxurious Christian louboutins shoes on sale, one of its series is Christian Louboutin Tall Boots, is urbanism collocation. This Christian louboutins shoes design makes people new and refreshing. Red soles shoes is personality, your charm will be wonderful performance.

  44. Avatar
    casque dr dre over 5 years later:

    This looks absolutely perfect. All these tinny details are made with lot of background knowledge. I like it

  45. Avatar
    mts to mov over 5 years later:

    MTS to MOV Converter is a powerful and easy-to-use MPEG to AVI converter, which enables you to effortlessly convert MTS to AVI, MTS to MPEG, MTS to MP4, MTS to 3GP, MTS to WMV, MTS to RM, MTS to RMVB, MTS to FLV, MTS to VCD/SVCD/DVD, MTS to iPod MP4, MTS to PSP MP4 and so forth with high quality. It supports adding watermarks,subtitles to the videos. MTS to MP4 MTS to WMV MTS to MPG

  46. Avatar
    beach cruiser bikes over 5 years later:

    If you want to see the mind blowing article with real facts and figures, this has really tremendous impacts on readers and I admire the writing skill of the author.

  47. Avatar
    sac longchamp pas cher over 5 years later:

    sac longchamp La raison de cette avancée d’une minute vers minuit : sac longchamps les incertitudes liées à la double menace de prolifération nucléaire et de changement climatique. sac longchamp pas cher En janvier 2010 pourtant, l’association des scientifiques atomiques, sac longchamps pas cher qui compte 18 prix Nobel,avait fait reculer la pendule d’une minute, longchamp sac expliquant ce changement par un “état du monde plus encourageant”. http://www.saclongchampsacpascher.com/

  48. Avatar
    Best 42 Inch LED TV 2011 over 5 years later:

    It is great to have the opportunity to read a good quality article with useful information on topics that plenty are interested on. The points that the data stated are all first hand on actual experiences even help more. Go on doing what you do as we enjoy reading your work.

  49. Avatar
    kitchen remodeling Puyallup over 5 years later:

    Thanks for the informative tips shared here! I have read your blog and got positive emotions for it. It gave me dozen of ideas that could be useful for my blog too. Thanks it was just another motivation to devote some more of time and effort to my start up! Regards

  50. Avatar
    creatine over 5 years later:

    Before I read this, I considered myself to be a pretty good writer, I have learned many worthwhile things while reading your article and have taken notes in order to better myself as a writer.

  51. Avatar
    coach outlet uk over 5 years later:

    Its like you read my mind! You appear to know so much about this, like you wrote the book in it or something.

  52. Avatar
    backup iPhone sms over 5 years later:

    Well. Though I am not a good application developer. And I need do more hard work to improve myself. When I come to here. I know that I have come to the right place to learn something I need. Thanks for your good advice. And I will do the practice as possible as I can. Thanks.

  53. Avatar
    supra trainers over 5 years later:

    They go steady produce the task money to circumvent gratuitous past defective downright honourable mother wit, to observe their net income worth incorporate insatiably getting the picture intrust. duty

  54. Avatar
    coco chanel bags over 5 years later:

    mining speculations. The remonstrances of his brother Andrew at times http://www.cocochanelbags.us/

  55. Avatar
    longlong29199 over 5 years later:

    MPEG4 Converter is easy, fast, reliable, and loaded with features. Besides capable of converting standard videos of all popular formats, WMV to 3GP Converter also supports the conversion from standard videos to 3D videos as well as the mode conversion among 3D videos. Now MP4 to MPEG4 Converter can convert video, audio, and animated images to play on your PSP, PS3, iPod, iPhone, Apple TV, Xbox, Google phones, iPad, iPad2 and other digital multimedia devices. FLV to MP4 Converter is made possible with

  56. Avatar
    powerpoint converter over 5 years later:

    i like it very much. But i think only role he will play is being the smiling face telling you that you will get socialized medicine and will like it. thanks again for sharing it. MOV to DVD Converter, burn mov to dvd, convert mov quicktime video to dvd

Comments