Beispiel #1
0
            public Batch(NCoverVersion version, StatusReporter statusReporter, ILogger logger)
            {
                this.version        = version;
                this.statusReporter = statusReporter;
                this.logger         = logger;

                coverageFiles = new MultiMap <string, string>();
            }
        /// <summary>
        /// Initializes the isolation provider.
        /// </summary>
        /// <param name="runtime">The runtime.</param>
        /// <param name="version">The NCover version.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="runtime"/> is null.</exception>
        public NCoverTestIsolationProvider(IRuntime runtime, NCoverVersion version)
        {
            if (runtime == null)
                throw new ArgumentNullException("runtime");

            this.runtime = runtime;
            this.version = version;
        }
Beispiel #3
0
        private static HostSetup ForceProcessorArchitectureAndRuntimeVersionIfRequired(HostSetup hostSetup, NCoverVersion version)
        {
            hostSetup = hostSetup.Copy();

            NCoverTool tool = NCoverTool.GetInstance(version, hostSetup.ProcessorArchitecture);
            hostSetup.ProcessorArchitecture = tool.NegotiateProcessorArchitecture(hostSetup.ProcessorArchitecture);
            hostSetup.RuntimeVersion = tool.NegotiateRuntimeVersion(hostSetup.RuntimeVersion);

            return hostSetup;
        }
Beispiel #4
0
        /// <summary>
        /// Initializes the isolation provider.
        /// </summary>
        /// <param name="runtime">The runtime.</param>
        /// <param name="version">The NCover version.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="runtime"/> is null.</exception>
        public NCoverTestIsolationProvider(IRuntime runtime, NCoverVersion version)
        {
            if (runtime == null)
            {
                throw new ArgumentNullException("runtime");
            }

            this.runtime = runtime;
            this.version = version;
        }
Beispiel #5
0
        public static NCoverTool GetInstance(NCoverVersion version, ProcessorArchitecture architecture)
        {
            switch (version)
            {
                case NCoverVersion.V1:
                    return new NCoverV1Tool(architecture);

                case NCoverVersion.V2:
                    return new NCoverV2Tool(architecture);

                case NCoverVersion.V3:
                    return new NCoverV3Tool(architecture);

                default:
                    throw new NotSupportedException("Unrecognized NCover version.");
            }
        }
Beispiel #6
0
        public static NCoverTool GetInstance(NCoverVersion version, ProcessorArchitecture architecture)
        {
            switch (version)
            {
            case NCoverVersion.V1:
                return(new NCoverV1Tool(architecture));

            case NCoverVersion.V2:
                return(new NCoverV2Tool(architecture));

            case NCoverVersion.V3:
                return(new NCoverV3Tool(architecture));

            default:
                throw new NotSupportedException("Unrecognized NCover version.");
            }
        }
 /// <summary>
 /// Creates a host factory.
 /// </summary>
 /// <param name="runtime">The runtime.</param>
 /// <param name="version">The NCover version.</param>
 /// <exception cref="ArgumentNullException">Thrown if <paramref name="runtime"/> is null.</exception>
 public NCoverHostFactory(IRuntime runtime, NCoverVersion version)
     : base(runtime)
 {
     this.version = version;
 }
Beispiel #8
0
        private static HostSetup ForceProcessorArchitectureAndRuntimeVersionIfRequired(HostSetup hostSetup, NCoverVersion version)
        {
            hostSetup = hostSetup.Copy();

            NCoverTool tool = NCoverTool.GetInstance(version, hostSetup.ProcessorArchitecture);

            hostSetup.ProcessorArchitecture = tool.NegotiateProcessorArchitecture(hostSetup.ProcessorArchitecture);
            hostSetup.RuntimeVersion        = tool.NegotiateRuntimeVersion(hostSetup.RuntimeVersion);

            return(hostSetup);
        }
