Exemple #1
0
 private static DTestCase FromXTestCase(XTestCase ea)
 {
     return(new DTestCase
     {
         CodeFilePath = FilePath.NewFilePath(ea.CodeFilePath),
         DisplayName = ea.DisplayName,
         DtcId = ea.Id,
         FullyQualifiedName = ea.FullyQualifiedName,
         LineNumber = DocumentCoordinate.NewDocumentCoordinate(ea.LineNumber),
         Source = FilePath.NewFilePath(ea.Source)
     });
 }
Exemple #2
0
        private static void NoteTestResults(PerTestIdDResults testResults, XTestResult tr, Func <string, string> rebaseCFP)
        {
            LogInfo("Noting Test Result: {0} - {1}", tr.DisplayName, tr.Outcome);

            var testId = new TestId(
                FilePath.NewFilePath(tr.TestCase.Source),
                new DocumentLocation(
                    FilePath.NewFilePath(tr.TestCase.CodeFilePath),
                    DocumentCoordinate.NewDocumentCoordinate(tr.TestCase.LineNumber)));

            var results = testResults.GetOrAdd(testId, _ => new ConcurrentBag <DTestResult>());

            results.Add(FromXTestResult(tr, rebaseCFP));
        }
        private static void FindSequencePointForType(RunStartParams rsp, PerDocumentSequencePoints perDocSP, ModuleDefinition module, TypeDefinition type)
        {
            foreach (MethodDefinition meth in type.Methods)
            {
                if (IsMethodSkipped(meth))
                {
                    continue;
                }

                var sps = from i in meth.Body.Instructions
                          where i.SequencePoint != null
                          where i.SequencePoint.StartLine != 0xfeefee
                          select new { module, meth, i.SequencePoint };

                int id = 0;
                foreach (var sp in sps)
                {
                    var fp     = PathBuilder.rebaseCodeFilePath(rsp.Solution.Path, rsp.Solution.SnapshotPath, FilePath.NewFilePath(sp.SequencePoint.Document.Url));
                    var seqPts = perDocSP.GetOrAdd(fp, _ => new ConcurrentBag <R4nd0mApps.TddStud10.Common.Domain.SequencePoint>());

                    seqPts.Add(new R4nd0mApps.TddStud10.Common.Domain.SequencePoint
                    {
                        id = new SequencePointId
                        {
                            methodId = new MethodId(AssemblyId.NewAssemblyId(sp.module.Mvid), MdTokenRid.NewMdTokenRid(sp.meth.MetadataToken.RID)),
                            uid      = id++
                        },
                        document    = fp,
                        startLine   = DocumentCoordinate.NewDocumentCoordinate(sp.SequencePoint.StartLine),
                        startColumn = DocumentCoordinate.NewDocumentCoordinate(sp.SequencePoint.StartColumn),
                        endLine     = DocumentCoordinate.NewDocumentCoordinate(sp.SequencePoint.EndLine),
                        endColumn   = DocumentCoordinate.NewDocumentCoordinate(sp.SequencePoint.EndColumn),
                    });
                }
            }
        }
Exemple #4
0
        private static void DiscoverUnitTests(IEnumerable <IXTestDiscoverer> tds, string slnPath, string slnSnapPath, string discoveredUnitTestsStore, string discoveredUnitDTestsStore, string buildOutputRoot, DateTime timeFilter, string[] ignoredTests)
        {
            Logger.LogInfo("DiscoverUnitTests: starting discovering.");
            var testsPerAssembly  = new PerDocumentLocationXTestCases();
            var dtestsPerAssembly = new PerDocumentLocationDTestCases();

            FindAndExecuteForEachAssembly(
                buildOutputRoot,
                timeFilter,
                (string assemblyPath) =>
            {
                var disc = new XUnitTestDiscoverer();
                disc.TestDiscovered.AddHandler(
                    new FSharpHandler <XTestCase>(
                        (o, ea) =>
                {
                    if (ea.CodeFilePath != null)
                    {
                        var cfp         = PathBuilder.rebaseCodeFilePath(FilePath.NewFilePath(slnPath), FilePath.NewFilePath(slnSnapPath), FilePath.NewFilePath(ea.CodeFilePath));
                        ea.CodeFilePath = cfp.Item;
                    }
                    var dl = new DocumentLocation {
                        document = FilePath.NewFilePath(ea.CodeFilePath), line = DocumentCoordinate.NewDocumentCoordinate(ea.LineNumber)
                    };
                    var tests = testsPerAssembly.GetOrAdd(dl, _ => new ConcurrentBag <XTestCase>());
                    tests.Add(ea);
                    var dtests = dtestsPerAssembly.GetOrAdd(dl, _ => new ConcurrentBag <DTestCase>());
                    dtests.Add(FromXTestCase(ea));
                }));
                disc.DiscoverTests(tds, FilePath.NewFilePath(assemblyPath), ignoredTests);
            });

            testsPerAssembly.Serialize(FilePath.NewFilePath(discoveredUnitTestsStore));
            dtestsPerAssembly.Serialize(FilePath.NewFilePath(discoveredUnitDTestsStore));
            Logger.LogInfo("Written discovered unit tests to {0} & {1}.", discoveredUnitTestsStore, discoveredUnitDTestsStore);
        }
        private static Tuple <bool, TestId> IsSequencePointAtStartOfAUnitTest(RunStartParams rsp, Mono.Cecil.Cil.SequencePoint sp, FilePath assemblyPath, Func <DocumentLocation, IEnumerable <DTestCase> > findTest)
        {
            if (sp == null)
            {
                return(new Tuple <bool, TestId>(false, null));
            }

            var dl = new DocumentLocation {
                document = PathBuilder.rebaseCodeFilePath(rsp.Solution.Path, rsp.Solution.SnapshotPath, FilePath.NewFilePath(sp.Document.Url)), line = DocumentCoordinate.NewDocumentCoordinate(sp.StartLine)
            };
            var test = findTest(dl).FirstOrDefault(t => t.Source.Equals(assemblyPath));

            if (test == null)
            {
                return(new Tuple <bool, TestId>(false, null));
            }
            else
            {
                return(new Tuple <bool, TestId>(
                           true,
                           new TestId(assemblyPath, dl)));
            }
        }