2012-02-12 20 views
24

मैं सीपीपीयूनीट आउटपुट को टीएपी प्रारूप में परिवर्तित करने के लिए एक पर्ल मॉड्यूल चाहता हूं। मैं परीक्षण चलाने और जांचने के लिए कमांड को बाद में उपयोग करना चाहता हूं।सीएपीयूनीट आउटपुट टीएपी प्रारूप कनवर्टर

+16

मैं कुछ भी की पता नहीं है काम कर रहा में, लेकिन CppUnit JUnit XML आउटपुट उपयोग कर रही है। आपके पास जुनीट-टू-टीएपी कनवर्टर की तलाश में अधिक भाग्य हो सकता है। अन्यथा आपकी सर्वश्रेष्ठ शर्त एक [CppUnit प्लगइन] (http://cppunit.sourceforge.net/doc/lastest/class_plug_in_manager.html) लिखना हो सकता है जो रूपांतरण करने के बजाय सीधे TAP आउटपुट करता है। – Schwern

+1

आपको टीएपी :: हार्नेस :: जुनीट देखना चाहिए, इसका कोड आपको रिवर्स कनवर्टर लिखने में मदद कर सकता है (जो अस्तित्व में प्रतीत नहीं होता है)। –

उत्तर

2

हाल ही में मैं जूनिट एक्सएमएल (हालांकि टीएपी प्रारूप में नहीं) से कुछ परिवर्तित कर रहा था। एक्सएमएल :: ट्विग मॉड्यूल का उपयोग करके करना बहुत आसान था। आप कोड इस तरह दिखना चाहिए:

use XML::Twig; 

my %hash; 

my $twig = XML::Twig->new(
    twig_handlers => { 
     testcase => sub { # this gets called per each testcase in XML 
      my ($t, $e) = @_; 
      my $testcase = $e->att("name"); 
      my $error = $e->field("error") || $e->field("failure"); 
      my $ok = defined $error ? "not ok" : "ok"; 
      # you may want to collect 
      # testcase name, result, error message, etc into hash 
      $hash{$testcase}{result} = $ok; 
      $hash{$testcase}{error} = $error; 
      # ... 
     } 
    } 
); 
$twig->parsefile("test.xml"); 
$twig->purge(); 

# Now XML processing is done, print hash out in TAP format: 
print "1..", scalar(keys(%hash)), "\n"; 
foreach my $testcase (keys %hash) { 
    # print out testcase result using info from hash 
    # don't forget to add leading space for errors 
    # ... 
} 

यह पॉलिश करने अपेक्षाकृत आसान होना चाहिए राज्य