Skip to content

Commit

Permalink
Use better temp directory cleanup in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
TyOverby committed Jan 4, 2016
1 parent cc10b52 commit 2b3da6d
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 37 deletions.
25 changes: 3 additions & 22 deletions src/Compilers/CSharp/Test/Syntax/Parsing/ParserRegressionTests.cs
Original file line number Diff line number Diff line change
@@ -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
{
Expand Down Expand Up @@ -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());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
<Compile Include="IncrementalParser\SyntaxDifferences.vb" />
<Compile Include="LocationTests.vb" />
<Compile Include="Parser\DeclarationTests.vb" />
<Compile Include="Parser\FuzzTesting.vb" />
<Compile Include="Parser\ParserRegressionTests.vb" />
<Compile Include="Parser\InterpolatedStringParsingTests.vb" />
<Compile Include="Parser\ParseAsyncTests.vb" />
<Compile Include="Parser\ParseAttributes.vb" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

<WorkItem(540022, "DevDiv")>
<Fact>
Expand Down Expand Up @@ -918,20 +919,9 @@ End Enum
End Sub

<WorkItem(2867, "https://github.com/dotnet/roslyn/issues/2867")>
<Fact(Skip:="https://github.com/dotnet/roslyn/issues/7159")>
<ConditionalFact(GetType(IsRelease))>
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

Expand Down
11 changes: 11 additions & 0 deletions src/Test/Utilities/Shared/Assert/ConditionalFactAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.";
}
}
42 changes: 42 additions & 0 deletions src/Test/Utilities/Shared/Syntax/SourceUtilities.cs
Original file line number Diff line number Diff line change
@@ -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];
}
}
}
}
1 change: 1 addition & 0 deletions src/Test/Utilities/Shared/TestUtilities.projitems
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Pdb\MockSymWriter.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Pdb\PdbTestUtilities.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Pdb\PdbValidation.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Syntax\SourceUtilities.cs" />
<Compile Include="$(MSBuildThisFileDirectory)TempFiles\DisposableDirectory.cs" />
<Compile Include="$(MSBuildThisFileDirectory)TempFiles\DisposableFile.cs" />
<Compile Include="$(MSBuildThisFileDirectory)TempFiles\TempDirectory.cs" />
Expand Down

0 comments on commit 2b3da6d

Please sign in to comment.