Exemple #1
0
        public void ProjectsDiscovered()
        {
            var fs = new TestFileSystemDirectory("root",
                                                 new TestFileSystemDirectory("src",
                                                                             new TestFileSystemDirectory("Module1",
                                                                                                         new TestFileSystemDirectory("Project11")),
                                                                             new TestFileSystemDirectory("Module2"),
                                                                             new TestFileSystemDirectory("Module3",
                                                                                                         new TestFileSystemDirectory("Project31"),
                                                                                                         new TestFileSystemDirectory("Project32"))),
                                                 new TestFileSystemDirectory("output"));

            var suite = new Suite(fs);

            suite.Modules.Should().BeEmpty();

            var discovery = new ModuleProjectDiscovery(fs);

            discovery.ExtendWithDiscoveries(suite);

            suite.Modules.Should().HaveCount(3);
            suite.Modules.Should().OnlyContain(m => m.Name == "Module1" ||
                                               m.Name == "Module2" ||
                                               m.Name == "Module3");

            suite.GetModule("Module1").Projects.Should().HaveCount(1);
            suite.GetModule("Module1").Projects.Should().Contain(p => p.Name == "Project11");
            suite.GetModule("Module2").Projects.Should().HaveCount(0);
            suite.GetModule("Module3").Projects.Should().HaveCount(2);
            suite.GetModule("Module3").Projects.Should().Contain(p => p.Name == "Project31");
            suite.GetModule("Module3").Projects.Should().Contain(p => p.Name == "Project32");
        }
Exemple #2
0
        public void ExistingModulesMergedWithDiscoveredOnes()
        {
            var fs = new TestFileSystemDirectory("root",
                                                 new TestFileSystemDirectory("src",
                                                                             new TestFileSystemDirectory("Module1",
                                                                                                         new TestFileSystemDirectory
                                                                                                             ("Project11"))));

            var suite = new Suite(fs);

            var module1  = suite.GetModule("Module1");
            var projectA = module1.GetProject("ProjectA");

            module1.Projects.Should().HaveCount(1);
            module1.Projects.Should().HaveElementAt(0, projectA);

            var discovery = new ModuleProjectDiscovery(fs);

            discovery.ExtendWithDiscoveries(suite);

            suite.Modules.Should().HaveCount(1);
            suite.Modules.Should().HaveElementAt(0, module1);
            module1.Projects.Should().HaveCount(2);
            module1.Projects.Should().Contain(projectA);
            module1.Projects.Should().Contain(p => p.Name == "Project11");
        }
Exemple #3
0
        public void StoresReferenceToRoot()
        {
            var fs    = new TestFileSystemDirectory("root");
            var suite = new Suite(fs);

            suite.SuiteRoot.Should().Be(fs);
        }
Exemple #4
0
        public void SetUp()
        {
            var root    = new TestFileSystemDirectory("root");
            var goalx86 = new Goal("debug-x86", new[] { Suite.DebugGoal, new Goal("x86") });
            var goalx64 = new Goal("debug-x64", new[] { Suite.DebugGoal, new Goal("x64") });

            x86Suite = new Suite(root, new[] { goalx86, goalx64 }, goalx86);
            x64Suite = new Suite(root, new[] { goalx86, goalx64 }, goalx64);
        }
Exemple #5
0
        public void ModuleRootIsChildOfSuiteRoot()
        {
            var fs = new TestFileSystemDirectory(
                "root", new TestFileSystemDirectory(
                    "src", new TestFileSystemDirectory("test")));
            var module = new Module("test", new Suite(fs));

            module.RootDirectory.Should().Be(
                fs.GetChildDirectory("src").GetChildDirectory("test"));
        }
Exemple #6
0
        public void RootDirectoryIsSubdirectoryOfModuleRoot()
        {
            var projdir = new TestFileSystemDirectory("test");
            var fs      = new TestFileSystemDirectory(
                "root", new TestFileSystemDirectory(
                    "src", new TestFileSystemDirectory(
                        "testmod", projdir)));
            var module  = new Module("testmod", new Suite(fs));
            var project = new Project("test", module);

            project.RootDirectory.Should().Be(projdir);
        }
