public BufferedFileSystemFixture()
 {
     FileSystem = new FakeFileSystem(IsWindows ?
                                     FakeEnvironment.CreateWindowsEnvironment() :
                                     FakeEnvironment.CreateUnixEnvironment());
     Log = new FakeLog();
 }
示例#2
0
        public void Process_WillNotMissOutputViaEvents()
        {
            var environment = FakeEnvironment.CreateWindowsEnvironment();
            var log         = new FakeLog();
            var runner      = new AdvProcessRunner(environment, log);

            var settings =
                new AdvProcessSettings()
                .WithArguments(args => args.Append("--out line1 line2 --echoArgs --delay 100"))
                .UseWorkingDirectory(Environment.CurrentDirectory)
                .SetRedirectStandardOutput(true);

            var outputDataReceived = new List <string>();

            using (var process = runner.Start(_appExe, settings))
            {
                process.OutputDataReceived +=
                    (sender, args) => { outputDataReceived.Add(args.Output); };

                process.WaitForExit();

                outputDataReceived.Should()
                .BeEquivalentTo("Args received: --out line1 line2 --echoArgs --delay 100",
                                "line1", "line2");
            }
        }
示例#3
0
        public void Read_write_compare()
        {
            // Arrange
            var environment = FakeEnvironment.CreateWindowsEnvironment();
            var fileSystem  = new FakeFileSystem(environment);

            fileSystem.CreateFile("Data/Info.plist").SetContent(Resources.Info_plist.NormalizeLineEndings());
            fileSystem.CreateFile("Info_COPY.plist");
            var context = Substitute.For <ICakeContext>();

            context.FileSystem.Returns(fileSystem);
            context.Environment.Returns(environment);
            var expected = context.DeserializePlist("./Data/Info.plist");

            // Act
            PlistAliases.SerializePlist(context, "./Info_COPY.plist", expected);
            var dataCopy = context.DeserializePlist("./Info_COPY.plist");

            // Assert
            var a1 = ((Dictionary <string, object>)expected).ToArray();
            var a2 = ((Dictionary <string, object>)dataCopy).ToArray();

            // Assert.Equal is not working correct on dictionary. Therefore we iterate
            for (var i = 0; i < a1.Length; i++)
            {
                Assert.Equal(a1[i].Key, a2[i].Key);

                Assert.Equal(a1[i].Value, a2[i].Value);
            }
        }
示例#4
0
        public void Dispose_Does_Not_Kill_Underlying_Process_If_Still_Running()
        {
            var environment = FakeEnvironment.CreateWindowsEnvironment();
            var log         = new FakeLog();
            var runner      = new AdvProcessRunner(environment, log);

            var settings =
                new AdvProcessSettings()
                .UseWorkingDirectory(Environment.CurrentDirectory)
                .WithArguments(args => args.Append("--sleep 5000"));

            int processId;

            using (var process = runner.Start(_appExe, settings))
            {
                processId = process.ProcessId;
                process.HasExited.Should().BeFalse();
            }

            using (var p2 = System.Diagnostics.Process.GetProcessById(processId))
            {
                p2.HasExited.Should().BeFalse();
                p2.Kill();
            }
        }
示例#5
0
        private void PrepareWindowsFixture()
        {
            Environment = FakeEnvironment.CreateWindowsEnvironment();
            FileSystem  = new FakeFileSystem(Environment);

            // Directories
            FileSystem.CreateDirectory("C://Working");
            FileSystem.CreateDirectory("C://Working/Foo");
            FileSystem.CreateDirectory("C://Working/Foo/Bar");
            FileSystem.CreateDirectory("C:");
            FileSystem.CreateDirectory("C:/Program Files (x86)");

            // Files
            FileSystem.CreateFile("C:/Working/Foo/Bar/Qux.c");
            FileSystem.CreateFile("C:/Program Files (x86)/Foo.c");
            FileSystem.CreateFile("C:/Working/Project.A.Test.dll");
            FileSystem.CreateFile("C:/Working/Project.B.Test.dll");
            FileSystem.CreateFile("C:/Working/Project.IntegrationTest.dll");
            FileSystem.CreateFile("C:/Tools & Services/MyTool.dll");
            FileSystem.CreateFile("C:/Tools + Services/MyTool.dll");
            FileSystem.CreateFile("C:/Some %2F Directory/MyTool.dll");
            FileSystem.CreateFile("C:/Some ! Directory/MyTool.dll");
            FileSystem.CreateFile("C:/Some@Directory/MyTool.dll");

            FileSystem.CreateFile("C:/Working/foobar.rs");
            FileSystem.CreateFile("C:/Working/foobaz.rs");
            FileSystem.CreateFile("C:/Working/foobax.rs");
        }
