From f1fb82a858bd6ccfcab960cada354c4ba5ee5515 Mon Sep 17 00:00:00 2001 From: Mike Norman Date: Wed, 19 Jul 2017 15:07:43 -0500 Subject: Forced check for TBA as default for comparereport, added 'no-check-TBA' option --- tools/DocStat/DocStat.Tests/CommandUtilsTests.cs | 21 ++++++++++++++ tools/DocStat/DocStat.Tests/DocStat.Tests.csproj | 7 +++++ tools/DocStat/DocStat/CommandUtils.cs | 23 ++++++++++++++++ tools/DocStat/DocStat/comparereport.cs | 35 +++++++++++++++++------- 4 files changed, 76 insertions(+), 10 deletions(-) create mode 100644 tools/DocStat/DocStat.Tests/CommandUtilsTests.cs (limited to 'tools') diff --git a/tools/DocStat/DocStat.Tests/CommandUtilsTests.cs b/tools/DocStat/DocStat.Tests/CommandUtilsTests.cs new file mode 100644 index 00000000..c3c57baf --- /dev/null +++ b/tools/DocStat/DocStat.Tests/CommandUtilsTests.cs @@ -0,0 +1,21 @@ +using NUnit.Framework; +using System; +namespace DocStat.Tests +{ + [TestFixture] + public class CommandUtilsTests + { + [Test] + public void CSVStringWith2() + { + Assert.AreEqual(@"""{0}"",""{1}""", CommandUtils.CSVFormatString(2)); + } + + [Test] + public void CSVStringWithIndexArray() + { + Assert.AreEqual(@"""{1}"",""{0}""", + CommandUtils.CSVFormatString(2, new int[] { 1, 0 })); + } + } +} diff --git a/tools/DocStat/DocStat.Tests/DocStat.Tests.csproj b/tools/DocStat/DocStat.Tests/DocStat.Tests.csproj index 2a48d3cd..d8e6c822 100644 --- a/tools/DocStat/DocStat.Tests/DocStat.Tests.csproj +++ b/tools/DocStat/DocStat.Tests/DocStat.Tests.csproj @@ -34,6 +34,7 @@ + @@ -46,6 +47,12 @@ Always + + Always + + + Always + diff --git a/tools/DocStat/DocStat/CommandUtils.cs b/tools/DocStat/DocStat/CommandUtils.cs index 8d4686fe..8affcdee 100644 --- a/tools/DocStat/DocStat/CommandUtils.cs +++ b/tools/DocStat/DocStat/CommandUtils.cs @@ -200,6 +200,29 @@ namespace DocStat ); } + public static string CSVFormatString(int numColumns, int[] order = null) + { + if (null != order && order.Length != numColumns) + throw new ArgumentException(String.Format("Column order array had {0} entries, but {1} columns are needed.", + order.Length.ToString(), + numColumns.ToString())); + Func indexFor = null; + + if (null != order) + { + indexFor = (int i) => order[i]; + } + else + { + indexFor = (int i) => i; + } + + string[] cols = new string[numColumns]; + for (int i = 0; i < numColumns; i++) + cols[i] = "\"{" + indexFor(i) + "}\""; + + return String.Join(",", cols); + } } } diff --git a/tools/DocStat/DocStat/comparereport.cs b/tools/DocStat/DocStat/comparereport.cs index 60cd06ea..c692282f 100644 --- a/tools/DocStat/DocStat/comparereport.cs +++ b/tools/DocStat/DocStat/comparereport.cs @@ -28,11 +28,13 @@ namespace DocStat string oldFilesDir = ""; bool typeOnly = false; string reportFile = ""; + bool nosigil = false; var options = new OptionSet { {"previous=", (p) => oldFilesDir = p}, {"typeonly", (t) => typeOnly = t != null}, - {"reportfile=", (r) => reportFile = r} + {"reportfile=", (r) => reportFile = r}, + { "no-check-TBA", (t) => nosigil = t != null } }; extras = options.Parse(extras); @@ -53,25 +55,34 @@ namespace DocStat IEnumerable updated = CommandUtils.GetFileList(processlist, omitlist, updatedDir, pattern); StreamWriter reportStream = new StreamWriter(reportFile); - reportStream.WriteLine(@"""File Name"",""Type"",""Member"""); - string threeColumnFormatString = @"""{0}"",""{1}"",""{2}"""; - string twoColumnFormatString = @"""{0}"",""{1}"""; + reportStream.WriteLine(String.Format(CommandUtils.CSVFormatString(3), "File Name", "Type", "Member")); Action Write = null; Action WriteSubsequent = (XElement e) => { - reportStream.WriteLine(threeColumnFormatString, "", "", e.Attribute("MemberName").Value); + reportStream.WriteLine(CommandUtils.CSVFormatString(3), "", "", e.Attribute("MemberName").Value); }; + Func hasSigil = null; + + if (nosigil) + { + hasSigil = (XElement e) => true; + } + else + { + hasSigil = (XElement e) => e.Element("Docs").Element("summary").Value == "To be added."; + } + foreach (string updatedXMLFile in updated) { XDocument updatedXDoc = XDocument.Load(updatedXMLFile); Action WriteFileLine = (string fname) => { - reportStream.WriteLine(twoColumnFormatString, + reportStream.WriteLine(CommandUtils.CSVFormatString(2), fname, updatedXDoc.Element("Type").Attribute("FullName").Value); Write = WriteSubsequent; @@ -79,7 +90,7 @@ namespace DocStat Write = (XElement e) => { - reportStream.WriteLine(twoColumnFormatString, + reportStream.WriteLine(CommandUtils.CSVFormatString(2), updatedXMLFile, updatedXDoc.Element("Type").Attribute("FullName").Value); WriteSubsequent(e); @@ -90,10 +101,14 @@ namespace DocStat XDocument oldXDoc = File.Exists(oldXMLFile) ? XDocument.Load(oldXMLFile) : null; if (null == oldXDoc) WriteFileLine(updatedXMLFile); - - foreach (XElement e in EcmaXmlHelper.NewMembers(updatedXDoc, oldXDoc)) + + IEnumerable newMembers = EcmaXmlHelper.NewMembers(updatedXDoc, oldXDoc); + if (null != newMembers && newMembers.Count() > 0) { - Write(e); + foreach (XElement e in newMembers.Where((f) => hasSigil(f))) + { + Write(e); + } } } reportStream.Flush(); -- cgit v1.2.3