protected void AssertFailed(Configuration configuration, Action <PSharpRuntime> test, int numExpectedErrors, ISet <string> expectedOutputs) { InMemoryLogger logger = new InMemoryLogger(); try { var bfEngine = BugFindingEngine.Create(configuration, test); bfEngine.SetLogger(logger); bfEngine.Run(); CheckErrors(bfEngine, numExpectedErrors, expectedOutputs); if (!configuration.EnableCycleDetection) { var rEngine = ReplayEngine.Create(configuration, test, bfEngine.ReproducableTrace); rEngine.SetLogger(logger); rEngine.Run(); Assert.True(rEngine.InternalError.Length == 0, rEngine.InternalError); CheckErrors(rEngine, numExpectedErrors, expectedOutputs); } } catch (Exception ex) { Assert.False(true, ex.Message + "\n" + ex.StackTrace); } finally { logger.Dispose(); } }
protected ITestingEngine AssertSucceeded(Configuration configuration, Action <PSharpRuntime> test) { InMemoryLogger logger = new InMemoryLogger(); BugFindingEngine engine = null; try { engine = BugFindingEngine.Create(configuration, test); engine.SetLogger(logger); engine.Run(); var numErrors = engine.TestReport.NumOfFoundBugs; Assert.True(numErrors == 0, GetBugReport(engine)); } catch (Exception ex) { Assert.False(true, ex.Message + "\n" + ex.StackTrace); } finally { logger.Dispose(); } return(engine); }
protected void AssertFailedAndWarning(Configuration configuration, string test, int numExpectedErrors, int numExpectedWarnings, string expectedOutput, bool isPSharpProgram = true) { InMemoryLogger logger = new InMemoryLogger(); configuration.ShowWarnings = true; try { var context = CompileTest(configuration, test, isPSharpProgram); var engine = StaticAnalysisEngine.Create(context, logger).Run(); var numErrors = engine.ErrorReporter.ErrorCount; var numWarnings = engine.ErrorReporter.WarningCount; Assert.Equal(numExpectedErrors, numErrors); Assert.Equal(numExpectedWarnings, numWarnings); if (!string.IsNullOrEmpty(expectedOutput)) { var actual = logger.ToString(); Assert.Equal(expectedOutput.Replace(Environment.NewLine, string.Empty), actual.Replace(Environment.NewLine, string.Empty)); } } finally { logger.Dispose(); } }
protected void AssertFailedWithException(Configuration configuration, Action <PSharpRuntime> test, Type exceptionType) { Assert.True(exceptionType.IsSubclassOf(typeof(Exception)), "Please configure the test correctly. " + $"Type '{exceptionType}' is not an exception type."); InMemoryLogger logger = new InMemoryLogger(); try { var engine = BugFindingEngine.Create(configuration, test); engine.SetLogger(logger); engine.Run(); var numErrors = engine.TestReport.NumOfFoundBugs; Assert.Equal(1, numErrors); var exception = this.RemoveNonDeterministicValuesFromReport(engine.TestReport.BugReports.First()). Split(new[] { '\r', '\n' }).FirstOrDefault(); Assert.Contains("'" + exceptionType.ToString() + "'", exception); } catch (Exception ex) { Assert.False(true, ex.Message); } finally { logger.Dispose(); } }
internal static void Failed(Configuration configuration, string test, int numExpectedErrors, string expectedOutput, bool isPSharpProgram = true) { InMemoryLogger logger = new InMemoryLogger(); try { var context = CompileTest(configuration, test, isPSharpProgram); var engine = StaticAnalysisEngine.Create(context, logger).Run(); var numErrors = engine.ErrorReporter.ErrorCount; Xunit.Assert.Equal(numExpectedErrors, numErrors); if (!string.IsNullOrEmpty(expectedOutput)) { var actual = logger.ToString(); Xunit.Assert.Equal( expectedOutput.Replace(Environment.NewLine, string.Empty), actual.Substring(0, actual.IndexOf(Environment.NewLine))); } } finally { logger.Dispose(); } }
protected void AssertFailedWithException(Configuration configuration, Action <PSharpRuntime> test, Type exceptionType, bool replay) { Assert.True(exceptionType.IsSubclassOf(typeof(Exception)), "Please configure the test correctly. " + $"Type '{exceptionType}' is not an exception type."); InMemoryLogger logger = new InMemoryLogger(); try { var bfEngine = BugFindingEngine.Create(configuration, test); bfEngine.SetLogger(logger); bfEngine.Run(); CheckErrors(bfEngine, exceptionType); if (replay && !configuration.EnableCycleDetection) { var rEngine = ReplayEngine.Create(configuration, test, bfEngine.ReproducableTrace); rEngine.SetLogger(logger); rEngine.Run(); Assert.True(rEngine.InternalError.Length == 0, rEngine.InternalError); CheckErrors(rEngine, exceptionType); } } catch (Exception ex) { Assert.False(true, ex.Message + "\n" + ex.StackTrace); } finally { logger.Dispose(); } }
protected void AssertSucceeded(Configuration configuration, string test, bool isPSharpProgram = true) { InMemoryLogger logger = new InMemoryLogger(); try { var context = CompileTest(configuration, test, isPSharpProgram); var engine = StaticAnalysisEngine.Create(context, logger).Run(); var numErrors = engine.ErrorReporter.ErrorCount; var numWarnings = engine.ErrorReporter.WarningCount; Assert.Equal(0, numErrors); Assert.Equal(0, numWarnings); } finally { logger.Dispose(); } }
protected void AssertSucceeded(Configuration configuration, Action <PSharpRuntime> test) { InMemoryLogger logger = new InMemoryLogger(); try { var engine = BugFindingEngine.Create(configuration, test); engine.SetLogger(logger); engine.Run(); var numErrors = engine.TestReport.NumOfFoundBugs; Assert.Equal(0, numErrors); } catch (Exception ex) { Assert.False(true, ex.Message); } finally { logger.Dispose(); } }
protected void AssertFailed(Configuration configuration, Action <PSharpRuntime> test, int numExpectedErrors, ISet <string> expectedOutputs) { InMemoryLogger logger = new InMemoryLogger(); try { var engine = BugFindingEngine.Create(configuration, test); engine.SetLogger(logger); engine.Run(); var numErrors = engine.TestReport.NumOfFoundBugs; Assert.Equal(numExpectedErrors, numErrors); if (expectedOutputs.Count > 0) { var bugReports = new HashSet <string>(); foreach (var bugReport in engine.TestReport.BugReports) { var actual = this.RemoveNonDeterministicValuesFromReport(bugReport); bugReports.Add(actual); } foreach (var expected in expectedOutputs) { Assert.Contains(expected, bugReports); } } } catch (Exception ex) { Assert.False(true, ex.Message); } finally { logger.Dispose(); } }