//[PexFactoryMethod(typeof(CategoryExpression))] public static CategoryExpression Create([PexAssumeUnderTest]String s) { Regex ex = new Regex("*;*"); //a;b - PexAssume.IsTrue(ex.IsMatch(s));// && (s.Contains(",") && s.Contains(";"))); CategoryExpression categoryExpression = new CategoryExpression(s); return categoryExpression; }
//[PexFactoryMethod(typeof(CategoryExpression))] public static CategoryExpression Create([PexAssumeUnderTest] String s) { Regex ex = new Regex("*;*"); //a;b - PexAssume.IsTrue(ex.IsMatch(s));// && (s.Contains(",") && s.Contains(";"))); CategoryExpression categoryExpression = new CategoryExpression(s); return(categoryExpression); }
public int Execute( ConsoleOptions options ) { XmlTextReader transformReader = GetTransformReader(options); if(transformReader == null) return FILE_NOT_FOUND; TextWriter outWriter = Console.Out; bool redirectOutput = options.output != null && options.output != string.Empty; if ( redirectOutput ) { StreamWriter outStreamWriter = new StreamWriter( options.output ); outStreamWriter.AutoFlush = true; outWriter = outStreamWriter; } TextWriter errorWriter = Console.Error; bool redirectError = options.err != null && options.err != string.Empty; if ( redirectError ) { StreamWriter errorStreamWriter = new StreamWriter( options.err ); errorStreamWriter.AutoFlush = true; errorWriter = errorStreamWriter; } TestRunner testRunner = MakeRunnerFromCommandLine( options ); try { if (testRunner.Test == null) { testRunner.Unload(); Console.Error.WriteLine("Unable to locate fixture {0}", options.fixture); return FIXTURE_NOT_FOUND; } EventCollector collector = new EventCollector( options, outWriter, errorWriter ); TestFilter testFilter = TestFilter.Empty; if ( options.run != null && options.run != string.Empty ) { Console.WriteLine( "Selected test: " + options.run ); testFilter = new SimpleNameFilter( options.run ); } if ( options.include != null && options.include != string.Empty ) { Console.WriteLine( "Included categories: " + options.include ); TestFilter includeFilter = new CategoryExpression( options.include ).Filter; if ( testFilter.IsEmpty ) testFilter = includeFilter; else testFilter = new AndFilter( testFilter, includeFilter ); } if ( options.exclude != null && options.exclude != string.Empty ) { Console.WriteLine( "Excluded categories: " + options.exclude ); TestFilter excludeFilter = new NotFilter( new CategoryExpression( options.exclude ).Filter ); if ( testFilter.IsEmpty ) testFilter = excludeFilter; else if ( testFilter is AndFilter ) ((AndFilter)testFilter).Add( excludeFilter ); else testFilter = new AndFilter( testFilter, excludeFilter ); } TestResult result = null; string savedDirectory = Environment.CurrentDirectory; TextWriter savedOut = Console.Out; TextWriter savedError = Console.Error; try { result = testRunner.Run( collector, testFilter ); } finally { outWriter.Flush(); errorWriter.Flush(); if ( redirectOutput ) outWriter.Close(); if ( redirectError ) errorWriter.Close(); Environment.CurrentDirectory = savedDirectory; Console.SetOut( savedOut ); Console.SetError( savedError ); } Console.WriteLine(); string xmlOutput = CreateXmlOutput( result ); if (options.xmlConsole) { Console.WriteLine(xmlOutput); } else { try { //CreateSummaryDocument(xmlOutput, transformReader ); XmlResultTransform xform = new XmlResultTransform( transformReader ); xform.Transform( new StringReader( xmlOutput ), Console.Out ); } catch( Exception ex ) { Console.WriteLine( "Error: {0}", ex.Message ); return TRANSFORM_ERROR; } } // Write xml output here string xmlResultFile = options.xml == null || options.xml == string.Empty ? "TestResult.xml" : options.xml; using ( StreamWriter writer = new StreamWriter( xmlResultFile ) ) { writer.Write(xmlOutput); } //if ( testRunner != null ) // testRunner.Unload(); if ( collector.HasExceptions ) { collector.WriteExceptions(); return UNEXPECTED_ERROR; } if ( !result.IsFailure ) return OK; ResultSummarizer summ = new ResultSummarizer( result ); return summ.FailureCount; } finally { testRunner.Unload(); } }
public int Execute( ConsoleOptions options ) { this.workDir = options.work; if (workDir == null || workDir == string.Empty) workDir = Environment.CurrentDirectory; else { workDir = Path.GetFullPath(workDir); if (!Directory.Exists(workDir)) Directory.CreateDirectory(workDir); } TextWriter outWriter = Console.Out; bool redirectOutput = options.output != null && options.output != string.Empty; if ( redirectOutput ) { StreamWriter outStreamWriter = new StreamWriter( Path.Combine(workDir, options.output) ); outStreamWriter.AutoFlush = true; outWriter = outStreamWriter; } TextWriter errorWriter = Console.Error; bool redirectError = options.err != null && options.err != string.Empty; if ( redirectError ) { StreamWriter errorStreamWriter = new StreamWriter( Path.Combine(workDir, options.err) ); errorStreamWriter.AutoFlush = true; errorWriter = errorStreamWriter; } TestPackage package = MakeTestPackage(options); ProcessModel processModel = package.Settings.Contains("ProcessModel") ? (ProcessModel)package.Settings["ProcessModel"] : ProcessModel.Default; DomainUsage domainUsage = package.Settings.Contains("DomainUsage") ? (DomainUsage)package.Settings["DomainUsage"] : DomainUsage.Default; RuntimeFramework framework = package.Settings.Contains("RuntimeFramework") ? (RuntimeFramework)package.Settings["RuntimeFramework"] : RuntimeFramework.CurrentFramework; #if CLR_2_0 || CLR_4_0 Console.WriteLine("ProcessModel: {0} DomainUsage: {1}", processModel, domainUsage); Console.WriteLine("Execution Runtime: {0}", framework); #else Console.WriteLine("DomainUsage: {0}", domainUsage); if (processModel != ProcessModel.Default && processModel != ProcessModel.Single) Console.WriteLine("Warning: Ignoring project setting 'processModel={0}'", processModel); if (!RuntimeFramework.CurrentFramework.Supports(framework)) Console.WriteLine("Warning: Ignoring project setting 'runtimeFramework={0}'", framework); #endif using (TestRunner testRunner = new DefaultTestRunnerFactory().MakeTestRunner(package)) { testRunner.Load(package); if (testRunner.Test == null) { testRunner.Unload(); Console.Error.WriteLine("Unable to locate fixture {0}", options.fixture); return FIXTURE_NOT_FOUND; } EventCollector collector = new EventCollector( options, outWriter, errorWriter ); TestFilter testFilter = TestFilter.Empty; SimpleNameFilter nameFilter = new SimpleNameFilter(); if ( options.run != null && options.run != string.Empty ) { Console.WriteLine( "Selected test(s): " + options.run ); foreach (string name in TestNameParser.Parse(options.run)) nameFilter.Add(name); testFilter = nameFilter; } if (options.runlist != null && options.runlist != string.Empty) { Console.WriteLine("Run list: " + options.runlist); using (StreamReader rdr = new StreamReader(options.runlist)) { // NOTE: We can't use rdr.EndOfStream because it's // not present in .NET 1.x. string line = rdr.ReadLine(); while (line != null) { if (line[0] != '#') nameFilter.Add(line); line = rdr.ReadLine(); } } testFilter = nameFilter; } if ( options.include != null && options.include != string.Empty ) { TestFilter includeFilter = new CategoryExpression( options.include ).Filter; Console.WriteLine("Included categories: " + includeFilter.ToString()); if (testFilter.IsEmpty) testFilter = includeFilter; else testFilter = new AndFilter( testFilter, includeFilter ); } if ( options.exclude != null && options.exclude != string.Empty ) { TestFilter excludeFilter = new NotFilter( new CategoryExpression( options.exclude ).Filter ); Console.WriteLine("Excluded categories: " + excludeFilter.ToString()); if ( testFilter.IsEmpty ) testFilter = excludeFilter; else if ( testFilter is AndFilter ) ((AndFilter)testFilter).Add( excludeFilter ); else testFilter = new AndFilter( testFilter, excludeFilter ); } if (testFilter is NotFilter) ((NotFilter)testFilter).TopLevel = true; TestResult result = null; string savedDirectory = Environment.CurrentDirectory; TextWriter savedOut = Console.Out; TextWriter savedError = Console.Error; try { result = testRunner.Run( collector, testFilter, false, LoggingThreshold.Off ); } finally { outWriter.Flush(); errorWriter.Flush(); if ( redirectOutput ) outWriter.Close(); if ( redirectError ) errorWriter.Close(); Environment.CurrentDirectory = savedDirectory; Console.SetOut( savedOut ); Console.SetError( savedError ); } Console.WriteLine(); int returnCode = UNEXPECTED_ERROR; if (result != null) { string xmlOutput = CreateXmlOutput(result); ResultSummarizer summary = new ResultSummarizer(result); if (options.xmlConsole) { Console.WriteLine(xmlOutput); } else { WriteSummaryReport(summary); if (summary.ErrorsAndFailures > 0 || result.IsError || result.IsFailure) { if (options.stoponerror) { Console.WriteLine("Test run was stopped after first error, as requested."); Console.WriteLine(); } WriteErrorsAndFailuresReport(result); } if (summary.TestsNotRun > 0) WriteNotRunReport(result); if (!options.noresult) { // Write xml output here string xmlResultFile = options.result == null || options.result == string.Empty ? "TestResult.xml" : options.result; using (StreamWriter writer = new StreamWriter(Path.Combine(workDir, xmlResultFile))) { writer.Write(xmlOutput); } } } returnCode = summary.ErrorsAndFailures; } if ( collector.HasExceptions ) { collector.WriteExceptions(); returnCode = UNEXPECTED_ERROR; } return returnCode; } }
public int Execute( ConsoleOptions options ) { TextWriter outWriter = Console.Out; bool redirectOutput = options.output != null && options.output != string.Empty; if ( redirectOutput ) { StreamWriter outStreamWriter = new StreamWriter( options.output ); outStreamWriter.AutoFlush = true; outWriter = outStreamWriter; } TextWriter errorWriter = Console.Error; bool redirectError = options.err != null && options.err != string.Empty; if ( redirectError ) { StreamWriter errorStreamWriter = new StreamWriter( options.err ); errorStreamWriter.AutoFlush = true; errorWriter = errorStreamWriter; } TestPackage package = MakeTestPackage(options); Console.WriteLine("ProcessModel: {0} DomainUsage: {1}", package.Settings.Contains("ProcessModel") ? package.Settings["ProcessModel"] : "Default", package.Settings.Contains("DomainUsage") ? package.Settings["DomainUsage"] : "Default"); Console.WriteLine("Execution Runtime: {0}", package.Settings.Contains("RuntimeFramework") ? package.Settings["RuntimeFramework"] : "Default"); using (TestRunner testRunner = new DefaultTestRunnerFactory().MakeTestRunner(package)) { testRunner.Load(package); if (testRunner.Test == null) { testRunner.Unload(); Console.Error.WriteLine("Unable to locate fixture {0}", options.fixture); return FIXTURE_NOT_FOUND; } EventCollector collector = new EventCollector( options, outWriter, errorWriter ); TestFilter testFilter = TestFilter.Empty; if ( options.run != null && options.run != string.Empty ) { Console.WriteLine( "Selected test(s): " + options.run ); testFilter = new SimpleNameFilter( options.run ); } if ( options.include != null && options.include != string.Empty ) { Console.WriteLine( "Included categories: " + options.include ); TestFilter includeFilter = new CategoryExpression( options.include ).Filter; if ( testFilter.IsEmpty ) testFilter = includeFilter; else testFilter = new AndFilter( testFilter, includeFilter ); } if ( options.exclude != null && options.exclude != string.Empty ) { Console.WriteLine( "Excluded categories: " + options.exclude ); TestFilter excludeFilter = new NotFilter( new CategoryExpression( options.exclude ).Filter ); if ( testFilter.IsEmpty ) testFilter = excludeFilter; else if ( testFilter is AndFilter ) ((AndFilter)testFilter).Add( excludeFilter ); else testFilter = new AndFilter( testFilter, excludeFilter ); } if (testFilter is NotFilter) ((NotFilter)testFilter).TopLevel = true; TestResult result = null; string savedDirectory = Environment.CurrentDirectory; TextWriter savedOut = Console.Out; TextWriter savedError = Console.Error; try { result = testRunner.Run( collector, testFilter ); } finally { outWriter.Flush(); errorWriter.Flush(); if ( redirectOutput ) outWriter.Close(); if ( redirectError ) errorWriter.Close(); Environment.CurrentDirectory = savedDirectory; Console.SetOut( savedOut ); Console.SetError( savedError ); } Console.WriteLine(); int returnCode = UNEXPECTED_ERROR; if (result != null) { string xmlOutput = CreateXmlOutput(result); ResultSummarizer summary = new ResultSummarizer(result); if (options.xmlConsole) { Console.WriteLine(xmlOutput); } else { WriteSummaryReport(summary); if (summary.ErrorsAndFailures > 0) WriteErrorsAndFailuresReport(result); if (summary.TestsNotRun > 0) WriteNotRunReport(result); } // Write xml output here string xmlResultFile = options.xml == null || options.xml == string.Empty ? "TestResult.xml" : options.xml; using (StreamWriter writer = new StreamWriter(xmlResultFile)) { writer.Write(xmlOutput); } returnCode = summary.ErrorsAndFailures; } if ( collector.HasExceptions ) { collector.WriteExceptions(); returnCode = UNEXPECTED_ERROR; } return returnCode; } }
internal static bool CreateTestFilter(ConsoleOptions options, out TestFilter testFilter) { testFilter = TestFilter.Empty; SimpleNameFilter nameFilter = new SimpleNameFilter(); if (options.run != null && options.run != string.Empty) { Console.WriteLine("Selected test(s): " + options.run); foreach (string name in TestNameParser.Parse(options.run)) nameFilter.Add(name); testFilter = nameFilter; } if (options.runlist != null && options.runlist != string.Empty) { Console.WriteLine("Run list: " + options.runlist); try { using (StreamReader rdr = new StreamReader(options.runlist)) { // NOTE: We can't use rdr.EndOfStream because it's // not present in .NET 1.x. string line = rdr.ReadLine(); while (line != null && line.Length > 0) { if (line[0] != '#') nameFilter.Add(line); line = rdr.ReadLine(); } } } catch (Exception e) { if (e is FileNotFoundException || e is DirectoryNotFoundException) { Console.WriteLine("Unable to locate file: " + options.runlist); return false; } throw; } testFilter = nameFilter; } if (options.include != null && options.include != string.Empty) { TestFilter includeFilter = new CategoryExpression(options.include).Filter; Console.WriteLine("Included categories: " + includeFilter.ToString()); if (testFilter.IsEmpty) testFilter = includeFilter; else testFilter = new AndFilter(testFilter, includeFilter); } if (options.exclude != null && options.exclude != string.Empty) { TestFilter excludeFilter = new NotFilter(new CategoryExpression(options.exclude).Filter); Console.WriteLine("Excluded categories: " + excludeFilter.ToString()); if (testFilter.IsEmpty) testFilter = excludeFilter; else if (testFilter is AndFilter) ((AndFilter) testFilter).Add(excludeFilter); else testFilter = new AndFilter(testFilter, excludeFilter); } if (testFilter is NotFilter) ((NotFilter) testFilter).TopLevel = true; return true; }
public int Execute(ConsoleOptions options) { var outWriter = System.Console.Out; var redirectOutput = options.output != null && options.output != string.Empty; if (redirectOutput) { var outStreamWriter = new StreamWriter(options.output); outStreamWriter.AutoFlush = true; outWriter = outStreamWriter; } var errorWriter = System.Console.Error; var redirectError = options.err != null && options.err != string.Empty; if (redirectError) { var errorStreamWriter = new StreamWriter(options.err); errorStreamWriter.AutoFlush = true; errorWriter = errorStreamWriter; } var package = MakeTestPackage(options); System.Console.WriteLine("ProcessModel: {0} DomainUsage: {1}", package.Settings.Contains("ProcessModel") ? package.Settings["ProcessModel"] : "Default", package.Settings.Contains("DomainUsage") ? package.Settings["DomainUsage"] : "Default"); System.Console.WriteLine("Execution Runtime: {0}", package.Settings.Contains("RuntimeFramework") ? package.Settings["RuntimeFramework"] : "Default"); var collector = new EventCollector(options, outWriter, errorWriter); var testFilter = TestFilter.Empty; if (options.run != null && options.run != string.Empty) { System.Console.WriteLine("Selected test(s): " + options.run); testFilter = new SimpleNameFilter(options.run); } if (options.include != null && options.include != string.Empty) { System.Console.WriteLine("Included categories: " + options.include); var includeFilter = new CategoryExpression(options.include).Filter; if (testFilter.IsEmpty) testFilter = includeFilter; else testFilter = new AndFilter(testFilter, includeFilter); } if (options.exclude != null && options.exclude != string.Empty) { System.Console.WriteLine("Excluded categories: " + options.exclude); TestFilter excludeFilter = new NotFilter(new CategoryExpression(options.exclude).Filter); if (testFilter.IsEmpty) testFilter = excludeFilter; else if (testFilter is AndFilter) ((AndFilter)testFilter).Add(excludeFilter); else testFilter = new AndFilter(testFilter, excludeFilter); } if (testFilter is NotFilter) ((NotFilter)testFilter).TopLevel = true; TestResult result; var returnCode = DoRun(options, redirectOutput, redirectError, package, outWriter, errorWriter, testFilter, out result, collector); if (returnCode != 0) return returnCode; returnCode = UNEXPECTED_ERROR; if (result != null) { var xmlOutput = CreateXmlOutput(result); var summary = new ResultSummarizer(result); if (options.xmlConsole) { System.Console.WriteLine(xmlOutput); } else { WriteSummaryReport(summary); if (summary.ErrorsAndFailures > 0) WriteErrorsAndFailuresReport(result); if (summary.TestsNotRun > 0) WriteNotRunReport(result); } // Write xml output here var xmlResultFile = options.xml == null || options.xml == string.Empty ? "TestResult.xml" : options.xml; using (var writer = new StreamWriter(xmlResultFile)) { writer.Write(xmlOutput); } returnCode = summary.ErrorsAndFailures; } if (collector.HasExceptions) { collector.WriteExceptions(); returnCode = UNEXPECTED_ERROR; } return returnCode; }