From 2b3da6d651807de3220b3866a64d556c65513b7d Mon Sep 17 00:00:00 2001 From: Ty Overby Date: Mon, 14 Dec 2015 11:30:09 -0800 Subject: [PATCH] Use better temp directory cleanup in tests Closes #6233 --- .../Syntax/Parsing/ParserRegressionTests.cs | 25 ++--------- .../Syntax/BasicCompilerSyntaxTest.vbproj | 2 +- ...uzzTesting.vb => ParserRegressionTests.vb} | 18 ++------ .../Shared/Assert/ConditionalFactAttribute.cs | 11 +++++ .../Shared/Syntax/SourceUtilities.cs | 42 +++++++++++++++++++ .../Utilities/Shared/TestUtilities.projitems | 1 + 6 files changed, 62 insertions(+), 37 deletions(-) rename src/Compilers/VisualBasic/Test/Syntax/Parser/{FuzzTesting.vb => ParserRegressionTests.vb} (97%) create mode 100644 src/Test/Utilities/Shared/Syntax/SourceUtilities.cs diff --git a/src/Compilers/CSharp/Test/Syntax/Parsing/ParserRegressionTests.cs b/src/Compilers/CSharp/Test/Syntax/Parsing/ParserRegressionTests.cs index 641f6f26625c9..5c31ed460e58f 100644 --- a/src/Compilers/CSharp/Test/Syntax/Parsing/ParserRegressionTests.cs +++ b/src/Compilers/CSharp/Test/Syntax/Parsing/ParserRegressionTests.cs @@ -1,11 +1,9 @@ // Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System.IO; using Microsoft.CodeAnalysis.CSharp.Test.Utilities; -using Microsoft.CodeAnalysis.Text; using Roslyn.Test.Utilities; +using Roslyn.Test.Utilities.Syntax; using Xunit; -using System.Text; namespace Microsoft.CodeAnalysis.CSharp.UnitTests.Parsing { @@ -80,27 +78,10 @@ public void c024928() } [WorkItem(2771, "https://github.com/dotnet/roslyn/issues/2771")] - [Fact(Skip = "This test continues to be flaky, even in this form, due to variations in the amount of memory available when it is run")] + [ConditionalFact(typeof(IsRelease))] public void TestBinary() { - // Apparently this fixed seed exposed a bug at some point - var random = new System.Random(12345); - // 40 million "character"s - const int n = 40 * 1000 * 1000; - var str = new string(' ', n); - - unsafe - { - fixed(char* chars = str) - { - for(int i = 0; i < n; i++) - { - chars[i] = (char)random.Next(char.MaxValue); - } - } - } - - var tree = CSharpSyntaxTree.ParseText(str); + CSharpSyntaxTree.ParseText(new RandomizedSourceText()); } } } diff --git a/src/Compilers/VisualBasic/Test/Syntax/BasicCompilerSyntaxTest.vbproj b/src/Compilers/VisualBasic/Test/Syntax/BasicCompilerSyntaxTest.vbproj index 80394bfdb0b72..e7939823d64f3 100644 --- a/src/Compilers/VisualBasic/Test/Syntax/BasicCompilerSyntaxTest.vbproj +++ b/src/Compilers/VisualBasic/Test/Syntax/BasicCompilerSyntaxTest.vbproj @@ -96,7 +96,7 @@ - + diff --git a/src/Compilers/VisualBasic/Test/Syntax/Parser/FuzzTesting.vb b/src/Compilers/VisualBasic/Test/Syntax/Parser/ParserRegressionTests.vb similarity index 97% rename from src/Compilers/VisualBasic/Test/Syntax/Parser/FuzzTesting.vb rename to src/Compilers/VisualBasic/Test/Syntax/Parser/ParserRegressionTests.vb index 7f2768d46e907..a181d14f2a2bb 100644 --- a/src/Compilers/VisualBasic/Test/Syntax/Parser/FuzzTesting.vb +++ b/src/Compilers/VisualBasic/Test/Syntax/Parser/ParserRegressionTests.vb @@ -4,8 +4,9 @@ Imports System.IO Imports Microsoft.CodeAnalysis Imports Microsoft.CodeAnalysis.Text Imports Roslyn.Test.Utilities +Imports Roslyn.Test.Utilities.Syntax -Public Class FuzzTesting : Inherits BasicTestBase +Public Class ParserRegressionTests : Inherits BasicTestBase @@ -918,20 +919,9 @@ End Enum End Sub - + Public Sub TestBinary() - ' use a fixed seed so the test Is reproducible - Dim random = New System.Random(12345) - Const n As Integer = 40 * 1000 * 1000 ' 40 million "character"s - Dim builder = New System.Text.StringBuilder(n + 10) - For i As Integer = 0 To n - 1 - builder.Append(ChrW(random.Next(&HFFFF))) - Next - - Dim source = builder.ToString() - Dim tree = VisualBasicSyntaxTree.ParseText(source) - - Assert.Equal(source, tree.ToString()) + Dim tree = VisualBasicSyntaxTree.ParseText(New RandomizedSourceText()) Assert.Equal(Syntax.InternalSyntax.Scanner.BadTokenCountLimit, tree.GetDiagnostics().Where(Function(d) d.Code = ERRID.ERR_IllegalChar).Count()) End Sub diff --git a/src/Test/Utilities/Shared/Assert/ConditionalFactAttribute.cs b/src/Test/Utilities/Shared/Assert/ConditionalFactAttribute.cs index 66799334272f1..4a1f01f2a9257 100644 --- a/src/Test/Utilities/Shared/Assert/ConditionalFactAttribute.cs +++ b/src/Test/Utilities/Shared/Assert/ConditionalFactAttribute.cs @@ -49,4 +49,15 @@ public class IsEnglishLocal : ExecutionCondition public override string SkipReason => "Current culture is not en-US"; } + + public class IsRelease : ExecutionCondition + { +#if DEBUG + public override bool ShouldSkip => true; +#else + public override bool ShouldSkip => false; +#endif + + public override string SkipReason => "Not in release mode."; + } } diff --git a/src/Test/Utilities/Shared/Syntax/SourceUtilities.cs b/src/Test/Utilities/Shared/Syntax/SourceUtilities.cs new file mode 100644 index 0000000000000..192409d3ee1e3 --- /dev/null +++ b/src/Test/Utilities/Shared/Syntax/SourceUtilities.cs @@ -0,0 +1,42 @@ +// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using Microsoft.CodeAnalysis.Text; +using System; +using System.Collections.Generic; +using System.Text; + +namespace Roslyn.Test.Utilities.Syntax +{ + internal sealed class RandomizedSourceText: SourceText + { + private char[] buffer = new char[2048]; + + public RandomizedSourceText() + { + var random = new Random(12345); + for (var i = 0; i < buffer.Length; i++) + { + buffer[i] = (char)random.Next(); + } + } + + public override char this[int position] => buffer[position % buffer.Length]; + + public override Encoding Encoding => Encoding.UTF8; + + public override int Length + { + get + { + return 40 * 1000 * 1000; + } + } + + public override void CopyTo(int sourceIndex, char[] destination, int destinationIndex, int count) + { + for (var i = 0; i < count; i++) + { + destination[destinationIndex + i] = this[sourceIndex + i]; + } + } + } +} diff --git a/src/Test/Utilities/Shared/TestUtilities.projitems b/src/Test/Utilities/Shared/TestUtilities.projitems index 1ec7cb743b06a..eb740d2848de4 100644 --- a/src/Test/Utilities/Shared/TestUtilities.projitems +++ b/src/Test/Utilities/Shared/TestUtilities.projitems @@ -58,6 +58,7 @@ +