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 BasicZipReadDiff_Pass() { TagDiffOptions options = new TagDiffOptions() { SourcePath1 = Path.Combine(Helper.GetPath(Helper.AppPath.testSource), @"zipped\mainx.zip"), SourcePath2 = Path.Combine(Helper.GetPath(Helper.AppPath.testSource), @"unzipped\simple\mainx.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) { 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 InsecureLogPath_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", LogFilePath = Path.Combine(Helper.GetPath(Helper.AppPath.testSource), @"unzipped\simple\empty.cpp"), }; TagDiffResult.ExitCode exitCode = TagDiffResult.ExitCode.CriticalError; try { TagDiffCommand command = new TagDiffCommand(options); TagDiffResult result = command.GetResult(); exitCode = result.ResultCode; } catch (Exception) { } //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 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 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); }
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 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 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); }
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 Equality_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 }; 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.TestFailed); }
public void InsecureLogPath_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", LogFilePath = Path.Combine(Helper.GetPath(Helper.AppPath.testSource), @"unzipped\simple\empty.cpp"), }; TagDiffResult.ExitCode exitCode = TagDiffResult.ExitCode.CriticalError; try { TagDiffCommand command = new TagDiffCommand(options); TagDiffResult result = command.GetResult(); exitCode = result.ResultCode; } catch (Exception) { } Assert.IsTrue(exitCode == TagDiffResult.ExitCode.CriticalError); }
public void InvalidLogPath_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 LogFilePath = Path.Combine(Helper.GetPath(Helper.AppPath.testOutput), @"baddir\log.txt"), }; TagDiffResult.ExitCode exitCode = TagDiffResult.ExitCode.CriticalError; try { TagDiffCommand command = new TagDiffCommand(options); TagDiffResult result = command.GetResult(); exitCode = result.ResultCode; } catch (Exception) { } Assert.IsTrue(exitCode == TagDiffResult.ExitCode.CriticalError); }