The application will return an exit code which can be used to determine

if all classes/methodes have a greater code coverage than specified.
This commit is contained in:
alpinechough 2011-01-13 06:37:22 +08:00 коммит произвёл Zoltan Varga
Родитель 8dfaba4ee1
Коммит 2e4cfc93f7
5 изменённых файлов: 70 добавлений и 0 удалений

Просмотреть файл

@ -1,3 +1,9 @@
2011-01-12 Andreas Windischer
* MonoCovMain.cs, MonoCovOptions.cs, monocov.1, README:
The application will return an exit code which can be used to determine if all
classes/methodes have a greater code coverage than specified.
2011-01-02 Andreas Windischer
* gui/gtk/CoverageView.cs: Create the method nodes only when

Просмотреть файл

@ -54,6 +54,9 @@ public class MonoCovMain {
if (options.exportHtmlDir != null)
return handleExportHtml (options, args);
if (options.minClassCoverage > 0 || options.minMethodeCoverage > 0)
return handleTestCoverage (options, args);
#if GUI_qt
return MonoCov.Gui.Qt.MonoCov.GuiMain (args);
#else
@ -155,5 +158,48 @@ public class MonoCovMain {
}
return 0;
}
private static int handleTestCoverage (MonoCovOptions opts, string[] args)
{
if (args.Length == 0) {
Console.WriteLine ("Error: Datafile name is required when using --minClassCoverage or --minMethodeCoverage.");
return 1;
}
CoverageModel model = new CoverageModel ();
try {
model.ReadFromFile (args[0]);
} catch (Exception e) {
Console.WriteLine ("Error: " + e.Message);
return 1;
}
foreach (ClassCoverageItem classItem in model.Classes.Values) {
if (!opts.quiet)
Console.WriteLine (String.Format ("Coverage of class \"{0}\": {1:0.}%", classItem.FullName, classItem.coveragePercent * 100));
if (opts.minClassCoverage > 0 && classItem.coveragePercent < opts.minClassCoverage) {
if (!opts.quiet)
Console.WriteLine ("Test failed.");
return 1;
}
foreach (MethodCoverageItem methodItem in classItem.Methods) {
if (!opts.quiet)
Console.WriteLine (String.Format ("\tCoverage of method \"{0}\": {1:0.}%", methodItem.Name, methodItem.coveragePercent * 100));
if (opts.minMethodeCoverage > 0 && methodItem.coveragePercent < opts.minMethodeCoverage) {
if (!opts.quiet)
Console.WriteLine ("Test failed.");
return 1;
}
}
}
return 0;
}
}
}

Просмотреть файл

@ -12,6 +12,8 @@ namespace MonoCov
optionSet.Add ("export-xml=", "Export coverage data as XML into specified directory", v => exportXmlDir = v);
optionSet.Add ("export-html=", "Export coverage data as HTML into specified directory", v => exportHtmlDir = v);
optionSet.Add ("stylesheet=", "Use the specified XSL stylesheet for XML->HTML conversion", v => exportHtmlDir = v);
optionSet.Add ("minClassCoverage=", "If a code coverage of a class is less than specified, the application exits with return code 1.", v => float.TryParse(v, out minClassCoverage));
optionSet.Add ("minMethodeCoverage=", "If a code coverage of a methode is less than specified, the application exits with return code 1.", v => float.TryParse(v, out minMethodeCoverage));
optionSet.Add ("no-progress", "No progress messages during the export process", v => quiet = v != null);
optionSet.Add ("h|help", "Show this message and exit", v => showHelp = v != null);
}
@ -20,6 +22,8 @@ namespace MonoCov
public string exportXmlDir;
public string exportHtmlDir;
public string styleSheet;
public float minClassCoverage = -1f;
public float minMethodeCoverage = -1f;
public bool quiet = false;
public bool showHelp = false;

8
README
Просмотреть файл

@ -74,6 +74,14 @@ be good if somebody could contribute a better one :)
To export the data as HTML, run monocov like this:
monocov --export-html=<DEST DIR> <DATA FILE NAME>
You can use this application to track your code coverage as part of your build
process. To specify a minimum methode coverage of 50% and a minimum class coverage
of 80%:
monocov --minClassCoverage=0.5 minMethodeCoverage=0.8 <DATA FILE NAME>
The application will return an exit code which can be used to determine if all
classes/methodes have a greater code coverage than specified.
2.5 KNOWN BUGS
--------------

Просмотреть файл

@ -12,6 +12,12 @@ Export the coverage data as HTML files in directory DIR.
.I \-export-xml:DIR
Export the coverage data as XML files in directory DIR.
.TP
.I \-test-class:VALUE
If a code coverage of a class is less than specified, the application exits with return code 1.
.TP
.I \-test-methode:VALUE
If a code coverage of a methode is less than specified, the application exits with return code 1.
.TP
.I \-version
Print version information.
.TP