Пример #1
0
        public async Task ErrorHandling()
        {
            using (var tempFiles = new TempFileStorage(canGetFileNames: true))
            {
                var storage  = (ISandboxedProcessFileStorage)tempFiles;
                var fileName = storage.GetFileName(SandboxedProcessFile.StandardOutput);
                SandboxedProcessOutput output;
                using (var fileStream = FileUtilities.CreateFileStream(fileName, FileMode.CreateNew, FileAccess.Write, FileShare.None, allowExcludeFileShareDelete: true))
                {
                    var content       = new string('S', 100);
                    var outputBuilder =
                        new SandboxedProcessOutputBuilder(Encoding.UTF8, content.Length / 2, tempFiles, SandboxedProcessFile.StandardOutput, null);

                    // NOTE: this only holds on Windows
                    // The specified content plus a NewLine will exceed the max memory length.
                    // Thus, the output builder will try to write the content to a file.
                    // However, the file is not writable (this runs in a using clause that already opened the file).
                    // Thus, this will internally fail, but not yet throw an exception.
                    outputBuilder.AppendLine(content);
                    output = outputBuilder.Freeze();
                    XAssert.IsTrue(output.HasException);
                }

                await Assert.ThrowsAsync <BuildXLException>(() => output.ReadValueAsync());

                await Assert.ThrowsAsync <BuildXLException>(() => output.SaveAsync());

                Assert.Throws <BuildXLException>(() => output.CreateReader());
            }
        }
Пример #2
0
        public async Task ObservedOutputWithNullStorage()
        {
            var    content        = new string('S', 100);
            string observedOutput = string.Empty;
            var    outputBuilder  =
                new SandboxedProcessOutputBuilder(
                    Encoding.UTF8,
                    0,
                    null,
                    SandboxedProcessFile.StandardOutput,
                    writtenOutput => observedOutput += writtenOutput);

            outputBuilder.AppendLine(content);
            SandboxedProcessOutput output = outputBuilder.Freeze();

            XAssert.IsFalse(output.IsSaved);
            XAssert.AreEqual(string.Empty, await output.ReadValueAsync());
            XAssert.AreEqual(content, observedOutput);
        }
        public void OutputPassThroughToParentConsole()
        {
            // Verify we can construct a builder with pass-through arguments.
            var outputBuilder =
                new SandboxedProcessOutputBuilder(
                    Encoding.UTF8,
                    maxMemoryLength: 0,
                    fileStorage: null,
                    file: SandboxedProcessFile.StandardOutput,
                    observer: null);

            XAssert.IsFalse(outputBuilder.HookOutputStream);
            SandboxedProcessOutput output = outputBuilder.Freeze();

            XAssert.IsNotNull(output);
            XAssert.IsTrue(output.HasLength);
            XAssert.IsFalse(output.HasException);
            XAssert.AreEqual(0, output.Length);
        }
Пример #4
0
 public async Task OutputInMemory()
 {
     using (var tempFiles = new TempFileStorage(canGetFileNames: true))
     {
         var storage       = (ISandboxedProcessFileStorage)tempFiles;
         var fileName      = storage.GetFileName(SandboxedProcessFile.StandardOutput);
         var content       = new string('S', 100);
         var outputBuilder =
             new SandboxedProcessOutputBuilder(
                 Encoding.UTF8,
                 content.Length + Environment.NewLine.Length,
                 tempFiles,
                 SandboxedProcessFile.StandardOutput,
                 null);
         outputBuilder.AppendLine(content);
         var output = outputBuilder.Freeze();
         XAssert.IsFalse(output.IsSaved);
         XAssert.IsFalse(File.Exists(fileName));
         XAssert.AreEqual(content + Environment.NewLine, await output.ReadValueAsync());
     }
 }