Exemple #7
0
        public void SetUp()
        {
            kernel = new StandardKernel();
            kernel.Bind <IFSRepositoryFingerprintFactory>().ToFactory();

            repository = new Mock <IFileSystemRepositoryAccess>();

            depRoot = new TestFileSystemDirectory("dep")
            {
                Files = new[] { "x" }
            };
            repository.Setup(r => r.GetDirectory(Path.Combine("test", "x"))).Returns(depRoot);
        }
        public void SetUp()
        {
            var root = new TestFileSystemDirectory("root");

            debugSuite   = new Suite(root, new[] { Suite.DebugGoal, Suite.ReleaseGoal }, Suite.DebugGoal);
            releaseSuite = new Suite(root, new[] { Suite.DebugGoal, Suite.ReleaseGoal }, Suite.ReleaseGoal);

            var customDebug   = new Goal("test-debug", new[] { Suite.DebugGoal });
            var customRelease = new Goal("test-release", new[] { Suite.ReleaseGoal });

            customDebugSuite   = new Suite(root, new[] { customDebug, customRelease }, customDebug);
            customReleaseSuite = new Suite(root, new[] { customDebug, customRelease }, customRelease);
        }
Exemple #9
0
        public void DeletesCacheDirectory()
        {
            var be = new Mock <IBuilderEnumerator>();

            be.Setup(b => b.GetAllPersistentBuilders()).Returns(new Type[0]);

            var parameters = new Mock <ICleanParameters>();
            var cdir       = new TestFileSystemDirectory("cache");
            var cleaner    = new CacheCleaner(cdir, be.Object);

            cdir.IsDeleted.Should().BeFalse();
            cleaner.Clean(parameters.Object);
            cdir.IsDeleted.Should().BeTrue();
        }
Exemple #10
0
        private static TestFileSystemDirectory CreateFsWithSourcesAndTests()
        {
            var fs = new TestFileSystemDirectory(
                "root",
                new TestFileSystemDirectory(
                    "src",
                    new TestFileSystemDirectory(
                        "Module1",
                        new TestFileSystemDirectory
                            ("Project11",
                            new TestFileSystemDirectory
                                ("cs",
                                new TestFileSystemDirectory
                                    ("subdir")
            {
                Files = new[] { "source3.cs" }
            })
            {
                Files = new[] { "source1.cs", "source2.cs" }
            },
                            new TestFileSystemDirectory
                                ("fs")
            {
                Files = new[] { "a.fs" }
            })),
                    new TestFileSystemDirectory(
                        "Module2"),
                    new TestFileSystemDirectory(
                        "Module3",
                        new TestFileSystemDirectory
                            ("Project31"),
                        new TestFileSystemDirectory
                            ("Project32"),
                        new TestFileSystemDirectory(
                            ("tests"),
                            new TestFileSystemDirectory("Project31.Test",
                                                        new TestFileSystemDirectory("cs")
            {
                Files = new[] { "test1.cs" }
            }),
                            new TestFileSystemDirectory("Project32.Test",
                                                        new TestFileSystemDirectory("cs")
            {
                Files = new[] { "test2.cs, test3.cs" }
            })))),
                new TestFileSystemDirectory("target"));

            return(fs);
        }
