コード例 #1
0
ファイル: GraphBasedTestBase.cs プロジェクト: uilit/BuildXL
        public async Task TestSpec2SpecMapGeneratedByTypeChecker(SimpleGraph file2file)
        {
            var helper    = new WorkspaceEvaluationHelper(TestOutputDirectory, null, forTesting: true);
            var repo      = GenerateFullWorkspaceRepo(helper, file2file);
            var workspace = await helper.ParseAsync(repo);

            var semanticModel = helper.Typecheck(workspace);

            Func <int, AbsolutePath> specIdxToSpecPath = (specIdx) => SpecIdxToSpecPath(repo, specIdx);
            var relevantSpecPaths = file2file.Nodes.Select(specIdxToSpecPath).ToList();
            Func <RoaringBitSet, IEnumerable <AbsolutePath> > materializeRelevant = (bitSet) =>
            {
                bitSet.MaterializeSetIfNeeded(string.Empty, (s, i) => workspace.GetAllSourceFiles()[i].GetAbsolutePath(helper.PathTable));
                return(bitSet.MaterializedSetOfPaths.Intersect(relevantSpecPaths));
            };

            // test the spec2spec map generated by TypeChecker
            XAssert.All(
                file2file.Nodes,
                specIdx =>
            {
                var specSourceFile       = workspace.GetSourceFile(SpecIdxToSpecPath(repo, specIdx));
                var computedDependencies = materializeRelevant(semanticModel.GetFileDependenciesOf(specSourceFile));
                var computedDependents   = materializeRelevant(semanticModel.GetFileDependentFilesOf(specSourceFile));
                var expectedDependents   = file2file.OutgoingEdges(specIdx).Select(e => specIdxToSpecPath(e.Dest));
                var expectedDependencies = file2file.IncomingEdges(specIdx).Select(e => specIdxToSpecPath(e.Src));

                XAssert.SetEqual(expectedDependencies, computedDependents);
                XAssert.SetEqual(expectedDependents, computedDependencies);
            });
        }
コード例 #2
0
        private string GenerateSpecContent(int specIndex, SimpleGraph dependencyGraph)
        {
            var incomingEdges          = dependencyGraph.IncomingEdges(specIndex).ToList();
            var sumOfImportsExpression = incomingEdges.Any()
                ? string.Join("+", incomingEdges.Select(edge => $"exportVar{edge.Src}"))
                : "0";
            var specLines = new[]
            {
                $"namespace MySpecTest {{",
                $"    export const exportVar{specIndex} = 42;",
                $"    const localVarThatDependsOnOtherSpecs{specIndex} = {sumOfImportsExpression};",
                $"}}"
            };

            return(string.Join(Environment.NewLine, specLines));
        }