public void InEquality_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\mainx.cpp") }, FilePathExclusions = Array.Empty <string>(), //allow source under unittest path TestType = "Inequality" }; 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 NoConsoleOutput_Pass() { TagDiffResult.ExitCode exitCode = TagDiffResult.ExitCode.CriticalError; try { string appInspectorPath = Helper.GetPath(Helper.AppPath.appInspectorCLI); string args = string.Format(@"tagdiff --src1 {0} --src2 {1} -x none -f text -k none -o {2}", Path.Combine(Helper.GetPath(Helper.AppPath.testSource), @"unzipped\simple\main.cpp"), Path.Combine(Helper.GetPath(Helper.AppPath.testSource), @"unzipped\simple\maincopy.cpp"), Path.Combine(Helper.GetPath(Helper.AppPath.testOutput), @"output.txt")); exitCode = (TagDiffResult.ExitCode)Helper.RunProcess(appInspectorPath, args, out string testContent); if (exitCode == TagDiffResult.ExitCode.TestPassed) { exitCode = String.IsNullOrEmpty(testContent) ? TagDiffResult.ExitCode.TestPassed : TagDiffResult.ExitCode.CriticalError; } } catch (Exception) { exitCode = TagDiffResult.ExitCode.CriticalError; } 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 LogDebugLevel_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>(), //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(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 TagdiffToTextFilePath_Pass() { TagDiffResult.ExitCode exitCode = TagDiffResult.ExitCode.CriticalError; try { string args = string.Format(@"tagdiff --src1 {0} --src2 {1} -f text -k none -o {2} -l {3}", Path.Combine(Helper.GetPath(Helper.AppPath.testSource), @"unzipped\simple\main.cpp"), Path.Combine(Helper.GetPath(Helper.AppPath.testSource), @"unzipped\simple\mainx.cpp"), Path.Combine(Helper.GetPath(Helper.AppPath.testOutput), @"output.txt"), Path.Combine(Helper.GetPath(Helper.AppPath.testOutput), @"log.txt")); if (File.Exists(Path.Combine(Helper.GetPath(Helper.AppPath.testOutput), @"output.txt"))) { File.Delete(Path.Combine(Helper.GetPath(Helper.AppPath.testOutput), @"output.txt")); } exitCode = (TagDiffResult.ExitCode)Microsoft.ApplicationInspector.CLI.Program.Main(args.Split(' ')); if (exitCode == TagDiffResult.ExitCode.TestFailed)//looking for diff list { if (!File.Exists(Path.Combine(Helper.GetPath(Helper.AppPath.testOutput), @"output.txt")) || new FileInfo(Path.Combine(Helper.GetPath(Helper.AppPath.testOutput), @"output.txt")).Length == 0) { exitCode = TagDiffResult.ExitCode.CriticalError; } } } catch (Exception) { exitCode = TagDiffResult.ExitCode.CriticalError; } Assert.IsTrue(exitCode == TagDiffResult.ExitCode.TestFailed); }
public void TagdiffToJsonFilePath_Pass() { TagDiffResult.ExitCode exitCode = TagDiffResult.ExitCode.CriticalError; try { string args = string.Format(@"tagdiff --src1 {0} --src2 {1} -f json -k none -o {2} -l {3}", Path.Combine(Helper.GetPath(Helper.AppPath.testSource), @"unzipped\simple\main.cpp"), Path.Combine(Helper.GetPath(Helper.AppPath.testSource), @"unzipped\simple\maincopy.cpp"), Path.Combine(Helper.GetPath(Helper.AppPath.testOutput), @"output.json"), Path.Combine(Helper.GetPath(Helper.AppPath.testOutput), @"log.txt")); if (File.Exists(Path.Combine(Helper.GetPath(Helper.AppPath.testOutput), @"output.json"))) { File.Delete(Path.Combine(Helper.GetPath(Helper.AppPath.testOutput), @"output.json")); } exitCode = (TagDiffResult.ExitCode)Microsoft.ApplicationInspector.CLI.Program.Main(args.Split(' ')); if (exitCode == TagDiffResult.ExitCode.TestPassed) { string content = File.ReadAllText(Path.Combine(Helper.GetPath(Helper.AppPath.testOutput), @"output.json")); var result = JsonConvert.DeserializeObject <TagDiffResult>(content); exitCode = result.TagDiffList.Count > 0 ? TagDiffResult.ExitCode.TestPassed : TagDiffResult.ExitCode.CriticalError; } } catch (Exception) { exitCode = TagDiffResult.ExitCode.CriticalError; } Assert.IsTrue(exitCode == TagDiffResult.ExitCode.CriticalError); }
public void TagdiffToUnknownFormatFilePath_Fail() { TagDiffResult.ExitCode exitCode = TagDiffResult.ExitCode.CriticalError; try { string args = string.Format(@"tagdiff --src1 {0} --src2 {1} -f unknown -k none -o {2} -l {3}", Path.Combine(Helper.GetPath(Helper.AppPath.testSource), @"unzipped\simple\main.cpp"), Path.Combine(Helper.GetPath(Helper.AppPath.testSource), @"unzipped\simple\maincopy.cpp"), Path.Combine(Helper.GetPath(Helper.AppPath.testOutput), @"output.txt"), Path.Combine(Helper.GetPath(Helper.AppPath.testOutput), @"log.txt")); if (File.Exists(Path.Combine(Helper.GetPath(Helper.AppPath.testOutput), @"output.json"))) { File.Delete(Path.Combine(Helper.GetPath(Helper.AppPath.testOutput), @"output.json")); } exitCode = (TagDiffResult.ExitCode)Microsoft.ApplicationInspector.CLI.Program.Main(args.Split(' ')); } catch (Exception) { //check for specific error if desired } Assert.IsTrue(exitCode == TagDiffResult.ExitCode.CriticalError); }
public void LogDebugLevel_Pass() { TagDiffResult.ExitCode exitCode = TagDiffResult.ExitCode.CriticalError; try { string args = string.Format(@"tagdiff --src1 {0} --src2 {1} -r {2} -k none -v debug -l {3}", Path.Combine(Helper.GetPath(Helper.AppPath.testSource), @"unzipped\simple\main.cpp"), Path.Combine(Helper.GetPath(Helper.AppPath.testSource), @"unzipped\baddir\mainx.cpp"), Path.Combine(Helper.GetPath(Helper.AppPath.testRules), @"mybadrule.json"), Path.Combine(Helper.GetPath(Helper.AppPath.testOutput), @"log.txt")); exitCode = (TagDiffResult.ExitCode)Microsoft.ApplicationInspector.CLI.Program.Main(args.Split(' ')); if (exitCode == TagDiffResult.ExitCode.CriticalError) { string testContent = File.ReadAllText(Path.Combine(Helper.GetPath(Helper.AppPath.testOutput), @"log.txt")); exitCode = testContent.ToLower().Contains("debug") ? TagDiffResult.ExitCode.TestPassed : TagDiffResult.ExitCode.CriticalError; } } catch (Exception) { exitCode = TagDiffResult.ExitCode.CriticalError; } Assert.IsTrue(exitCode == TagDiffResult.ExitCode.TestPassed); }
public void DefaultWithCustomRules_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>(), //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(options); TagDiffResult result = command.GetResult(); exitCode = result.ResultCode; } catch (Exception) { exitCode = TagDiffResult.ExitCode.CriticalError; } 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 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 void NoConsoleNoFileOutput_Fail() { TagDiffResult.ExitCode exitCode = TagDiffResult.ExitCode.CriticalError; try { string args = string.Format(@"tagdiff --src1 {0} --src2 {1} -x none -f text -k none -l {2}", Path.Combine(Helper.GetPath(Helper.AppPath.testSource), @"unzipped\simple\main.cpp"), Path.Combine(Helper.GetPath(Helper.AppPath.testSource), @"unzipped\simple\maincopy.cpp"), Path.Combine(Helper.GetPath(Helper.AppPath.testOutput), @"log.txt")); exitCode = (TagDiffResult.ExitCode)Microsoft.ApplicationInspector.CLI.Program.Main(args.Split(' ')); } catch (Exception) { } Assert.IsTrue(exitCode == TagDiffResult.ExitCode.CriticalError); }
public void ZipReadDiff_Pass() { TagDiffResult.ExitCode exitCode = TagDiffResult.ExitCode.CriticalError; try { string args = string.Format(@"tagdiff --src1 {0} --src2 {1} -k none -l {2}", Path.Combine(Helper.GetPath(Helper.AppPath.testSource), @"unzipped\simple\mainx.cpp"), Path.Combine(Helper.GetPath(Helper.AppPath.testSource), @"zipped\mainx.zip"), Path.Combine(Helper.GetPath(Helper.AppPath.testOutput), @"log.txt")); exitCode = (TagDiffResult.ExitCode)Microsoft.ApplicationInspector.CLI.Program.Main(args.Split(' ')); } catch (Exception) { } Assert.IsTrue(exitCode == TagDiffResult.ExitCode.TestPassed); }
public void InvalidLogPath_Fail() { TagDiffResult.ExitCode exitCode = TagDiffResult.ExitCode.CriticalError; try { string args = string.Format(@"tagdiff --src1 {0} --src2 {1} -k none -l {2}", Path.Combine(Helper.GetPath(Helper.AppPath.testSource), @"unzipped\simple\main.cpp"), Path.Combine(Helper.GetPath(Helper.AppPath.testSource), @"unzipped\simple\mainx.cpp"), Path.Combine(Helper.GetPath(Helper.AppPath.testOutput), @"\baddir\log.txt")); exitCode = (TagDiffResult.ExitCode)Microsoft.ApplicationInspector.CLI.Program.Main(args.Split(' ')); } catch (Exception) { } Assert.IsTrue(exitCode == TagDiffResult.ExitCode.CriticalError);//test fails even when values match unless this case run individually -mstest bug? }
public void NoConsoleNoFileOutput_Fail() { TagDiffResult.ExitCode exitCode = TagDiffResult.ExitCode.CriticalError; try { string appInspectorPath = Helper.GetPath(Helper.AppPath.appInspectorCLI); string args = String.Format(@"tagdiff --src1 {0} --src2 {1} -x none -f text -k none -l {2}", Path.Combine(Helper.GetPath(Helper.AppPath.testSource), @"unzipped\simple\main.cpp"), Path.Combine(Helper.GetPath(Helper.AppPath.testSource), @"unzipped\simple\maincopy.cpp"), Path.Combine(Helper.GetPath(Helper.AppPath.testOutput), @"log.txt")); exitCode = (TagDiffResult.ExitCode)Helper.RunProcess(appInspectorPath, args); } catch (Exception) { } Assert.IsTrue(exitCode == TagDiffResult.ExitCode.CriticalError); }
public void NoDefaultNoCustomRules_Fail() { TagDiffResult.ExitCode exitCode = TagDiffResult.ExitCode.CriticalError; try { string args = string.Format(@"tagdiff --src1 {0} --src2 {1} -i -k none -l {2}", Path.Combine(Helper.GetPath(Helper.AppPath.testSource), @"unzipped\simple\main.cpp"), Path.Combine(Helper.GetPath(Helper.AppPath.testSource), @"unzipped\simple\mainx.cpp"), Path.Combine(Helper.GetPath(Helper.AppPath.testOutput), @"log.txt")); exitCode = (TagDiffResult.ExitCode)Microsoft.ApplicationInspector.CLI.Program.Main(args.Split(' ')); } catch (Exception) { //check for specific error if desired } Assert.IsTrue(exitCode == TagDiffResult.ExitCode.CriticalError); }
public void ZipReadDiff_Pass() { TagDiffResult.ExitCode exitCode = TagDiffResult.ExitCode.CriticalError; try { string appInspectorPath = Helper.GetPath(Helper.AppPath.appInspectorCLI); string args = String.Format(@"tagdiff --src1 {0} --src2 {1} -k none -l {2}", Path.Combine(Helper.GetPath(Helper.AppPath.testSource), @"unzipped\simple\mainx.cpp"), Path.Combine(Helper.GetPath(Helper.AppPath.testSource), @"zipped\mainx.zip"), Path.Combine(Helper.GetPath(Helper.AppPath.testOutput), @"log.txt")); exitCode = (TagDiffResult.ExitCode)Helper.RunProcess(appInspectorPath, args); } catch (Exception) { } Assert.IsTrue(exitCode == TagDiffResult.ExitCode.TestPassed); }
public void NoDefaultNoCustomRules_Fail() { TagDiffResult.ExitCode exitCode = TagDiffResult.ExitCode.CriticalError; try { string appInspectorPath = Helper.GetPath(Helper.AppPath.appInspectorCLI); string args = String.Format(@"tagdiff --src1 {0} --src2 {1} -i -k none -l {2}", Path.Combine(Helper.GetPath(Helper.AppPath.testSource), @"unzipped\simple\main.cpp"), Path.Combine(Helper.GetPath(Helper.AppPath.testSource), @"unzipped\simple\mainx.cpp"), Path.Combine(Helper.GetPath(Helper.AppPath.testOutput), @"log.txt")); exitCode = (TagDiffResult.ExitCode)Helper.RunProcess(appInspectorPath, args); } catch (Exception) { //check for specific error if desired } Assert.IsTrue(exitCode == TagDiffResult.ExitCode.CriticalError); }
public void LogErrorLevel_Pass() { TagDiffResult.ExitCode exitCode = TagDiffResult.ExitCode.CriticalError; try { string appInspectorPath = Helper.GetPath(Helper.AppPath.appInspectorCLI); string args = String.Format(@"tagdiff --src1 {0} --src2 {1} -k none -l {2}", Path.Combine(Helper.GetPath(Helper.AppPath.testSource), @"unzipped\simple\badfilepath.cpp"), Path.Combine(Helper.GetPath(Helper.AppPath.testSource), @"unzipped\simple\mainx.cpp"), Path.Combine(Helper.GetPath(Helper.AppPath.testOutput), @"log.txt")); exitCode = (TagDiffResult.ExitCode)Helper.RunProcess(appInspectorPath, args); string testContent = File.ReadAllText(Path.Combine(Helper.GetPath(Helper.AppPath.testOutput), @"log.txt")); exitCode = testContent.ToLower().Contains("error") ? TagDiffResult.ExitCode.TestPassed : TagDiffResult.ExitCode.CriticalError; } catch (Exception) { exitCode = TagDiffResult.ExitCode.CriticalError; } Assert.IsTrue(exitCode == TagDiffResult.ExitCode.TestPassed); }
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 } //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 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); }
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 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 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; } Assert.IsTrue(exitCode == TagDiffResult.ExitCode.TestPassed); }
public void NoResults_Fail() { TagDiffOptions options = new() { SourcePath1 = new string[] { Path.Combine(Helper.GetPath(Helper.AppPath.testSource), @"unzipped\simple\empty.cpp") }, SourcePath2 = new string[] { Path.Combine(Helper.GetPath(Helper.AppPath.testSource), @"unzipped\simple\blank.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.CriticalError); }
public void DefaultWithCustomRules_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 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.TestFailed); }