public Initialise ( string fileName, bool loadExisting ) : bool | ||
fileName | string | The filename to save to |
loadExisting | bool | |
return | bool |
/// <summary> /// This is the initial console harness - it may become the full thing /// </summary> /// <param name="args"></param> /// <returns></returns> static int Main(string[] args) { var returnCode = 0; var returnCodeOffset = 0; AppDomain.CurrentDomain.UnhandledException += CurrentDomainOnUnhandledException; try { CommandLineParser parser; if (!ParseCommandLine(args, out parser)) return parser.ReturnCodeOffset + 1; LogManager.GetRepository().Threshold = parser.LogLevel; returnCodeOffset = parser.ReturnCodeOffset; var filter = BuildFilter(parser); var perfCounter = CreatePerformanceCounter(parser); string outputFile; if (!GetFullOutputFile(parser, out outputFile)) return returnCodeOffset + 1; using (var container = new Bootstrapper(Logger)) { var persistance = new FilePersistance(parser, Logger); container.Initialise(filter, parser, persistance, perfCounter); if (!persistance.Initialise(outputFile, parser.MergeExistingOutputFile)) return returnCodeOffset + 1; returnCode = RunWithContainer(parser, container, persistance); } perfCounter.ResetCounters(); } catch (ExitApplicationWithoutReportingException) { Logger.ErrorFormat("If you are unable to resolve the issue please contact the OpenCover development team"); Logger.ErrorFormat("see https://www.github.com/opencover/opencover/issues"); returnCode = returnCodeOffset + 1; } catch (Exception ex) { Logger.Fatal("At: Program.Main"); Logger.FatalFormat("An {0} occured: {1}", ex.GetType(), ex.Message); Logger.FatalFormat("stack: {0}", ex.StackTrace); Logger.FatalFormat("A report has been sent to the OpenCover development team."); Logger.ErrorFormat("If you are unable to resolve the issue please contact the OpenCover development team"); Logger.ErrorFormat("see https://www.github.com/opencover/opencover/issues"); ReportCrash(ex); returnCode = returnCodeOffset + 1; } return returnCode; }
public void SetUp() { _mockCommandLine = new Mock<ICommandLine>(); _filePath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); _persistence = new FilePersistance(_mockCommandLine.Object); _persistence.Initialise(_filePath); _textWriter = Console.Out; var stringWriter = new StringWriter(new StringBuilder()); Console.SetOut(stringWriter); }
public void Commit_CreatesFile() { // arrange var persistence = new FilePersistance(_mockCommandLine.Object, _mockLogger.Object); persistence.Initialise(_filePath, false); persistence.PersistModule(new Module{Classes = new Class[0]}); // act persistence.Commit(); // assert Assert.IsTrue(File.Exists(_filePath)); }
public void CanLoadExistingFileWhenInitialising() { // arrange var moduleHash = Guid.NewGuid().ToString(); var persistence = new FilePersistance(_mockCommandLine.Object, _mockLogger.Object); persistence.Initialise(_filePath, false); var point = new SequencePoint() // BranchPoints within SequencePoint shorther than 3 characters will be removed {StartLine = 1, EndLine = 1, StartColumn = 1, EndColumn = 4}; var branchPoint = new BranchPoint{Path = 0, OffsetPoints = new List<int>()}; var branchPoint2 = new BranchPoint { Path = 1, OffsetPoints = new List<int>{1,2}}; var file = new OpenCover.Framework.Model.File(); var filref = new FileRef() {UniqueId = file.UniqueId}; persistence.PersistModule(new Module { Summary = new Summary {NumSequencePoints = 1}, Files = new[] {file}, ModuleHash = moduleHash, Classes = new[] { new Class { Summary = new Summary {NumSequencePoints = 1}, Files = new[] {file}, Methods = new[] { new Method { FileRef = filref, MetadataToken = 1234, Summary = new Summary {NumSequencePoints = 1}, MethodPoint = point, SequencePoints = new[] {point}, BranchPoints = new[] {branchPoint, branchPoint2} } } } } }); persistence.Commit(); var persistence2 = new FilePersistance(_mockCommandLine.Object, _mockLogger.Object); // act persistence2.Initialise(_filePath, true); // assert Assert.IsNotNull(persistence2.CoverageSession); Assert.AreEqual(moduleHash, persistence2.CoverageSession.Modules[0].ModuleHash); Assert.AreEqual(point.UniqueSequencePoint, persistence2.CoverageSession.Modules[0].Classes[0].Methods[0].SequencePoints[0].UniqueSequencePoint); Assert.AreEqual(point.UniqueSequencePoint, persistence2.CoverageSession.Modules[0].Classes[0].Methods[0].MethodPoint.UniqueSequencePoint); var method = persistence2.CoverageSession.Modules[0].Classes[0].Methods[0]; var br1 = persistence2.CoverageSession.Modules[0].Classes[0].Methods[0].BranchPoints[0]; var br2 = persistence2.CoverageSession.Modules[0].Classes[0].Methods[0].BranchPoints[1]; Assert.AreEqual(branchPoint.UniqueSequencePoint, br1.UniqueSequencePoint); Assert.AreEqual(branchPoint2.UniqueSequencePoint, br2.UniqueSequencePoint); Assert.AreEqual(0, br1.OffsetPoints.Count); Assert.AreEqual(2, br2.OffsetPoints.Count); Assert.AreEqual(1, br2.OffsetPoints[0]); Assert.AreEqual(2, br2.OffsetPoints[1]); // the method and sequence point if point to same offset need to merge Assert.AreSame(method.MethodPoint, method.SequencePoints[0]); // the loaded summary object needs to be cleared Assert.AreEqual(0, persistence2.CoverageSession.Summary.NumSequencePoints); Assert.AreEqual(0, persistence2.CoverageSession.Modules[0].Summary.NumSequencePoints); Assert.AreEqual(0, persistence2.CoverageSession.Modules[0].Classes[0].Summary.NumSequencePoints); Assert.AreEqual(0, persistence2.CoverageSession.Modules[0].Classes[0].Methods[0].Summary.NumSequencePoints); }
/// <summary> /// This is the initial console harness - it may become the full thing /// </summary> /// <param name="args"></param> /// <returns></returns> static int Main(string[] args) { var returnCode = 0; try { CommandLineParser parser; if (ParseCommandLine(args, out parser)) return returnCode; var filter = BuildFilter(parser); string outputFile; if (GetFullOutputFile(parser, out outputFile)) return returnCode; var container = new Bootstrapper(); var persistance = new FilePersistance(parser); container.Initialise(filter, parser, persistance); persistance.Initialise(outputFile); bool registered = false; try { if (parser.Register) { ProfilerRegistration.Register(parser.UserRegistration); registered = true; } var harness = (IProfilerManager)container.Container.Resolve(typeof(IProfilerManager), null); harness.RunProcess((environment) => { var startInfo = new ProcessStartInfo(Path.Combine(Environment.CurrentDirectory, parser.Target)); environment(startInfo.EnvironmentVariables); startInfo.Arguments = parser.TargetArgs; startInfo.UseShellExecute = false; startInfo.WorkingDirectory = parser.TargetDir; var process = Process.Start(startInfo); process.WaitForExit(); if (parser.ReturnTargetCode) returnCode = process.ExitCode; }); DisplayResults(persistance, parser); } catch (Exception ex) { Trace.WriteLine(string.Format("Exception: {0}\n{1}", ex.Message, ex.InnerException)); throw; } finally { if (parser.Register && registered) ProfilerRegistration.Unregister(parser.UserRegistration); } } catch (Exception ex) { System.Console.WriteLine(); System.Console.WriteLine("An exception occured: {0}", ex.Message); System.Console.WriteLine("stack: {0}", ex.StackTrace); } return returnCode; }
/// <summary> /// This is the initial console harness - it may become the full thing /// </summary> /// <param name="args"></param> /// <returns></returns> static int Main(string[] args) { var returnCode = 0; var returnCodeOffset = 0; var logger = LogManager.GetLogger(typeof (Bootstrapper)); try { CommandLineParser parser; if (!ParseCommandLine(args, out parser)) return parser.ReturnCodeOffset + 1; LogManager.GetRepository().Threshold = parser.LogLevel; returnCodeOffset = parser.ReturnCodeOffset; var filter = BuildFilter(parser); string outputFile; if (!GetFullOutputFile(parser, out outputFile)) return returnCodeOffset + 1; var container = new Bootstrapper(logger); var persistance = new FilePersistance(parser, logger); container.Initialise(filter, parser, persistance); persistance.Initialise(outputFile); var registered = false; try { if (parser.Register) { ProfilerRegistration.Register(parser.UserRegistration); registered = true; } var harness = (IProfilerManager)container.Container.Resolve(typeof(IProfilerManager), null); harness.RunProcess((environment) => { returnCode = 0; if (parser.Service) { RunService(parser, environment, logger); } else { returnCode = RunProcess(parser, environment); } }, parser.Service); DisplayResults(persistance, parser, logger); } catch (Exception ex) { Trace.WriteLine(string.Format("Exception: {0}\n{1}", ex.Message, ex.InnerException)); throw; } finally { if (parser.Register && registered) ProfilerRegistration.Unregister(parser.UserRegistration); } } catch (Exception ex) { if (logger.IsFatalEnabled) { logger.FatalFormat("An exception occured: {0}", ex.Message); logger.FatalFormat("stack: {0}", ex.StackTrace); } returnCode = returnCodeOffset + 1; } return returnCode; }
/// <summary> /// This is the initial console harness - it may become the full thing /// </summary> /// <param name="args"></param> /// <returns></returns> static int Main(string[] args) { int returnCode; var returnCodeOffset = 0; try { CommandLineParser parser; if (!ParseCommandLine(args, out parser)) return parser.ReturnCodeOffset + 1; LogManager.GetRepository().Threshold = parser.LogLevel; returnCodeOffset = parser.ReturnCodeOffset; var filter = BuildFilter(parser); var perfCounter = CreatePerformanceCounter(parser); string outputFile; if (!GetFullOutputFile(parser, out outputFile)) return returnCodeOffset + 1; using (var container = new Bootstrapper(Logger)) { var persistance = new FilePersistance(parser, Logger); container.Initialise(filter, parser, persistance, perfCounter); persistance.Initialise(outputFile, parser.MergeExistingOutputFile); returnCode = RunWithContainer(parser, container, persistance); } perfCounter.ResetCounters(); } catch (Exception ex) { if (Logger.IsFatalEnabled) { Logger.FatalFormat("An exception occured: {0}", ex.Message); Logger.FatalFormat("stack: {0}", ex.StackTrace); } returnCode = returnCodeOffset + 1; } return returnCode; }
/// <summary> /// This is the initial console harness - it may become the full thing /// </summary> /// <param name="args"></param> /// <returns></returns> static int Main(string[] args) { var returnCode = 0; var returnCodeOffset = 0; var logger = LogManager.GetLogger(typeof (Bootstrapper)); try { CommandLineParser parser; if (!ParseCommandLine(args, out parser)) return parser.ReturnCodeOffset + 1; LogManager.GetRepository().Threshold = parser.LogLevel; returnCodeOffset = parser.ReturnCodeOffset; var filter = BuildFilter(parser); string outputFile; if (!GetFullOutputFile(parser, out outputFile)) return returnCodeOffset + 1; IPerfCounters perfCounter = new NullPerfCounter(); if (parser.EnablePerformanceCounters) { if (new WindowsPrincipal(WindowsIdentity.GetCurrent()).IsInRole(WindowsBuiltInRole.Administrator)) { perfCounter = new PerfCounters(); } else { throw new InvalidCredentialException("You must be running as an Administrator to enable performance counters."); } } using (var container = new Bootstrapper(logger)) { var persistance = new FilePersistance(parser, logger); container.Initialise(filter, parser, persistance, perfCounter); persistance.Initialise(outputFile); var registered = false; try { if (parser.Register) { ProfilerRegistration.Register(parser.Registration); registered = true; } var harness = container.Resolve<IProfilerManager>(); harness.RunProcess((environment) => { returnCode = 0; if (parser.Service) { RunService(parser, environment, logger); } else { returnCode = RunProcess(parser, environment); } }, parser.Service); DisplayResults(persistance, parser, logger); } catch (Exception ex) { Trace.WriteLine(string.Format("Exception: {0}\n{1}", ex.Message, ex.InnerException)); throw; } finally { if (parser.Register && registered) ProfilerRegistration.Unregister(parser.Registration); } } perfCounter.ResetCounters(); } catch (Exception ex) { if (logger.IsFatalEnabled) { logger.FatalFormat("An exception occured: {0}", ex.Message); logger.FatalFormat("stack: {0}", ex.StackTrace); } returnCode = returnCodeOffset + 1; } return returnCode; }
/// <summary> /// This is the initial console harness - it may become the full thing /// </summary> /// <param name="args"></param> /// <returns></returns> static int Main(string[] args) { int returnCode; var returnCodeOffset = 0; AppDomain.CurrentDomain.UnhandledException += CurrentDomainOnUnhandledException; try { //throw new NullReferenceException(); CommandLineParser parser; if (!ParseCommandLine(args, out parser)) return parser.ReturnCodeOffset + 1; LogManager.GetRepository().Threshold = parser.LogLevel; returnCodeOffset = parser.ReturnCodeOffset; var filter = BuildFilter(parser); var perfCounter = CreatePerformanceCounter(parser); string outputFile; if (!GetFullOutputFile(parser, out outputFile)) return returnCodeOffset + 1; using (var container = new Bootstrapper(Logger)) { var persistance = new FilePersistance(parser, Logger); container.Initialise(filter, parser, persistance, perfCounter); persistance.Initialise(outputFile, parser.MergeExistingOutputFile); returnCode = RunWithContainer(parser, container, persistance); } perfCounter.ResetCounters(); } catch (Exception ex) { if (Logger.IsFatalEnabled) { Logger.FatalFormat("An exception occured: {0}", ex.Message); Logger.FatalFormat("stack: {0}", ex.StackTrace); Logger.FatalFormat("A report has been sent to the OenCover development team..."); } ReportCrash(ex); returnCode = returnCodeOffset + 1; } return returnCode; }