Repository navigation
Expand file tree
/
Copy pathScriptingTestHelpers.cs
More file actions
56 lines (49 loc) · 2.12 KB
/
Copy pathScriptingTestHelpers.cs
File metadata and controls
56 lines (49 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// 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.Linq;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Test.Utilities;
using Xunit;
using System;
using System.Threading.Tasks;
using Roslyn.Test.Utilities;
namespace Microsoft.CodeAnalysis.Scripting.Test
{
public class ScriptingTestHelpers
{
internal static void AssertCompilationError(Script script, params DiagnosticDescription[] expectedDiagnostics)
{
AssertCompilationError(() => script.RunAsync().Wait(), expectedDiagnostics);
}
internal static void AssertCompilationError(Task<ScriptState> state, string code, params DiagnosticDescription[] expectedDiagnostics)
{
AssertCompilationError(() => state.Result.ContinueWithAsync(code).Wait(), expectedDiagnostics);
}
internal static void AssertCompilationError<T>(Task<ScriptState<T>> state, string code, params DiagnosticDescription[] expectedDiagnostics)
{
AssertCompilationError(() => state.Result.ContinueWithAsync(code).Wait(), expectedDiagnostics);
}
internal static void AssertCompilationError(ScriptState state, string code, params DiagnosticDescription[] expectedDiagnostics)
{
AssertCompilationError(() => state.ContinueWithAsync(code).Wait(), expectedDiagnostics);
}
internal static void AssertCompilationError(Action action, params DiagnosticDescription[] expectedDiagnostics)
{
bool noException = false;
try
{
action();
noException = true;
}
catch (CompilationErrorException e)
{
e.Diagnostics.Verify(expectedDiagnostics);
e.Diagnostics.Any(d => d.Severity == DiagnosticSeverity.Error && e.Message == d.ToString());
}
catch (Exception e)
{
Assert.False(true, "Unexpected exception: " + e);
}
Assert.False(noException);
}
}
}