Beispiel #9
0
 /// <summary>
 /// Creates an uninitialized host.
 /// </summary>
 /// <param name="hostSetup">The host setup.</param>
 /// <param name="logger">The logger for host message output.</param>
 /// <param name="installationPath">The runtime installation path where the hosting executable will be found.</param>
 /// <param name="version">The NCover version.</param>
 /// <exception cref="ArgumentNullException">Thrown if <paramref name="hostSetup"/>
 /// <paramref name="logger"/>, <paramref name="installationPath"/> is null.</exception>
 public NCoverHost(HostSetup hostSetup, ILogger logger, string installationPath, NCoverVersion version)
     : base(ForceProcessorArchitectureAndRuntimeVersionIfRequired(hostSetup, version), logger, installationPath)
 {
     this.version = version;
 }
Beispiel #10
0
 /// <summary>
 /// Creates an uninitialized host.
 /// </summary>
 /// <param name="hostSetup">The host setup.</param>
 /// <param name="logger">The logger for host message output.</param>
 /// <param name="installationPath">The runtime installation path where the hosting executable will be found.</param>
 /// <param name="version">The NCover version.</param>
 /// <exception cref="ArgumentNullException">Thrown if <paramref name="hostSetup"/> 
 /// <paramref name="logger"/>, <paramref name="installationPath"/> is null.</exception>
 public NCoverHost(HostSetup hostSetup, ILogger logger, string installationPath, NCoverVersion version)
     : base(ForceProcessorArchitectureAndRuntimeVersionIfRequired(hostSetup, version), logger, installationPath)
 {
     this.version = version;
 }