示例#6
0
        public string EvaluateArgs(AsciiDoctorJRunnerSettings settings)
        {
            var args        = new ProcessArgumentBuilder();
            var environment = FakeEnvironment.CreateWindowsEnvironment();

            settings.Evaluate(args, environment);

            return(args.Render());
        }
示例#7
0
        //Cake
        public static ICakeEnvironment CreateEnvironment()
        {
            var environment = FakeEnvironment.CreateWindowsEnvironment();

            environment.WorkingDirectory = Directory.GetCurrentDirectory();
            environment.WorkingDirectory = environment.WorkingDirectory.Combine("../../../");

            return(environment);
        }
        public static GlobberFixture Windows()
        {
            var environment = FakeEnvironment.CreateWindowsEnvironment();
            var filesystem  = new FakeFileSystem(environment);

            // Directories
            filesystem.CreateDirectory("C://Working");
            filesystem.CreateDirectory("C://Working/Foo");
            filesystem.CreateDirectory("C://Working/Foo/Bar");
            filesystem.CreateDirectory("C:");
            filesystem.CreateDirectory("C:/Program Files (x86)");

            // UNC directories
            filesystem.CreateDirectory(@"\\Server");
            filesystem.CreateDirectory(@"\\Server\Foo");
            filesystem.CreateDirectory(@"\\Server\Foo\Bar");
            filesystem.CreateDirectory(@"\\Server\Bar");
            filesystem.CreateDirectory(@"\\Foo\Bar");
            filesystem.CreateDirectory(@"\\Foo (Bar)");
            filesystem.CreateDirectory(@"\\Foo@Bar\");
            filesystem.CreateDirectory(@"\\嵌套");
            filesystem.CreateDirectory(@"\\嵌套\目录");

            // Files
            filesystem.CreateFile("C:/Working/Foo/Bar/Qux.c");
            filesystem.CreateFile("C:/Program Files (x86)/Foo.c");
            filesystem.CreateFile("C:/Working/Project.A.Test.dll");
            filesystem.CreateFile("C:/Working/Project.B.Test.dll");
            filesystem.CreateFile("C:/Working/Project.IntegrationTest.dll");
            filesystem.CreateFile("C:/Tools & Services/MyTool.dll");
            filesystem.CreateFile("C:/Tools + Services/MyTool.dll");
            filesystem.CreateFile("C:/Some %2F Directory/MyTool.dll");
            filesystem.CreateFile("C:/Some ! Directory/MyTool.dll");
            filesystem.CreateFile("C:/Some@Directory/MyTool.dll");
            filesystem.CreateFile("C:/Working/foobar.rs");
            filesystem.CreateFile("C:/Working/foobaz.rs");
            filesystem.CreateFile("C:/Working/foobax.rs");

            // UNC files
            filesystem.CreateFile(@"\\Server\Foo/Bar/Qux.c");
            filesystem.CreateFile(@"\\Server\Foo/Bar/Qex.c");
            filesystem.CreateFile(@"\\Server\Foo/Bar/Qux.h");
            filesystem.CreateFile(@"\\Server\Foo/Baz/Qux.c");
            filesystem.CreateFile(@"\\Server\Foo/Bar/Baz/Qux.c");
            filesystem.CreateFile(@"\\Server\Bar/Qux.c");
            filesystem.CreateFile(@"\\Server\Bar/Qux.h");
            filesystem.CreateFile(@"\\Server\Foo.Bar.Test.dll");
            filesystem.CreateFile(@"\\Server\Bar.Qux.Test.dll");
            filesystem.CreateFile(@"\\Server\Quz.FooTest.dll");
            filesystem.CreateFile(@"\\Foo\Bar.baz");
            filesystem.CreateFile(@"\\Foo (Bar)\Baz.c");
            filesystem.CreateFile(@"\\Foo@Bar\Baz.c");
            filesystem.CreateFile(@"\\嵌套/目录/文件.延期");

            return(new GlobberFixture(filesystem, environment));
        }
示例#9
0
 public ScriptAnalyzerFixture(bool windows = false)
 {
     Environment = windows
         ? FakeEnvironment.CreateWindowsEnvironment()
         : FakeEnvironment.CreateUnixEnvironment();
     FileSystem = new FakeFileSystem(Environment);
     Globber    = new Globber(FileSystem, Environment);
     Log        = Substitute.For <ICakeLog>();
     Providers  = new List <ILoadDirectiveProvider>();
 }
示例#10
0
        public void Deserialize_missing_file_throws_exception()
        {
            var environment = FakeEnvironment.CreateWindowsEnvironment();
            var fileSystem  = new FakeFileSystem(environment);
            var context     = Substitute.For <ICakeContext>();

            context.FileSystem.Returns(fileSystem);
            context.Environment.Returns(environment);

            Assert.Throws <FileNotFoundException>(() => PlistAliases.DeserializePlist(context, "./file-doesnt-exist"));
        }
示例#11
0
        public ClickTwiceFixture(ITestOutputHelper output)
        {
            var environment = FakeEnvironment.CreateWindowsEnvironment();

            Environment = environment;
            var fileSystem = new FakeFileSystem(environment);

            fileSystem.CreateDirectory("./artifacts");
            //fileSystem.CreateFile(PackageFilePath.FullPath).SetContent(SamplePackageJson);
            FileSystem = fileSystem;
            Logger     = new UnitTestLogger(output);
        }
示例#12
0
        /// <summary>
        /// Ensures that the environment is a windows environment.
        /// <para>WARNING: As calling this method will remove the existing Environment
        /// and replace it with a new one, this method should be called first, before any
        /// other modifications are made.</para>
        /// </summary>
        public void GivenAWindowsEnvironment()
        {
            Environment = FakeEnvironment.CreateWindowsEnvironment();

            // re-create everything that had a reference to the old environment
            // see https://github.com/cake-build/cake/blob/main/src/Cake.Testing/Fixtures/ToolFixture%602.cs#L78
            FileSystem = new FakeFileSystem(Environment);
            Globber    = new Globber(FileSystem, Environment);
            Tools      = new ToolLocator(Environment, new ToolRepository(Environment), new ToolResolutionStrategy(FileSystem, Environment, Globber, Configuration, new NullLog()));

            // re-create the tool (as it, too, had a reference to the environment
            _tool = new GradleRunner(FileSystem, Environment, ProcessRunner, Tools);
        }
示例#13
0
            public void Should_Be_Able_To_Resolve_Path_Via_Environment_Path_Variable_On_Windows()
            {
                // Given
                var fixture = new UPackToolResolverFixture(FakeEnvironment.CreateWindowsEnvironment());

                fixture.Environment.SetEnvironmentVariable("PATH", "/temp;/stuff/programs;/programs");
                fixture.FileSystem.CreateFile("/stuff/programs/upack.exe");

                // When
                var result = fixture.Resolve();

                // Then
                Assert.Equal("/stuff/programs/upack.exe", result.FullPath);
            }
            public void Should_Prefer_ToolExeNames_With_Windows_Platform_Affinity_When_Windows_Environment(string windowsTool)
            {
                // Given
                var fixture = new ToolResolutionStrategyFixture(FakeEnvironment.CreateWindowsEnvironment());

                fixture.Repository.Register("./tool");
                fixture.Repository.Register($"./{windowsTool}");

                // When
                var result = fixture.Resolve(new[] { "tool", windowsTool });

                // Then
                Assert.Equal($"C:/Working/{windowsTool}", result.FullPath);
            }
示例#15
0
                public void Should_Expand_Existing_Environment_Variables()
                {
                    // Given
                    var environment = FakeEnvironment.CreateWindowsEnvironment();

                    environment.SetEnvironmentVariable("FOO", "bar");
                    var path = new DirectoryPath("/%FOO%/baz");

                    // When
                    var result = path.ExpandEnvironmentVariables(environment);

                    // Then
                    Assert.Equal("/bar/baz", result.FullPath);
                }
示例#16
0
                public void Should_Expand_Existing_Environment_Variables()
                {
                    // Given
                    var environment = FakeEnvironment.CreateWindowsEnvironment();

                    environment.SetEnvironmentVariable("FOO", "bar");
                    var path = new FilePath("/%FOO%/baz.qux");

                    // When
                    var result = path.ExpandEnvironmentVariables(environment);

                    // Then
                    result.FullPath.ShouldBe("/bar/baz.qux");
                }
 public void Setup()
 {
     _environment    = FakeEnvironment.CreateWindowsEnvironment();
     _log            = new FakeLog();
     _arguments      = Substitute.For <ICakeArguments>();
     _appVeyor       = Substitute.For <IAppVeyorProvider>();
     _azure          = Substitute.For <ITFBuildProvider>();
     _appEnvironment = new AppVeyorEnvironmentInfo(_environment);
     _appVeyor.Environment.Returns(_appEnvironment);
     _globber       = Substitute.For <IGlobber>();
     _fileSystem    = new FakeFileSystem(_environment);
     _processRunner = Substitute.For <IProcessRunner>();
     _toolLocator   = Substitute.For <IToolLocator>();
 }
        public static FakeEnvironment CreateFromRuntime()
        {
            var architecture = RuntimeInformation.OSArchitecture;
            var is64Bit      = architecture == Architecture.Arm64 || architecture == Architecture.X64;

            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                return(FakeEnvironment.CreateWindowsEnvironment(is64Bit));
            }
            else
            {
                return(FakeEnvironment.CreateUnixEnvironment(is64Bit));
            }
        }
