Ejemplo n.º 1
0
        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);
            });
        }
Ejemplo n.º 2
0
        private ModuleRepository GenerateWorkspaceRepo(WorkspaceEvaluationHelper helper, SimpleGraph file2file, int[] selectedFiles)
        {
            XAssert.IsTrue(file2file.IsDAG(), "Must be a DAG");
            var specs = selectedFiles
                        .Select(i =>
            {
                var specsToImport = file2file.OutgoingEdges(i).Select(e => e.Dest).ToList();
                var specContent   = GenerateSpec(i, specsToImport);
                return(new ModuleRepository.NameContentPair(GetSpecName(i), specContent));
            })
                        .Concat(new[]
            {
                new ModuleRepository.NameContentPair(HelperSpecName, GetHelperSpecContent()),
                new ModuleRepository.NameContentPair(Qualifier, GetSpecWithDefaultQualifierContent()),
            })
                        .ToArray();

            return(helper.NewModuleRepoWithPrelude().AddContent(TestModule, specs));
        }