-
Notifications
You must be signed in to change notification settings - Fork 4.6k
/
ErrObjectTests.cs
146 lines (121 loc) · 5.94 KB
/
ErrObjectTests.cs
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using Microsoft.VisualBasic.CompilerServices;
using System;
using Xunit;
namespace Microsoft.VisualBasic.Tests
{
public class ErrObjectTests
{
[Fact]
[ActiveIssue("https://github.com/mono/mono/issues/14854", TestRuntimes.Mono)]
public void Clear()
{
ProjectData.ClearProjectError();
ProjectData.SetProjectError(new ArgumentException(), 3);
var errObj = Information.Err();
errObj.Number = 5;
errObj.Description = "Description";
errObj.HelpContext = 6;
errObj.HelpFile = "File";
errObj.Source = "Source";
errObj.Clear();
Assert.Equal(0, errObj.Erl);
Assert.Equal(0, errObj.HelpContext);
Assert.Equal("", errObj.HelpFile);
Assert.Equal("", errObj.Source);
Assert.Equal(0, errObj.LastDllError);
Assert.Equal(0, errObj.Number);
Assert.Equal("", errObj.Description);
Assert.Null(errObj.GetException());
Assert.Equal(0, Information.Erl());
}
[Fact]
public void Raise()
{
ProjectData.ClearProjectError();
ProjectData.SetProjectError(new Exception());
_ = Assert.Throws<ArgumentException>(() => Information.Err().Raise(0)).ToString();
ProjectData.SetProjectError(new Exception());
_ = Assert.Throws<OutOfMemoryException>(() => Information.Err().Raise(7)).ToString();
ProjectData.SetProjectError(new ArgumentException());
_ = Assert.Throws<OutOfMemoryException>(() => Information.Err().Raise(7)).ToString();
ProjectData.SetProjectError(new ArgumentException());
_ = Assert.Throws<Exception>(() => Information.Err().Raise(32768)).ToString();
ProjectData.SetProjectError(new InvalidOperationException());
_ = Assert.Throws<Exception>(() => Information.Err().Raise(1, Description: "MyDescription")).ToString();
}
[Fact]
public void Source()
{
ProjectData.ClearProjectError();
ProjectData.SetProjectError(new Exception() { Source = null });
Assert.Null(Information.Err().Source);
ProjectData.SetProjectError(new Exception() { Source = "MySource1" });
Assert.Equal("MySource1", Information.Err().Source);
ProjectData.SetProjectError(new Exception() { Source = null });
Assert.Null(Information.Err().Source);
ProjectData.SetProjectError(new Exception() { Source = null });
_ = Assert.Throws<OutOfMemoryException>(() => Information.Err().Raise(7, Source: "MySource2"));
Assert.Equal("MySource2", Information.Err().Source);
}
[Fact]
public void FilterDefaultMessage()
{
ProjectData.ClearProjectError();
string message = "Description";
ProjectData.SetProjectError(new System.IO.FileNotFoundException(message));
Assert.Equal(message, Information.Err().Description);
message = "";
ProjectData.SetProjectError(new System.IO.FileNotFoundException(message));
Assert.NotEqual(message, Information.Err().Description);
message = "Exception from HRESULT: 0x80";
ProjectData.SetProjectError(new System.IO.FileNotFoundException(message));
Assert.NotEqual(message, Information.Err().Description);
}
[Fact]
public void MakeHelpLink()
{
ProjectData.ClearProjectError();
ProjectData.SetProjectError(new ArgumentException());
Assert.Equal("#0", Assert.Throws<OutOfMemoryException>(() => Information.Err().Raise(7)).HelpLink);
ProjectData.SetProjectError(new ArgumentException());
Assert.Equal("#3", Assert.Throws<OutOfMemoryException>(() => Information.Err().Raise(7, HelpContext: 3)).HelpLink);
ProjectData.SetProjectError(new ArgumentException());
Assert.Equal("MyFile1#3", Assert.Throws<OutOfMemoryException>(() => Information.Err().Raise(7, HelpFile: "MyFile1")).HelpLink);
ProjectData.ClearProjectError();
ProjectData.SetProjectError(new ArgumentException());
Assert.Equal("MyFile2#0", Assert.Throws<OutOfMemoryException>(() => Information.Err().Raise(7, HelpFile: "MyFile2")).HelpLink);
ProjectData.SetProjectError(new ArgumentException());
Assert.Equal("MyFile3#3", Assert.Throws<OutOfMemoryException>(() => Information.Err().Raise(7, HelpContext: 3, HelpFile: "MyFile3")).HelpLink);
}
[Theory]
[InlineData(null, 0, "")]
[InlineData("", 0, "")]
[InlineData("#0", 0, "")]
[InlineData("#1", 1, "")]
[InlineData("#-3", -3, "")]
[InlineData("MyFile1", 0, "MyFile1")]
[InlineData("MyFile4#4", 4, "MyFile4")]
public void ParseHelpLink(string helpLink, int expectedHelpContext, string expectedHelpFile)
{
ProjectData.ClearProjectError();
ProjectData.SetProjectError(new ArgumentException() { HelpLink = helpLink });
Assert.Equal(expectedHelpContext, Information.Err().HelpContext);
Assert.Equal(expectedHelpFile, Information.Err().HelpFile);
}
[Theory]
[InlineData("#")]
[InlineData("##")]
[InlineData("##2")]
[InlineData("MyFile2#")]
[InlineData("MyFile3##")]
public void ParseHelpLink_InvalidCastException(string helpLink)
{
ProjectData.ClearProjectError();
ProjectData.SetProjectError(new ArgumentException() { HelpLink = helpLink });
Assert.Throws<InvalidCastException>(() => Information.Err().HelpContext);
Assert.Throws<InvalidCastException>(() => Information.Err().HelpFile);
}
}
}