示例#19
0
            public void WhenStringInput_AddsAsArgument()
            {
                TestSettings input = new TestSettings {
                    String = "tubo"
                };

                ProcessArgumentBuilder builder = new ProcessArgumentBuilder();
                var environment = FakeEnvironment.CreateWindowsEnvironment();

                environment.WorkingDirectory = ".";
                builder.AppendAll(environment, input, new FilePath[] { "arg1" });
                var actual = builder.Render();

                Assert.That(actual, Is.EqualTo("--string=\"tubo\" arg1"));
            }
示例#20
0
            public void Should_Expand_Existing_Environment_Variables()
            {
                // Given
                var context     = Substitute.For <ICakeContext>();
                var environment = FakeEnvironment.CreateWindowsEnvironment();

                environment.SetEnvironmentVariable("FOO", "bar");
                context.Environment.Returns(environment);

                // When
                var result = FileAliases.ExpandEnvironmentVariables(context, "/%FOO%/baz.qux");

                // Then
                Assert.Equal("/bar/baz.qux", result.FullPath);
            }
示例#21
0
        private void PrepareWindowsFixture()
        {
            Environment = FakeEnvironment.CreateWindowsEnvironment();
            FileSystem  = new FakeFileSystem(Environment);

            // Directories
            FileSystem.CreateDirectory("C://Working");
            FileSystem.CreateDirectory("C://Working/Foo");
            FileSystem.CreateDirectory("C://Working/Foo/Bar");
            FileSystem.CreateDirectory("C:");
            FileSystem.CreateDirectory("C:/Program Files (x86)");

            // Files
            FileSystem.CreateFile("C:/Working/Foo/Bar/Qux.c");
            FileSystem.CreateFile("C:/Program Files (x86)/Foo.c");
        }