Beispiel #11
0
 /// <summary>
 /// Creates an NCover test isolation context.
 /// </summary>
 /// <param name="testIsolationOptions">The test isolation options.</param>
 /// <param name="logger">The logger.</param>
 /// <param name="runtime">The runtime.</param>
 /// <param name="version">The NCover version.</param>
 /// <exception cref="ArgumentNullException">Thrown if <paramref name="testIsolationOptions" />,
 /// <paramref name="logger"/> or <paramref name="runtime"/> is null.</exception>
 public NCoverTestIsolationContext(TestIsolationOptions testIsolationOptions, ILogger logger,
                                   IRuntime runtime, NCoverVersion version)
     : base(new NCoverHostFactory(runtime, version), testIsolationOptions, logger)
 {
     this.version = version;
 }
        public void GeneratesNCoverCoverageWithCorrectOptionsAndMergesIfNecessary(string factoryName, NCoverVersion version,
            string ncoverCoverageFile, bool includeLogArgument, bool runMultipleAssemblies)
        {
            string tempPath = SpecialPathPolicy.For<NCoverTestIsolationProviderIntegrationTest>().GetTempDirectory().FullName;
            string coverageFilePath = Path.Combine(tempPath, ncoverCoverageFile ?? "Coverage.xml");
            string coverageLogFilePath = Path.Combine(tempPath, "CoverageLog.txt");

            string ncoverArguments = includeLogArgument
                ? "//l \"" + coverageLogFilePath + "\"" + (version == NCoverVersion.V1 ? "" : " //ll Normal")
                : null;

            if (File.Exists(coverageFilePath))
                File.Delete(coverageFilePath);

            if (File.Exists(coverageLogFilePath))
                File.Delete(coverageLogFilePath);

            Type firstTestType = typeof(SimpleTest);
            Type secondTestType = typeof(DummyTest);

            TestLauncher launcher = new TestLauncher();
            launcher.Logger = new MarkupStreamLogger(TestLog.Default);

            launcher.TestProject.TestPackage.AddFile(new FileInfo(AssemblyUtils.GetAssemblyLocalPath(firstTestType.Assembly)));
            if (runMultipleAssemblies)
                launcher.TestProject.TestPackage.AddFile(new FileInfo(AssemblyUtils.GetAssemblyLocalPath(secondTestType.Assembly)));

            launcher.TestProject.TestRunnerFactoryName = factoryName;
            launcher.TestExecutionOptions.FilterSet = new FilterSet<ITestDescriptor>(
                new OrFilter<ITestDescriptor>(new[]
                    {
                        new TypeFilter<ITestDescriptor>(new EqualityFilter<string>(firstTestType.FullName), false),
                        new TypeFilter<ITestDescriptor>(new EqualityFilter<string>(secondTestType.FullName), false),
                    }));

            if (ncoverArguments != null)
                launcher.TestRunnerOptions.AddProperty("NCoverArguments", ncoverArguments);
            if (ncoverCoverageFile != null)
                launcher.TestRunnerOptions.AddProperty("NCoverCoverageFile", ncoverCoverageFile);

            TestLauncherResult result;
            using (new CurrentDirectorySwitcher(tempPath))
                result = launcher.Run();

            NCoverTool tool = NCoverTool.GetInstance(version, ProcessorArchitecture.MSIL);
            if (! tool.IsInstalled())
            {
                Assert.AreEqual(ResultCode.Failure, result.ResultCode);

                var logEntries = result.Report.LogEntries;
                Assert.AreEqual(1, logEntries.Count, "Expected to find a log entry.");
                Assert.AreEqual(LogSeverity.Error, logEntries[0].Severity);
                Assert.Contains(logEntries[0].Details, tool.Name + " does not appear to be installed.");
            }
            else
            {
                int passed = runMultipleAssemblies ? 2 : 1;
                int failed = 1;

                Assert.AreEqual(passed + failed, result.Statistics.RunCount);
                Assert.AreEqual(passed, result.Statistics.PassedCount);
                Assert.AreEqual(failed, result.Statistics.FailedCount);
                Assert.AreEqual(0, result.Statistics.InconclusiveCount);
                Assert.AreEqual(0, result.Statistics.SkippedCount);

                Assert.IsTrue(File.Exists(coverageFilePath),
                    "The NCover runner should have written its coverage log to '{0}'.", coverageFilePath);

                string coverageXml = File.ReadAllText(coverageFilePath);
                File.Delete(coverageFilePath);

                Assert.Contains(coverageXml, firstTestType.Name,
                    "Expected the coverage log to include information about the test method that we actually ran.\n"
                    + "In NCover v3, there is now a list of excluded 'system assemblies' in NCover.Console.exe.config which "
                    + "specifies MbUnit and Gallio by default.  For this test to run, the file must be edited such that "
                    + "these entries are removed.");

                if (runMultipleAssemblies)
                {
                    Assert.Contains(coverageXml, secondTestType.Name,
                        "Expected the coverage log to include information about the test method that we actually ran.\n"
                        + "In NCover v3, there is now a list of excluded 'system assemblies' in NCover.Console.exe.config which "
                        + "specifies MbUnit and Gallio by default.  For this test to run, the file must be edited such that "
                        + "these entries are removed.");
                }

                if (ncoverArguments != null && ncoverArguments.Contains("/l"))
                {
                    Assert.IsTrue(File.Exists(coverageLogFilePath),
                        "Should have created a coverage log file since the /l argument was specified.");
                    File.Delete(coverageLogFilePath);
                }
            }
        }
 /// <summary>
 /// Creates a host factory.
 /// </summary>
 /// <param name="runtime">The runtime.</param>
 /// <param name="version">The NCover version.</param>
 /// <exception cref="ArgumentNullException">Thrown if <paramref name="runtime"/> is null.</exception>
 public NCoverHostFactory(IRuntime runtime, NCoverVersion version)
     : base(runtime)
 {
     this.version = version;
 }
        public void GeneratesNCoverCoverageWithCorrectOptionsAndMergesIfNecessary(string factoryName, NCoverVersion version,
                                                                                  string ncoverCoverageFile, bool includeLogArgument, bool runMultipleAssemblies)
        {
            string tempPath            = SpecialPathPolicy.For <NCoverTestIsolationProviderIntegrationTest>().GetTempDirectory().FullName;
            string coverageFilePath    = Path.Combine(tempPath, ncoverCoverageFile ?? "Coverage.xml");
            string coverageLogFilePath = Path.Combine(tempPath, "CoverageLog.txt");

            string ncoverArguments = includeLogArgument
                ? "//l \"" + coverageLogFilePath + "\"" + (version == NCoverVersion.V1 ? "" : " //ll Normal")
                : null;

            if (File.Exists(coverageFilePath))
            {
                File.Delete(coverageFilePath);
            }

            if (File.Exists(coverageLogFilePath))
            {
                File.Delete(coverageLogFilePath);
            }

            Type firstTestType  = typeof(SimpleTest);
            Type secondTestType = typeof(DummyTest);

            TestLauncher launcher = new TestLauncher();

            launcher.Logger = new MarkupStreamLogger(TestLog.Default);

            launcher.TestProject.TestPackage.AddFile(new FileInfo(AssemblyUtils.GetAssemblyLocalPath(firstTestType.Assembly)));
            if (runMultipleAssemblies)
            {
                launcher.TestProject.TestPackage.AddFile(new FileInfo(AssemblyUtils.GetAssemblyLocalPath(secondTestType.Assembly)));
            }

            launcher.TestProject.TestRunnerFactoryName = factoryName;
            launcher.TestExecutionOptions.FilterSet    = new FilterSet <ITestDescriptor>(
                new OrFilter <ITestDescriptor>(new[]
            {
                new TypeFilter <ITestDescriptor>(new EqualityFilter <string>(firstTestType.FullName), false),
                new TypeFilter <ITestDescriptor>(new EqualityFilter <string>(secondTestType.FullName), false),
            }));

            if (ncoverArguments != null)
            {
                launcher.TestRunnerOptions.AddProperty("NCoverArguments", ncoverArguments);
            }
            if (ncoverCoverageFile != null)
            {
                launcher.TestRunnerOptions.AddProperty("NCoverCoverageFile", ncoverCoverageFile);
            }

            TestLauncherResult result;

            using (new CurrentDirectorySwitcher(tempPath))
                result = launcher.Run();

            NCoverTool tool = NCoverTool.GetInstance(version, ProcessorArchitecture.MSIL);

            if (!tool.IsInstalled())
            {
                Assert.AreEqual(ResultCode.Failure, result.ResultCode);

                var logEntries = result.Report.LogEntries;
                Assert.AreEqual(1, logEntries.Count, "Expected to find a log entry.");
                Assert.AreEqual(LogSeverity.Error, logEntries[0].Severity);
                Assert.Contains(logEntries[0].Details, tool.Name + " does not appear to be installed.");
            }
            else
            {
                int passed = runMultipleAssemblies ? 2 : 1;
                int failed = 1;

                Assert.AreEqual(passed + failed, result.Statistics.RunCount);
                Assert.AreEqual(passed, result.Statistics.PassedCount);
                Assert.AreEqual(failed, result.Statistics.FailedCount);
                Assert.AreEqual(0, result.Statistics.InconclusiveCount);
                Assert.AreEqual(0, result.Statistics.SkippedCount);

                Assert.IsTrue(File.Exists(coverageFilePath),
                              "The NCover runner should have written its coverage log to '{0}'.", coverageFilePath);

                string coverageXml = File.ReadAllText(coverageFilePath);
                File.Delete(coverageFilePath);

                Assert.Contains(coverageXml, firstTestType.Name,
                                "Expected the coverage log to include information about the test method that we actually ran.\n"
                                + "In NCover v3, there is now a list of excluded 'system assemblies' in NCover.Console.exe.config which "
                                + "specifies MbUnit and Gallio by default.  For this test to run, the file must be edited such that "
                                + "these entries are removed.");

                if (runMultipleAssemblies)
                {
                    Assert.Contains(coverageXml, secondTestType.Name,
                                    "Expected the coverage log to include information about the test method that we actually ran.\n"
                                    + "In NCover v3, there is now a list of excluded 'system assemblies' in NCover.Console.exe.config which "
                                    + "specifies MbUnit and Gallio by default.  For this test to run, the file must be edited such that "
                                    + "these entries are removed.");
                }

                if (ncoverArguments != null && ncoverArguments.Contains("/l"))
                {
                    Assert.IsTrue(File.Exists(coverageLogFilePath),
                                  "Should have created a coverage log file since the /l argument was specified.");
                    File.Delete(coverageLogFilePath);
                }
            }
        }