Exemple #11
0
        public void RunsBuilderOnlyOnceIfFingerprintRemains()
        {
            // Setting up the test
            var resultSet = new HashSet <TargetRelativePath>
            {
                new TargetRelativePath(String.Empty, @"a\b\c"),
                new TargetRelativePath(String.Empty, @"c\d"),
                new TargetRelativePath(String.Empty, @"e")
            };

            var realBuilder        = new Mock <IBuilder>();
            var realBuilderDeps    = new Mock <IDependencies>();
            var initialFingerprint = new Mock <IDependencyFingerprint>();
            var buildContext       = new Mock <IBuildContext>();
            var cache     = new Mock <IBuildCache>();
            var targetDir = new TestFileSystemDirectory("target");

            realBuilderDeps.Setup(dep => dep.Fingerprint).Returns(initialFingerprint.Object);

            realBuilder.Setup(b => b.Dependencies).Returns(realBuilderDeps.Object);
            realBuilder.Setup(b => b.Uid).Returns("");
            realBuilder.Setup(b => b.BuilderType).Returns(typeof(IBuilder));
            realBuilder.Setup(b => b.Run(buildContext.Object)).Returns(resultSet);
            realBuilder.Setup(b => b.CanRun()).Returns(true);

            // Creating the builder
            var cachedBuilder = new CachedBuilder(realBuilder.Object, cache.Object, targetDir);

            cachedBuilder.Dependencies.Should().Be(realBuilderDeps.Object);

            // Running the builder for the first time
            var result1 = cachedBuilder.Run(buildContext.Object);

            // ..verifying
            result1.Should().BeEquivalentTo(resultSet);
            realBuilder.Verify(b => b.Run(buildContext.Object), Times.Once());

            // Modifying cache behavior
            cache.Setup(c => c.Contains(new BuildKey(realBuilder.Object.BuilderType, ""), initialFingerprint.Object)).Returns(true);
            cache.Setup(c => c.Restore(new BuildKey(realBuilder.Object.BuilderType, ""), targetDir, It.IsAny <bool>(), It.IsAny <Regex[]>())).Returns(resultSet);

            // Running the builder for the second time
            var result2 = cachedBuilder.Run(buildContext.Object);

            // ..verifying
            result2.Should().BeEquivalentTo(resultSet);
            realBuilder.Verify(b => b.Run(buildContext.Object), Times.Once());
        }
Exemple #12
0
        public void SetUp()
        {
            kernel = new StandardKernel();
            Kernel.RegisterCoreBindings(kernel);
            kernel.Bind <IFileSystemDirectory>().ToConstant(new TestFileSystemDirectory("root")).WhenTargetHas
            <SuiteRootAttribute>();

            target = new TestFileSystemDirectory("target");
            kernel.Bind <IFileSystemDirectory>().ToConstant(target).WhenTargetHas
            <TargetRootAttribute>();

            kernel.Bind <IUserOutput>().To <TestUserOutput>();

            suite      = kernel.Get <Suite>();
            suite.Name = "test suite";
        }
Exemple #13
0
        public void NoSourceDirectoryDoesNotCauseError()
        {
            var fs = new TestFileSystemDirectory("root",
                                                 new TestFileSystemDirectory("abc"),
                                                 new TestFileSystemDirectory("output"));

            var suite = new Suite(fs);

            suite.Modules.Should().BeEmpty();

            var discovery = new ModuleProjectDiscovery(fs);

            discovery.ExtendWithDiscoveries(suite);

            suite.Modules.Should().BeEmpty();
        }
Exemple #14
0
        public void KeepsPersistentReferences()
        {
            var cdir = new TestFileSystemDirectory("cache",
                                                   new[]
            {
                new TestFileSystemDirectory("Bari.Core.Test.Build.Cache.NonPersistentReference_1"),
                new TestFileSystemDirectory("Bari.Core.Test.Build.Cache.NonPersistentReference_2"),
                new TestFileSystemDirectory("Bari.Core.Test.Build.Cache.PersistentReference_3"),
                new TestFileSystemDirectory("Bari.Core.Test.Build.Cache.PersistentReference_4")
            });

            var be = new Mock <IBuilderEnumerator>();

            be.Setup(b => b.GetAllPersistentBuilders()).Returns(new[] { typeof(PersistentReference) });

            var predicates = new SoftCleanPredicates();
            var cleaner    = new CacheCleaner(new Lazy <IFileSystemDirectory>(() => cdir), be.Object, () => predicates);

            cdir.IsDeleted.Should().BeFalse();
            ((TestFileSystemDirectory)cdir.GetChildDirectory("Bari.Core.Test.Build.Cache.NonPersistentReference_1"))
            .IsDeleted.Should().BeFalse();
            ((TestFileSystemDirectory)cdir.GetChildDirectory("Bari.Core.Test.Build.Cache.NonPersistentReference_2"))
            .IsDeleted.Should().BeFalse();
            ((TestFileSystemDirectory)cdir.GetChildDirectory("Bari.Core.Test.Build.Cache.PersistentReference_3"))
            .IsDeleted.Should().BeFalse();
            ((TestFileSystemDirectory)cdir.GetChildDirectory("Bari.Core.Test.Build.Cache.PersistentReference_4"))
            .IsDeleted.Should().BeFalse();

            var parameters = new Mock <ICleanParameters>();

            parameters.SetupGet(p => p.KeepReferences).Returns(true);

            cleaner.Clean(parameters.Object);

            cdir.IsDeleted.Should().BeFalse();
            ((TestFileSystemDirectory)cdir.GetChildDirectory("Bari.Core.Test.Build.Cache.NonPersistentReference_1"))
            .IsDeleted.Should().BeTrue();
            ((TestFileSystemDirectory)cdir.GetChildDirectory("Bari.Core.Test.Build.Cache.NonPersistentReference_2"))
            .IsDeleted.Should().BeTrue();
            ((TestFileSystemDirectory)cdir.GetChildDirectory("Bari.Core.Test.Build.Cache.PersistentReference_3"))
            .IsDeleted.Should().BeFalse();
            ((TestFileSystemDirectory)cdir.GetChildDirectory("Bari.Core.Test.Build.Cache.PersistentReference_4"))
            .IsDeleted.Should().BeFalse();
        }