示例#22
0
            public void Should_Throw_If_Report_Is_Undefined()
            {
                // Given
                var environment = FakeEnvironment.CreateWindowsEnvironment();
                var fileSystem  = new FakeFileSystem(environment);

                // When
                var result = Record.Exception(() =>
                                              MsBuildCodeAnalysisReporter.CreateCodeAnalysisReport(
                                                  fileSystem,
                                                  @"c:\msbuild.log",
                                                  CodeAnalysisReport.Undefined,
                                                  @"c:\report.html"));

                // Then
                result.IsArgumentOutOfRangeException("report");
            }
示例#23
0
        public void Kill_Process_Returns_Minus1_ExitCode()
        {
            var environment = FakeEnvironment.CreateWindowsEnvironment();
            var log         = new FakeLog();
            var runner      = new AdvProcessRunner(environment, log);

            var settings =
                new AdvProcessSettings()
                .UseWorkingDirectory(Environment.CurrentDirectory)
                .WithArguments(args => args.Append("--sleep 5000 --exitcode 3"));

            using (var process = runner.Start(_appExe, settings))
            {
                process.Kill();
                process.GetExitCode().Should().Be(-1);
            }
        }
示例#24
0
        public void CanDeserializePlist()
        {
            // Arrange
            var environment = FakeEnvironment.CreateWindowsEnvironment();
            var fileSystem  = new FakeFileSystem(environment);

            fileSystem.CreateFile("Data/Issue3_Info.plist").SetContent(Resources.Issues3_Info_plist.NormalizeLineEndings());
            var context = Substitute.For <ICakeContext>();

            context.FileSystem.Returns(fileSystem);
            context.Environment.Returns(environment);

            var plist = context.DeserializePlist("./Data/Issue3_Info.plist");

            // Assert
            Assert.NotNull(plist);
        }
