public override void WriteResults(Result result, CLICommandOptions commandOptions, bool autoClose = true) { TagDiffResult tagDiffResult = (TagDiffResult)result; CLITagDiffCmdOptions cLITagDiffCmdOptions = (CLITagDiffCmdOptions)commandOptions; TextWriter.WriteLine(MsgHelp.FormatString(MsgHelp.ID.TAGTEST_RESULTS_TEST_TYPE, cLITagDiffCmdOptions.TestType)); if (tagDiffResult.ResultCode == TagDiffResult.ExitCode.TestFailed) { TextWriter.WriteLine(MsgHelp.GetString(MsgHelp.ID.TAGTEST_RESULTS_FAIL)); } else { TextWriter.WriteLine(MsgHelp.GetString(MsgHelp.ID.TAGTEST_RESULTS_SUCCESS)); } //Results list if (tagDiffResult.TagDiffList.Count > 0) { TextWriter.WriteLine("Differences"); foreach (TagDiff tagDiff in tagDiffResult.TagDiffList) { TextWriter.WriteLine(string.Format("Tag: {0}, Only found in file: {1}", tagDiff.Tag, tagDiff.Source)); } } if (autoClose) { FlushAndClose(); } }
private static int RunTagDiffCommand(CLITagDiffCmdOptions cliOptions) { TagDiffCommand command = new(new TagDiffOptions() { SourcePath1 = cliOptions.SourcePath1, SourcePath2 = cliOptions.SourcePath2, CustomRulesPath = cliOptions.CustomRulesPath, IgnoreDefaultRules = cliOptions.IgnoreDefaultRules, FilePathExclusions = cliOptions.FilePathExclusions, ConsoleVerbosityLevel = cliOptions.ConsoleVerbosityLevel, TestType = cliOptions.TestType, Log = cliOptions.Log, ConfidenceFilters = cliOptions.ConfidenceFilters, FileTimeOut = cliOptions.FileTimeOut, ProcessingTimeOut = cliOptions.ProcessingTimeOut, ScanUnknownTypes = cliOptions.ScanUnknownTypes, SingleThread = cliOptions.SingleThread, LogFilePath = cliOptions.LogFilePath, LogFileLevel = cliOptions.LogFileLevel }); TagDiffResult tagDiffResult = command.GetResult(); ResultsWriter.Write(tagDiffResult, cliOptions); return((int)tagDiffResult.ResultCode); }
public void LogDebugLevel_Pass() { TagDiffOptions options = new TagDiffOptions() { SourcePath1 = Path.Combine(Helper.GetPath(Helper.AppPath.testSource), @"unzipped\simple\main.cpp"), SourcePath2 = Path.Combine(Helper.GetPath(Helper.AppPath.testSource), @"unzipped\simple\maincopy.cpp"), FilePathExclusions = "none", //allow source under unittest path LogFileLevel = "debug", LogFilePath = Path.Combine(Helper.GetPath(Helper.AppPath.testOutput), @"logdebug.txt"), }; TagDiffResult.ExitCode exitCode = TagDiffResult.ExitCode.CriticalError; try { TagDiffCommand command = new TagDiffCommand(options); TagDiffResult result = command.GetResult(); exitCode = result.ResultCode; string testLogContent = File.ReadAllText(options.LogFilePath); if (String.IsNullOrEmpty(testLogContent)) { exitCode = TagDiffResult.ExitCode.CriticalError; } else if (testLogContent.ToLower().Contains("debug")) { exitCode = TagDiffResult.ExitCode.TestPassed; } } catch (Exception) { //check for specific error if desired } Assert.IsTrue(exitCode == TagDiffResult.ExitCode.TestPassed); }
public void LogErrorLevel_Pass() { TagDiffOptions options = new TagDiffOptions() { SourcePath1 = Path.Combine(Helper.GetPath(Helper.AppPath.testSource), @"unzipped\simple\main.cpp"), SourcePath2 = Path.Combine(Helper.GetPath(Helper.AppPath.testSource), @"unzipped\simple\nofilehere.cpp"), FilePathExclusions = "none", //allow source under unittest path LogFileLevel = "error", LogFilePath = Path.Combine(Helper.GetPath(Helper.AppPath.testOutput), @"logerror.txt"), }; TagDiffResult.ExitCode exitCode = TagDiffResult.ExitCode.CriticalError; try { TagDiffCommand command = new TagDiffCommand(options); TagDiffResult result = command.GetResult(); exitCode = result.ResultCode; } catch (Exception) { string testLogContent = File.ReadAllText(options.LogFilePath); if (!String.IsNullOrEmpty(testLogContent) && testLogContent.ToLower().Contains("error")) { exitCode = TagDiffResult.ExitCode.TestPassed; } else { exitCode = TagDiffResult.ExitCode.CriticalError; } } Assert.IsTrue(exitCode == TagDiffResult.ExitCode.TestPassed); }
public void DefaultWithCustomRules_Pass() { TagDiffOptions options = new TagDiffOptions() { SourcePath1 = Path.Combine(Helper.GetPath(Helper.AppPath.testSource), @"unzipped\simple\main.cpp"), SourcePath2 = Path.Combine(Helper.GetPath(Helper.AppPath.testSource), @"unzipped\simple\maincopy.cpp"), FilePathExclusions = "none", //allow source under unittest path IgnoreDefaultRules = true, CustomRulesPath = Path.Combine(Helper.GetPath(Helper.AppPath.testRules), @"myrule.json"), }; TagDiffResult.ExitCode exitCode = TagDiffResult.ExitCode.CriticalError; try { TagDiffCommand command = new TagDiffCommand(options); TagDiffResult result = command.GetResult(); exitCode = result.ResultCode; } catch (Exception) { exitCode = TagDiffResult.ExitCode.CriticalError; } Assert.IsTrue(exitCode == TagDiffResult.ExitCode.TestPassed); }
private static int RunTagDiffCommand(CLITagDiffCmdOptions cliOptions) { TagDiffCommand command = new(new TagDiffOptions() { SourcePath1 = cliOptions.SourcePath1, SourcePath2 = cliOptions.SourcePath2, CustomRulesPath = cliOptions.CustomRulesPath, CustomCommentsPath = cliOptions.CustomCommentsPath, CustomLanguagesPath = cliOptions.CustomLanguagesPath, IgnoreDefaultRules = cliOptions.IgnoreDefaultRules, FilePathExclusions = cliOptions.FilePathExclusions, TestType = cliOptions.TestType, ConfidenceFilters = cliOptions.ConfidenceFilters, SeverityFilters = cliOptions.SeverityFilters, FileTimeOut = cliOptions.FileTimeOut, ProcessingTimeOut = cliOptions.ProcessingTimeOut, ScanUnknownTypes = cliOptions.ScanUnknownTypes, SingleThread = cliOptions.SingleThread, }, loggerFactory); TagDiffResult tagDiffResult = command.GetResult(); ResultsWriter writer = new(loggerFactory); writer.Write(tagDiffResult, cliOptions); return((int)tagDiffResult.ResultCode); }
public void NoDefaultNoCustomRules_Fail() { TagDiffOptions options = new TagDiffOptions() { SourcePath1 = Path.Combine(Helper.GetPath(Helper.AppPath.testSource), @"unzipped\simple\main.cpp"), SourcePath2 = Path.Combine(Helper.GetPath(Helper.AppPath.testSource), @"unzipped\simple\mainx.cpp"), FilePathExclusions = "none", //allow source under unittest path IgnoreDefaultRules = true }; TagDiffResult.ExitCode exitCode = TagDiffResult.ExitCode.CriticalError; try { TagDiffCommand command = new TagDiffCommand(options); TagDiffResult result = command.GetResult(); exitCode = result.ResultCode; } catch (Exception) { //check for specific error if desired } //because these are static and each test is meant to be indpendent null assign the references to create the log WriteOnce.Log = null; Utils.Logger = null; Assert.IsTrue(exitCode == TagDiffResult.ExitCode.CriticalError); }
public void InEquality_Pass() { TagDiffOptions options = new TagDiffOptions() { SourcePath1 = Path.Combine(Helper.GetPath(Helper.AppPath.testSource), @"unzipped\simple\main.cpp"), SourcePath2 = Path.Combine(Helper.GetPath(Helper.AppPath.testSource), @"unzipped\simple\mainx.cpp"), FilePathExclusions = "none", //allow source under unittest path TestType = "Inequality" }; TagDiffResult.ExitCode exitCode = TagDiffResult.ExitCode.CriticalError; try { TagDiffCommand command = new TagDiffCommand(options); TagDiffResult result = command.GetResult(); exitCode = result.ResultCode; } catch (Exception) { exitCode = TagDiffResult.ExitCode.CriticalError; } Assert.IsTrue(exitCode == TagDiffResult.ExitCode.TestPassed); }
public void DefaultWithCustomRules_Pass() { TagDiffOptions options = new TagDiffOptions() { SourcePath1 = Path.Combine(Helper.GetPath(Helper.AppPath.testSource), @"unzipped\simple\main.cpp"), SourcePath2 = Path.Combine(Helper.GetPath(Helper.AppPath.testSource), @"unzipped\simple\maincopy.cpp"), FilePathExclusions = "none", //allow source under unittest path IgnoreDefaultRules = true, CustomRulesPath = Path.Combine(Helper.GetPath(Helper.AppPath.testRules), @"myrule.json"), }; TagDiffResult.ExitCode exitCode = TagDiffResult.ExitCode.CriticalError; try { TagDiffCommand command = new TagDiffCommand(options); TagDiffResult result = command.GetResult(); exitCode = result.ResultCode; } catch (Exception) { exitCode = TagDiffResult.ExitCode.CriticalError; } //because these are static and each test is meant to be indpendent null assign the references to create the log WriteOnce.Log = null; Utils.Logger = null; Assert.IsTrue(exitCode == TagDiffResult.ExitCode.TestPassed); }
public void InEquality_Fail() { TagDiffOptions options = new TagDiffOptions() { SourcePath1 = Path.Combine(Helper.GetPath(Helper.AppPath.testSource), @"unzipped\simple\main.cpp"), SourcePath2 = Path.Combine(Helper.GetPath(Helper.AppPath.testSource), @"unzipped\simple\maincopy.cpp"), FilePathExclusions = "none", //allow source under unittest path TestType = "Inequality" }; TagDiffResult.ExitCode exitCode = TagDiffResult.ExitCode.CriticalError; try { TagDiffCommand command = new TagDiffCommand(options); TagDiffResult result = command.GetResult(); exitCode = result.ResultCode; } catch (Exception) { exitCode = TagDiffResult.ExitCode.CriticalError; } //because these are static and each test is meant to be indpendent null assign the references to create the log WriteOnce.Log = null; Utils.Logger = null; Assert.IsTrue(exitCode == TagDiffResult.ExitCode.TestFailed); }
public void NoConsoleOutput_Pass() { TagDiffOptions options = new TagDiffOptions() { SourcePath1 = Path.Combine(Helper.GetPath(Helper.AppPath.testSource), @"unzipped\simple\main.cpp"), SourcePath2 = Path.Combine(Helper.GetPath(Helper.AppPath.testSource), @"unzipped\simple\maincopy.cpp"), FilePathExclusions = "none", ConsoleVerbosityLevel = "none" }; TagDiffResult.ExitCode exitCode = TagDiffResult.ExitCode.CriticalError; try { // Attempt to open output file. using (var writer = new StreamWriter(Path.Combine(Helper.GetPath(Helper.AppPath.testOutput), @"consoleout.txt"))) { // Redirect standard output from the console to the output file. Console.SetOut(writer); TagDiffCommand command = new TagDiffCommand(options); TagDiffResult result = command.GetResult(); exitCode = result.ResultCode; try { string testContent = File.ReadAllText(Path.Combine(Helper.GetPath(Helper.AppPath.testOutput), @"consoleout.txt")); if (String.IsNullOrEmpty(testContent)) { exitCode = TagDiffResult.ExitCode.TestPassed; } else { exitCode = TagDiffResult.ExitCode.TestFailed; } } catch (Exception) { exitCode = TagDiffResult.ExitCode.TestPassed;//no console output file found } } } catch (Exception) { exitCode = TagDiffResult.ExitCode.TestPassed; } //because these are static and each test is meant to be indpendent null assign the references to create the log WriteOnce.Log = null; Utils.Logger = null; //reset to normal var standardOutput = new StreamWriter(Console.OpenStandardOutput()); standardOutput.AutoFlush = true; Console.SetOut(standardOutput); Assert.IsTrue(exitCode == TagDiffResult.ExitCode.TestPassed); }
public void NoConsoleOutput_Pass() { TagDiffOptions options = new() { SourcePath1 = new string[] { Path.Combine(Helper.GetPath(Helper.AppPath.testSource), @"unzipped\simple\main.cpp") }, SourcePath2 = new string[] { Path.Combine(Helper.GetPath(Helper.AppPath.testSource), @"unzipped\simple\maincopy.cpp") }, FilePathExclusions = Array.Empty <string>(), ConsoleVerbosityLevel = "none" }; TagDiffResult.ExitCode exitCode = TagDiffResult.ExitCode.CriticalError; try { // Attempt to open output file. using (var writer = new StreamWriter(Path.Combine(Helper.GetPath(Helper.AppPath.testOutput), @"consoleout.txt"))) { // Redirect standard output from the console to the output file. Console.SetOut(writer); TagDiffCommand command = new(options); TagDiffResult result = command.GetResult(); exitCode = result.ResultCode; try { string testContent = File.ReadAllText(Path.Combine(Helper.GetPath(Helper.AppPath.testOutput), @"consoleout.txt")); if (String.IsNullOrEmpty(testContent)) { exitCode = TagDiffResult.ExitCode.TestPassed; } else { exitCode = TagDiffResult.ExitCode.TestFailed; } } catch (Exception) { exitCode = TagDiffResult.ExitCode.TestPassed;//no console output file found } } } catch (Exception) { exitCode = TagDiffResult.ExitCode.TestPassed; } //reset to normal var standardOutput = new StreamWriter(Console.OpenStandardOutput()); standardOutput.AutoFlush = true; Console.SetOut(standardOutput); Assert.IsTrue(exitCode == TagDiffResult.ExitCode.TestPassed); } }
public override void WriteResults(Result result, CLICommandOptions commandOptions, bool autoClose = true) { TagDiffResult tagDiffResult = (TagDiffResult)result; CLITagDiffCmdOptions cLITagDiffCmdOptions = (CLITagDiffCmdOptions)commandOptions; //For console output, update write once for same results to console or file WriteOnce.TextWriter = TextWriter; if (string.IsNullOrEmpty(commandOptions.OutputFilePath)) { WriteOnce.Result("Results"); } WriteOnce.General(MsgHelp.FormatString(MsgHelp.ID.TAGTEST_RESULTS_TEST_TYPE, cLITagDiffCmdOptions.TestType), false, WriteOnce.ConsoleVerbosity.Low); if (tagDiffResult.ResultCode == TagDiffResult.ExitCode.TestFailed) { WriteOnce.Any(MsgHelp.GetString(MsgHelp.ID.TAGTEST_RESULTS_FAIL), true, ConsoleColor.Red, WriteOnce.ConsoleVerbosity.Low); } else { WriteOnce.Any(MsgHelp.GetString(MsgHelp.ID.TAGTEST_RESULTS_SUCCESS), true, ConsoleColor.Green, WriteOnce.ConsoleVerbosity.Low); } //Results list if (tagDiffResult.TagDiffList.Count > 0) { WriteOnce.Result("Differences"); foreach (TagDiff tagDiff in tagDiffResult.TagDiffList) { WriteOnce.General(string.Format("Tag: {0}, Only found in file: {1}", tagDiff.Tag, tagDiff.Source)); } } if (autoClose) { FlushAndClose(); } }
public void LogTraceLevel_Pass() { TagDiffOptions options = new TagDiffOptions() { SourcePath1 = Path.Combine(Helper.GetPath(Helper.AppPath.testSource), @"unzipped\simple\main.cpp"), SourcePath2 = Path.Combine(Helper.GetPath(Helper.AppPath.testSource), @"unzipped\simple\maincopy.cpp"), FilePathExclusions = "none", //allow source under unittest path LogFileLevel = "trace", LogFilePath = Path.Combine(Helper.GetPath(Helper.AppPath.testOutput), @"logtrace.txt"), }; TagDiffResult.ExitCode exitCode = TagDiffResult.ExitCode.CriticalError; try { TagDiffCommand command = new TagDiffCommand(options); TagDiffResult result = command.GetResult(); exitCode = result.ResultCode; string testLogContent = File.ReadAllText(options.LogFilePath); if (String.IsNullOrEmpty(testLogContent)) { exitCode = TagDiffResult.ExitCode.CriticalError; } else if (testLogContent.ToLower().Contains("trace")) { exitCode = TagDiffResult.ExitCode.TestPassed; } } catch (Exception) { exitCode = TagDiffResult.ExitCode.CriticalError; } //because these are static and each test is meant to be indpendent null assign the references to create the log WriteOnce.Log = null; Utils.Logger = null; Assert.IsTrue(exitCode == TagDiffResult.ExitCode.TestPassed); }
public void BasicZipReadDiff_Pass() { TagDiffOptions options = new() { SourcePath1 = new string[] { Path.Combine(Helper.GetPath(Helper.AppPath.testSource), @"zipped\mainx.zip") }, SourcePath2 = new string[] { Path.Combine(Helper.GetPath(Helper.AppPath.testSource), @"unzipped\simple\mainx.cpp") }, FilePathExclusions = Array.Empty <string>(), //allow source under unittest path }; TagDiffResult.ExitCode exitCode = TagDiffResult.ExitCode.CriticalError; try { TagDiffCommand command = new(options); TagDiffResult result = command.GetResult(); exitCode = result.ResultCode; } catch (Exception) { exitCode = TagDiffResult.ExitCode.CriticalError; } Assert.IsTrue(exitCode == TagDiffResult.ExitCode.TestPassed); }
public void Equality_Fail() { TagDiffOptions options = new() { SourcePath1 = new string[] { Path.Combine(Helper.GetPath(Helper.AppPath.testSource), @"unzipped\simple\main.cpp") }, SourcePath2 = new string[] { Path.Combine(Helper.GetPath(Helper.AppPath.testSource), @"unzipped\simple\mainx.cpp") }, FilePathExclusions = Array.Empty <string>(), //allow source under unittest path }; TagDiffResult.ExitCode exitCode = TagDiffResult.ExitCode.CriticalError; try { TagDiffCommand command = new(options); TagDiffResult result = command.GetResult(); exitCode = result.ResultCode; } catch (Exception) { //check for specific error if desired } Assert.IsTrue(exitCode == TagDiffResult.ExitCode.TestFailed); }
public void InsecureLogPath_Fail() { TagDiffOptions options = new() { SourcePath1 = new string[] { Path.Combine(Helper.GetPath(Helper.AppPath.testSource), @"unzipped\simple\main.cpp") }, SourcePath2 = new string[] { Path.Combine(Helper.GetPath(Helper.AppPath.testSource), @"unzipped\simple\maincopy.cpp") }, FilePathExclusions = Array.Empty <string>(), LogFilePath = Path.Combine(Helper.GetPath(Helper.AppPath.testSource), @"unzipped\simple\empty.cpp"), }; TagDiffResult.ExitCode exitCode = TagDiffResult.ExitCode.CriticalError; try { TagDiffCommand command = new(options); TagDiffResult result = command.GetResult(); exitCode = result.ResultCode; } catch (Exception) { } Assert.IsTrue(exitCode == TagDiffResult.ExitCode.CriticalError); }
public void InvalidLogPath_Fail() { TagDiffOptions options = new() { SourcePath1 = new string[] { Path.Combine(Helper.GetPath(Helper.AppPath.testSource), @"unzipped\simple\main.cpp") }, SourcePath2 = new string[] { Path.Combine(Helper.GetPath(Helper.AppPath.testSource), @"unzipped\simple\mainx.cpp") }, FilePathExclusions = Array.Empty <string>(), //allow source under unittest path LogFilePath = Path.Combine(Helper.GetPath(Helper.AppPath.testOutput), @"baddir\log.txt"), }; TagDiffResult.ExitCode exitCode = TagDiffResult.ExitCode.CriticalError; try { TagDiffCommand command = new(options); TagDiffResult result = command.GetResult(); exitCode = result.ResultCode; } catch (Exception) { } Assert.IsTrue(exitCode == TagDiffResult.ExitCode.CriticalError); }
public void NoResults_Fail() { TagDiffOptions options = new TagDiffOptions() { SourcePath1 = Path.Combine(Helper.GetPath(Helper.AppPath.testSource), @"unzipped\simple\empty.cpp"), SourcePath2 = Path.Combine(Helper.GetPath(Helper.AppPath.testSource), @"unzipped\simple\blank.cpp"), FilePathExclusions = "none", //allow source under unittest path }; TagDiffResult.ExitCode exitCode = TagDiffResult.ExitCode.CriticalError; try { TagDiffCommand command = new TagDiffCommand(options); TagDiffResult result = command.GetResult(); exitCode = result.ResultCode; } catch (Exception) { //check for specific error if desired } Assert.IsTrue(exitCode == TagDiffResult.ExitCode.CriticalError); }
private static int RunTagDiffCommand(CLITagDiffCmdOptions cliOptions) { TagDiffResult.ExitCode exitCode = TagDiffResult.ExitCode.CriticalError; TagDiffCommand command = new TagDiffCommand(new TagDiffOptions() { SourcePath1 = cliOptions.SourcePath1 ?? "", SourcePath2 = cliOptions.SourcePath2 ?? "", CustomRulesPath = cliOptions.CustomRulesPath, IgnoreDefaultRules = cliOptions.IgnoreDefaultRules, FilePathExclusions = cliOptions.FilePathExclusions, ConsoleVerbosityLevel = cliOptions.ConsoleVerbosityLevel, TestType = cliOptions.TestType, Log = cliOptions.Log }); TagDiffResult tagDiffResult = command.GetResult(); exitCode = tagDiffResult.ResultCode; ResultsWriter.Write(tagDiffResult, cliOptions); return((int)exitCode); }
public void DefaultWithCustomRules_Fail() { TagDiffOptions options = new() { SourcePath1 = new string[] { Path.Combine(Helper.GetPath(Helper.AppPath.testSource), @"unzipped\simple\main.cpp") }, SourcePath2 = new string[] { Path.Combine(Helper.GetPath(Helper.AppPath.testSource), @"unzipped\simple\mainx.cpp") }, FilePathExclusions = Array.Empty <string>(), //allow source under unittest path CustomRulesPath = Path.Combine(Helper.GetPath(Helper.AppPath.testRules), @"myrule.json"), }; TagDiffResult.ExitCode exitCode = TagDiffResult.ExitCode.CriticalError; try { TagDiffCommand command = new(options); TagDiffResult result = command.GetResult(); exitCode = result.ResultCode; } catch (Exception) { exitCode = TagDiffResult.ExitCode.CriticalError; } Assert.IsTrue(exitCode == TagDiffResult.ExitCode.TestFailed); }