Exemple #15
0
        public void ReturnsCachedIfBuilderCannotRun()
        {
            // Setting up the test
            var resultSet = new HashSet <TargetRelativePath>
            {
                new TargetRelativePath(String.Empty, @"a\b\c"),
                new TargetRelativePath(String.Empty, @"c\d"),
                new TargetRelativePath(String.Empty, @"e")
            };

            var realBuilder        = new Mock <IBuilder>();
            var realBuilderDeps    = new Mock <IDependencies>();
            var initialFingerprint = new Mock <IDependencyFingerprint>();
            var buildContext       = new Mock <IBuildContext>();
            var cache     = new Mock <IBuildCache>();
            var targetDir = new TestFileSystemDirectory("target");

            realBuilderDeps.Setup(dep => dep.Fingerprint).Returns(initialFingerprint.Object);

            realBuilder.Setup(b => b.Dependencies).Returns(realBuilderDeps.Object);
            realBuilder.Setup(b => b.BuilderType).Returns(typeof(IBuilder));
            realBuilder.Setup(b => b.Uid).Returns("");
            realBuilder.Setup(b => b.Run(buildContext.Object)).Returns(resultSet);
            realBuilder.Setup(b => b.CanRun()).Returns(true);

            // Creating the builder
            var cachedBuilder = new CachedBuilder(realBuilder.Object, cache.Object, targetDir);

            cache.Setup(c => c.ContainsAny(new BuildKey(realBuilder.Object.BuilderType, ""))).Returns(true);
            cache.Setup(c => c.Restore(new BuildKey(realBuilder.Object.BuilderType, ""), targetDir, It.IsAny <bool>(), It.IsAny <Regex[]>())).Returns(resultSet);

            // Making it wrong
            realBuilder.Setup(b => b.CanRun()).Returns(false);
            realBuilder.Setup(b => b.Run(It.IsAny <IBuildContext>())).Throws <InvalidOperationException>();

            // And trying again:
            var result2 = cachedBuilder.Run(buildContext.Object);

            result2.Should().BeEquivalentTo(resultSet);
        }
Exemple #16
0
        public void ThrowsExceptionIfBuilderCannotRunAndNoCachedResults()
        {
            // Setting up the test
            var realBuilder        = new Mock <IBuilder>();
            var realBuilderDeps    = new Mock <IDependencies>();
            var initialFingerprint = new Mock <IDependencyFingerprint>();
            var buildContext       = new Mock <IBuildContext>();
            var cache     = new Mock <IBuildCache>();
            var targetDir = new TestFileSystemDirectory("target");

            realBuilderDeps.Setup(dep => dep.Fingerprint).Returns(initialFingerprint.Object);

            realBuilder.Setup(b => b.Dependencies).Returns(realBuilderDeps.Object);
            realBuilder.Setup(b => b.Uid).Returns("");
            realBuilder.Setup(b => b.BuilderType).Returns(typeof(IBuilder));
            realBuilder.Setup(b => b.CanRun()).Returns(false);

            // Creating the builder
            var cachedBuilder = new CachedBuilder(realBuilder.Object, cache.Object, targetDir);

            // Running the builder for the first time
            cachedBuilder.Run(buildContext.Object);
        }
Exemple #17
0
 public void SetUp()
 {
     sourceSetRoot = new TestFileSystemDirectory("cpp");
 }