示例#25
0
            public void Should_Throw_If_OutputFile_Is_Null()
            {
                // Given
                var environment = FakeEnvironment.CreateWindowsEnvironment();
                var fileSystem  = new FakeFileSystem(environment);

                // When
                var result = Record.Exception(() =>
                                              MsBuildCodeAnalysisReporter.CreateCodeAnalysisReport(
                                                  fileSystem,
                                                  @"c:\msbuild.log",
                                                  CodeAnalysisReport.MsBuildXmlFileLoggerByRule,
                                                  null));

                // Then
                result.IsArgumentNullException("outputFile");
            }
示例#26
0
            public void Process_With_Output_Not_Redirected_Will_Throw()
            {
                var environment = FakeEnvironment.CreateWindowsEnvironment();
                var log         = new FakeLog();
                var runner      = new AdvProcessRunner(environment, log);

                var settings =
                    new AdvProcessSettings()
                    .WithArguments(args => args.Append("--out OutputLine1"))
                    .UseWorkingDirectory(Environment.CurrentDirectory)
                    .SetRedirectStandardOutput(false);

                using (var process = runner.Start(_appExe, settings))
                {
                    process.Invoking(sut => sut.OutputDataReceived += (sender, args) => { })
                    .ShouldThrow <InvalidOperationException>();
                }
            }
示例#27
0
        public void Process_Can_Be_Killed()
        {
            var environment = FakeEnvironment.CreateWindowsEnvironment();
            var log         = new FakeLog();
            var runner      = new AdvProcessRunner(environment, log);

            var settings =
                new AdvProcessSettings()
                .UseWorkingDirectory(Environment.CurrentDirectory)
                .WithArguments(args => args.Append("--sleep 5000"));

            using (var process = runner.Start(_appExe, settings))
            {
                process.Kill();

                process.HasExited.Should().BeTrue();
            }
        }
示例#28
0
        public void Process_Should_Return_Correct_Exit_Code()
        {
            var environment = FakeEnvironment.CreateWindowsEnvironment();
            var log         = new FakeLog();
            var runner      = new AdvProcessRunner(environment, log);

            var settings =
                new AdvProcessSettings().WithArguments(args => args.Append("--exitcode 3"))
                .UseWorkingDirectory(Environment.CurrentDirectory);


            using (var process = runner.Start(_appExe, settings))
            {
                process.WaitForExit();
                var exitCode = process.GetExitCode();
                Console.WriteLine(string.Join("\r\n", log.Messages));
                exitCode.Should().Be(3);
            }
        }
示例#29
0
        public void Process_Should_Return_Correct_StandardError()
        {
            var environment = FakeEnvironment.CreateWindowsEnvironment();
            var log         = new FakeLog();
            var runner      = new AdvProcessRunner(environment, log);

            var settings =
                new AdvProcessSettings().WithArguments(
                    args => args.Append("--err \"error line1\" \"error line2\" \"error line3\""))
                .UseWorkingDirectory(Environment.CurrentDirectory)
                .SetRedirectStandardError(true);

            using (var process = runner.Start(_appExe, settings))
            {
                process.WaitForExit();
                var output = process.GetStandardError().ToArray();

                output.Should().BeEquivalentTo("error line1", "error line2", "error line3");
            }
        }
示例#30
0
        public void Process_Should_Use_Provided_EnvironmentVariables()
        {
            var environment = FakeEnvironment.CreateWindowsEnvironment();
            var log         = new FakeLog();
            var runner      = new AdvProcessRunner(environment, log);

            var settings =
                new AdvProcessSettings()
                .WithArguments(args => args.Append("--environmentVariables EnvVar1 EnvVar2"))
                .UseWorkingDirectory(Environment.CurrentDirectory)
                .WithEnvironmentVariable("EnvVar1", "Value1")
                .WithEnvironmentVariable("EnvVar2", "Value2")
                .SetRedirectStandardOutput(true);

            using (var process = runner.Start(_appExe, settings))
            {
                process.WaitForExit();
                var output = process.GetStandardOutput().ToArray();

                output.Should().BeEquivalentTo("EnvVar1: 'Value1'", "EnvVar2: 'Value2'");
            }
        }