From 17176edb80dee3cf6afd588f0f620e7c6af31542 Mon Sep 17 00:00:00 2001 From: Bryan Date: Wed, 6 Jan 2016 15:30:56 -0800 Subject: [PATCH] Remove StreamForwarder Tests from E2E --- scripts/test/runtests.ps1 | 1 + scripts/test/runtests.sh | 1 + test/E2E/EndToEndTest.cs | 100 +-------------- .../StreamForwarderTests.cs | 118 ++++++++++++++++++ .../StreamForwarderTests.xproj | 19 +++ test/StreamForwarderTests/project.json | 24 ++++ 6 files changed, 164 insertions(+), 99 deletions(-) create mode 100644 test/StreamForwarderTests/StreamForwarderTests.cs create mode 100644 test/StreamForwarderTests/StreamForwarderTests.xproj create mode 100644 test/StreamForwarderTests/project.json diff --git a/scripts/test/runtests.ps1 b/scripts/test/runtests.ps1 index 5cbb3e1c6..74a6e4b79 100644 --- a/scripts/test/runtests.ps1 +++ b/scripts/test/runtests.ps1 @@ -9,6 +9,7 @@ $TestBinRoot = "$RepoRoot\artifacts\tests" $TestProjects = @( "E2E", + "StreamForwarderTests" "Microsoft.DotNet.Tools.Publish.Tests" ) diff --git a/scripts/test/runtests.sh b/scripts/test/runtests.sh index 7a8dab4d0..ed6a5970c 100755 --- a/scripts/test/runtests.sh +++ b/scripts/test/runtests.sh @@ -20,6 +20,7 @@ TestBinRoot="$REPOROOT/artifacts/tests" TestProjects=( \ E2E \ + StreamForwarderTests \ Microsoft.DotNet.Tools.Publish.Tests \ ) diff --git a/test/E2E/EndToEndTest.cs b/test/E2E/EndToEndTest.cs index 15cfe1d33..31abe2863 100644 --- a/test/E2E/EndToEndTest.cs +++ b/test/E2E/EndToEndTest.cs @@ -160,102 +160,4 @@ namespace Microsoft.DotNet.Tests.EndToEnd return false; } } -} - -public class StreamForwarderTests -{ - [Fact] - public void Unbuffered() - { - Forward(4, true, ""); - Forward(4, true, "123", "123"); - Forward(4, true, "1234", "1234"); - Forward(3, true, "123456789", "123", "456", "789"); - Forward(4, true, "\r\n", "\n"); - Forward(4, true, "\r\n34", "\n", "34"); - Forward(4, true, "1\r\n4", "1\n", "4"); - Forward(4, true, "12\r\n", "12\n"); - Forward(4, true, "123\r\n", "123\n"); - Forward(4, true, "1234\r\n", "1234", "\n"); - Forward(3, true, "\r\n3456\r\n9", "\n", "3456", "\n", "9"); - Forward(4, true, "\n", "\n"); - Forward(4, true, "\n234", "\n", "234"); - Forward(4, true, "1\n34", "1\n", "34"); - Forward(4, true, "12\n4", "12\n", "4"); - Forward(4, true, "123\n", "123\n"); - Forward(4, true, "1234\n", "1234", "\n"); - Forward(3, true, "\n23456\n89", "\n", "23456", "\n", "89"); - } - - [Fact] - public void LineBuffered() - { - Forward(4, false, ""); - Forward(4, false, "123", "123\n"); - Forward(4, false, "1234", "1234\n"); - Forward(3, false, "123456789", "123456789\n"); - Forward(4, false, "\r\n", "\n"); - Forward(4, false, "\r\n34", "\n", "34\n"); - Forward(4, false, "1\r\n4", "1\n", "4\n"); - Forward(4, false, "12\r\n", "12\n"); - Forward(4, false, "123\r\n", "123\n"); - Forward(4, false, "1234\r\n", "1234\n"); - Forward(3, false, "\r\n3456\r\n9", "\n", "3456\n", "9\n"); - Forward(4, false, "\n", "\n"); - Forward(4, false, "\n234", "\n", "234\n"); - Forward(4, false, "1\n34", "1\n", "34\n"); - Forward(4, false, "12\n4", "12\n", "4\n"); - Forward(4, false, "123\n", "123\n"); - Forward(4, false, "1234\n", "1234\n"); - Forward(3, false, "\n23456\n89", "\n", "23456\n", "89\n"); - } - - private static void Forward(int bufferSize, bool unbuffered, string str, params string[] expectedWrites) - { - var expectedCaptured = str.Replace("\r", "").Replace("\n", Environment.NewLine); - - // No forwarding. - Forward(bufferSize, ForwardOptions.None, str, null, new string[0]); - - // Capture only. - Forward(bufferSize, ForwardOptions.Capture, str, expectedCaptured, new string[0]); - - var writeOptions = unbuffered ? - ForwardOptions.Write | ForwardOptions.WriteLine : - ForwardOptions.WriteLine; - - // Forward. - Forward(bufferSize, writeOptions, str, null, expectedWrites); - - // Forward and capture. - Forward(bufferSize, writeOptions | ForwardOptions.Capture, str, expectedCaptured, expectedWrites); - } - - private enum ForwardOptions - { - None = 0x0, - Capture = 0x1, - Write = 0x02, - WriteLine = 0x04, - } - - private static void Forward(int bufferSize, ForwardOptions options, string str, string expectedCaptured, string[] expectedWrites) - { - var forwarder = new StreamForwarder(bufferSize); - var writes = new List(); - if ((options & ForwardOptions.WriteLine) != 0) - { - forwarder.ForwardTo( - write: (options & ForwardOptions.Write) == 0 ? (Action)null : writes.Add, - writeLine: s => writes.Add(s + "\n")); - } - if ((options & ForwardOptions.Capture) != 0) - { - forwarder.Capture(); - } - forwarder.Read(new StringReader(str)); - Assert.Equal(expectedWrites, writes); - var captured = forwarder.GetCapturedOutput(); - Assert.Equal(expectedCaptured, captured); - } -} +} \ No newline at end of file diff --git a/test/StreamForwarderTests/StreamForwarderTests.cs b/test/StreamForwarderTests/StreamForwarderTests.cs new file mode 100644 index 000000000..226ab4a51 --- /dev/null +++ b/test/StreamForwarderTests/StreamForwarderTests.cs @@ -0,0 +1,118 @@ +// Copyright (c) .NET Foundation and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System; +using System.Collections.Generic; +using System.IO; +using System.Runtime.InteropServices; +using System.Text; +using Xunit; +using Microsoft.DotNet.Cli.Utils; +using Microsoft.DotNet.ProjectModel; +using Microsoft.DotNet.Tools.Test.Utilities; + +namespace StreamForwarderTests +{ + public class StreamForwarderTests + { + public static void Main() + { + Console.WriteLine("Dummy Entrypoint"); + } + + [Fact] + public void Unbuffered() + { + Forward(4, true, ""); + Forward(4, true, "123", "123"); + Forward(4, true, "1234", "1234"); + Forward(3, true, "123456789", "123", "456", "789"); + Forward(4, true, "\r\n", "\n"); + Forward(4, true, "\r\n34", "\n", "34"); + Forward(4, true, "1\r\n4", "1\n", "4"); + Forward(4, true, "12\r\n", "12\n"); + Forward(4, true, "123\r\n", "123\n"); + Forward(4, true, "1234\r\n", "1234", "\n"); + Forward(3, true, "\r\n3456\r\n9", "\n", "3456", "\n", "9"); + Forward(4, true, "\n", "\n"); + Forward(4, true, "\n234", "\n", "234"); + Forward(4, true, "1\n34", "1\n", "34"); + Forward(4, true, "12\n4", "12\n", "4"); + Forward(4, true, "123\n", "123\n"); + Forward(4, true, "1234\n", "1234", "\n"); + Forward(3, true, "\n23456\n89", "\n", "23456", "\n", "89"); + } + + [Fact] + public void LineBuffered() + { + Forward(4, false, ""); + Forward(4, false, "123", "123\n"); + Forward(4, false, "1234", "1234\n"); + Forward(3, false, "123456789", "123456789\n"); + Forward(4, false, "\r\n", "\n"); + Forward(4, false, "\r\n34", "\n", "34\n"); + Forward(4, false, "1\r\n4", "1\n", "4\n"); + Forward(4, false, "12\r\n", "12\n"); + Forward(4, false, "123\r\n", "123\n"); + Forward(4, false, "1234\r\n", "1234\n"); + Forward(3, false, "\r\n3456\r\n9", "\n", "3456\n", "9\n"); + Forward(4, false, "\n", "\n"); + Forward(4, false, "\n234", "\n", "234\n"); + Forward(4, false, "1\n34", "1\n", "34\n"); + Forward(4, false, "12\n4", "12\n", "4\n"); + Forward(4, false, "123\n", "123\n"); + Forward(4, false, "1234\n", "1234\n"); + Forward(3, false, "\n23456\n89", "\n", "23456\n", "89\n"); + } + + private static void Forward(int bufferSize, bool unbuffered, string str, params string[] expectedWrites) + { + var expectedCaptured = str.Replace("\r", "").Replace("\n", Environment.NewLine); + + // No forwarding. + Forward(bufferSize, ForwardOptions.None, str, null, new string[0]); + + // Capture only. + Forward(bufferSize, ForwardOptions.Capture, str, expectedCaptured, new string[0]); + + var writeOptions = unbuffered ? + ForwardOptions.Write | ForwardOptions.WriteLine : + ForwardOptions.WriteLine; + + // Forward. + Forward(bufferSize, writeOptions, str, null, expectedWrites); + + // Forward and capture. + Forward(bufferSize, writeOptions | ForwardOptions.Capture, str, expectedCaptured, expectedWrites); + } + + private enum ForwardOptions + { + None = 0x0, + Capture = 0x1, + Write = 0x02, + WriteLine = 0x04, + } + + private static void Forward(int bufferSize, ForwardOptions options, string str, string expectedCaptured, string[] expectedWrites) + { + var forwarder = new StreamForwarder(bufferSize); + var writes = new List(); + if ((options & ForwardOptions.WriteLine) != 0) + { + forwarder.ForwardTo( + write: (options & ForwardOptions.Write) == 0 ? (Action)null : writes.Add, + writeLine: s => writes.Add(s + "\n")); + } + if ((options & ForwardOptions.Capture) != 0) + { + forwarder.Capture(); + } + forwarder.Read(new StringReader(str)); + Assert.Equal(expectedWrites, writes); + var captured = forwarder.GetCapturedOutput(); + Assert.Equal(expectedCaptured, captured); + } + } +} diff --git a/test/StreamForwarderTests/StreamForwarderTests.xproj b/test/StreamForwarderTests/StreamForwarderTests.xproj new file mode 100644 index 000000000..8d2e1ee44 --- /dev/null +++ b/test/StreamForwarderTests/StreamForwarderTests.xproj @@ -0,0 +1,19 @@ + + + + 14.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + + + + 386d412c-003c-47b1-8258-0e35865cb7c4 + StreamForwarderTests + ..\..\artifacts\obj\$(MSBuildProjectName) + ..\..\artifacts\bin\$(MSBuildProjectName)\ + + + 2.0 + + + + \ No newline at end of file diff --git a/test/StreamForwarderTests/project.json b/test/StreamForwarderTests/project.json new file mode 100644 index 000000000..2e21d6123 --- /dev/null +++ b/test/StreamForwarderTests/project.json @@ -0,0 +1,24 @@ +{ + "version": "1.0.0-*", + "compilationOptions": { + "emitEntryPoint": true + }, + + "dependencies": { + "NETStandard.Library" : "1.0.0-rc2-23704", + + "xunit": "2.1.0", + "xunit.console.netcore": "1.0.2-prerelease-00101", + "xunit.netcore.extensions": "1.0.0-prerelease-*", + "xunit.runner.utility": "2.1.0", + + "Microsoft.DotNet.ProjectModel": { "target": "project" }, + "Microsoft.DotNet.Cli.Utils": { "target": "project" }, + + "Microsoft.DotNet.Tools.Tests.Utilities": { "target": "project" } + }, + + "frameworks": { + "dnxcore50": { } + } +}