Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Feb 4, 2019. It is now read-only.
/PashPublic archive

Commita79e9fa

Browse files
committed
TEST: Be less strict with error messages.
The error messages for various variable commands were changed afterPowerShell 3.0 so the tests are now less strict to supportPowerShell 3.0 and above.
1 parent4e4e884 commita79e9fa

File tree

5 files changed

+57
-34
lines changed

5 files changed

+57
-34
lines changed

‎Source/ReferenceTests/Commands/ClearVariableTests.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ public void UnknownNameCausesError()
8080
});
8181

8282
ErrorRecorderror=ReferenceHost.GetLastRawErrorRecords().Single();
83-
Assert.AreEqual("Cannot find a variable with name 'unknownvariable'.",error.Exception.Message);
83+
StringAssert.Contains("Cannot find a variable",error.Exception.Message);
84+
StringAssert.Contains("name 'unknownvariable'.",error.Exception.Message);
8485
Assert.AreEqual("VariableNotFound,Microsoft.PowerShell.Commands.ClearVariableCommand",error.FullyQualifiedErrorId);
8586
Assert.AreEqual("unknownvariable",error.TargetObject);
8687
Assert.IsInstanceOf<ItemNotFoundException>(error.Exception);
@@ -102,8 +103,10 @@ public void TwoUnknownNamesCausesTwoErrors()
102103
ErrorRecorderror1=ReferenceHost.GetLastRawErrorRecords().First();
103104
ErrorRecorderror2=ReferenceHost.GetLastRawErrorRecords().Last();
104105
Assert.AreEqual(2,ReferenceHost.GetLastRawErrorRecords().Count());
105-
Assert.AreEqual("Cannot find a variable with name 'unknownvariable1'.",error1.Exception.Message);
106-
Assert.AreEqual("Cannot find a variable with name 'unknownvariable2'.",error2.Exception.Message);
106+
StringAssert.Contains("Cannot find a variable",error1.Exception.Message);
107+
StringAssert.Contains("name 'unknownvariable1'.",error1.Exception.Message);
108+
StringAssert.Contains("Cannot find a variable",error2.Exception.Message);
109+
StringAssert.Contains("name 'unknownvariable2'.",error2.Exception.Message);
107110
}
108111

109112
[Test]
@@ -287,7 +290,8 @@ public void UnknownVariableWithWildcardEscaped()
287290
});
288291

289292
ErrorRecorderror=ReferenceHost.GetLastRawErrorRecords().Single();
290-
Assert.AreEqual("Cannot find a variable with name '`?unknown`?'.",error.Exception.Message);
293+
StringAssert.Contains("Cannot find a variable",error.Exception.Message);
294+
StringAssert.Contains("name '`?unknown`?'.",error.Exception.Message);
291295
Assert.AreEqual("`?unknown`?",error.TargetObject);
292296
Assert.AreEqual("`?unknown`?",error.CategoryInfo.TargetName);
293297
}

‎Source/ReferenceTests/Commands/GetVariableTests.cs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,8 @@ public void UnknownNameCausesError()
329329
});
330330

331331
ErrorRecorderror=ReferenceHost.GetLastRawErrorRecords().Single();
332-
Assert.AreEqual("Cannot find a variable with name 'unknownvariable'.",error.Exception.Message);
332+
StringAssert.Contains("Cannot find a variable",error.Exception.Message);
333+
StringAssert.Contains("name 'unknownvariable'.",error.Exception.Message);
333334
Assert.AreEqual("VariableNotFound,Microsoft.PowerShell.Commands.GetVariableCommand",error.FullyQualifiedErrorId);
334335
Assert.AreEqual("unknownvariable",error.TargetObject);
335336
Assert.IsInstanceOf<ItemNotFoundException>(error.Exception);
@@ -365,7 +366,8 @@ public void UnknownVariableWithWildcardEscaped()
365366
});
366367

367368
ErrorRecorderror=ReferenceHost.GetLastRawErrorRecords().Single();
368-
Assert.AreEqual("Cannot find a variable with name '`?unknown`?'.",error.Exception.Message);
369+
StringAssert.Contains("Cannot find a variable",error.Exception.Message);
370+
StringAssert.Contains("name '`?unknown`?'.",error.Exception.Message);
369371
Assert.AreEqual("`?unknown`?",error.TargetObject);
370372
Assert.AreEqual("`?unknown`?",error.CategoryInfo.TargetName);
371373
}
@@ -396,7 +398,7 @@ public void GetPrivateVariableByName()
396398
});
397399

398400
ErrorRecorderror=ReferenceHost.GetLastRawErrorRecords().Single();
399-
Assert.AreEqual("Cannot access the variable '$foo' because it is a private variable",error.Exception.Message);
401+
StringAssert.Contains("Cannot access the variable '$foo' because it is a private variable",error.Exception.Message);
400402
Assert.AreEqual("VariableIsPrivate,Microsoft.PowerShell.Commands.GetVariableCommand",error.FullyQualifiedErrorId);
401403
Assert.AreEqual("foo",error.TargetObject);
402404
Assert.IsInstanceOf<SessionStateException>(error.Exception);
@@ -422,8 +424,8 @@ public void GetTwoPrivateVariablesByName()
422424
ErrorRecorderror1=ReferenceHost.GetLastRawErrorRecords().First();
423425
ErrorRecorderror2=ReferenceHost.GetLastRawErrorRecords().Last();
424426
Assert.AreEqual(2,ReferenceHost.GetLastRawErrorRecords().Count());
425-
Assert.AreEqual("Cannot access the variable '$foo' because it is a private variable",error1.Exception.Message);
426-
Assert.AreEqual("Cannot access the variable '$bar' because it is a private variable",error2.Exception.Message);
427+
StringAssert.Contains("Cannot access the variable '$foo' because it is a private variable",error1.Exception.Message);
428+
StringAssert.Contains("Cannot access the variable '$bar' because it is a private variable",error2.Exception.Message);
427429
}
428430

429431
[Test]
@@ -449,7 +451,7 @@ public void GetPrivateVariableByNameAndScope()
449451
});
450452

451453
ErrorRecorderror=ReferenceHost.GetLastRawErrorRecords().Single();
452-
Assert.AreEqual("Cannot access the variable '$foo' because it is a private variable",error.Exception.Message);
454+
StringAssert.Contains("Cannot access the variable '$foo' because it is a private variable",error.Exception.Message);
453455
Assert.AreEqual("VariableIsPrivate,Microsoft.PowerShell.Commands.GetVariableCommand",error.FullyQualifiedErrorId);
454456
}
455457

@@ -468,8 +470,8 @@ public void GetTwoPrivateVariablesByNameAndScope()
468470
ErrorRecorderror1=ReferenceHost.GetLastRawErrorRecords().First();
469471
ErrorRecorderror2=ReferenceHost.GetLastRawErrorRecords().Last();
470472
Assert.AreEqual(2,ReferenceHost.GetLastRawErrorRecords().Count());
471-
Assert.AreEqual("Cannot access the variable '$foo' because it is a private variable",error1.Exception.Message);
472-
Assert.AreEqual("Cannot access the variable '$bar' because it is a private variable",error2.Exception.Message);
473+
StringAssert.Contains("Cannot access the variable '$foo' because it is a private variable",error1.Exception.Message);
474+
StringAssert.Contains("Cannot access the variable '$bar' because it is a private variable",error2.Exception.Message);
473475
}
474476
}
475477
}

‎Source/ReferenceTests/Commands/NewVariableTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ public void VisibilityIsPrivate()
229229
ErrorRecorderror=ex.ErrorRecord;
230230
Assert.AreEqual(0,ReferenceHost.GetLastRawErrorRecords().Count());
231231
Assert.AreEqual("foo",error.TargetObject);
232-
Assert.AreEqual("Cannot access the variable '$foo' because it is a private variable",error.Exception.Message);
232+
StringAssert.Contains("Cannot access the variable '$foo' because it is a private variable",error.Exception.Message);
233233
Assert.IsInstanceOf<ParentContainsErrorRecordException>(error.Exception);
234234
Assert.AreEqual("foo",ex.ItemName);
235235
Assert.AreEqual(SessionStateCategory.Variable,ex.SessionStateCategory);
@@ -279,7 +279,7 @@ public void CannotSetPrivateVariableValue()
279279
ErrorRecorderror=ex.ErrorRecord;
280280
Assert.AreEqual(0,ReferenceHost.GetLastRawErrorRecords().Count());
281281
Assert.AreEqual("foo",error.TargetObject);
282-
Assert.AreEqual("Cannot access the variable '$foo' because it is a private variable",error.Exception.Message);
282+
StringAssert.Contains("Cannot access the variable '$foo' because it is a private variable",error.Exception.Message);
283283
Assert.IsInstanceOf<ParentContainsErrorRecordException>(error.Exception);
284284
Assert.AreEqual("foo",ex.ItemName);
285285
Assert.AreEqual(SessionStateCategory.Variable,ex.SessionStateCategory);

‎Source/ReferenceTests/Commands/RemoveVariableTests.cs

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ public void ByName()
2222
});
2323

2424
ErrorRecorderror=ReferenceHost.GetLastRawErrorRecords().Single();
25-
Assert.AreEqual("Cannot find a variable with name 'foo'.",error.Exception.Message);
25+
StringAssert.Contains("Cannot find a variable",error.Exception.Message);
26+
StringAssert.Contains("name 'foo'.",error.Exception.Message);
2627
}
2728

2829
[Test]
@@ -38,7 +39,8 @@ public void NameUsingNamedParametersAndAbbreviatedCommandName()
3839
});
3940

4041
ErrorRecorderror=ReferenceHost.GetLastRawErrorRecords().Single();
41-
Assert.AreEqual("Cannot find a variable with name 'foo'.",error.Exception.Message);
42+
StringAssert.Contains("Cannot find a variable",error.Exception.Message);
43+
StringAssert.Contains("name 'foo'.",error.Exception.Message);
4244
}
4345

4446
[Test]
@@ -56,8 +58,10 @@ public void MultipleNames()
5658

5759
ErrorRecorderror1=ReferenceHost.GetLastRawErrorRecords().First();
5860
ErrorRecorderror2=ReferenceHost.GetLastRawErrorRecords().Last();
59-
Assert.AreEqual("Cannot find a variable with name 'a'.",error1.Exception.Message);
60-
Assert.AreEqual("Cannot find a variable with name 'b'.",error2.Exception.Message);
61+
StringAssert.Contains("Cannot find a variable",error1.Exception.Message);
62+
StringAssert.Contains("name 'a'.",error1.Exception.Message);
63+
StringAssert.Contains("Cannot find a variable",error2.Exception.Message);
64+
StringAssert.Contains("name 'b'.",error2.Exception.Message);
6165
}
6266

6367
[Test]
@@ -69,7 +73,8 @@ public void UnknownNameCausesError()
6973
});
7074

7175
ErrorRecorderror=ReferenceHost.GetLastRawErrorRecords().Single();
72-
Assert.AreEqual("Cannot find a variable with name 'unknownvariable'.",error.Exception.Message);
76+
StringAssert.Contains("Cannot find a variable",error.Exception.Message);
77+
StringAssert.Contains("name 'unknownvariable'.",error.Exception.Message);
7378
Assert.AreEqual("VariableNotFound,Microsoft.PowerShell.Commands.RemoveVariableCommand",error.FullyQualifiedErrorId);
7479
Assert.AreEqual("unknownvariable",error.TargetObject);
7580
Assert.IsInstanceOf<ItemNotFoundException>(error.Exception);
@@ -157,7 +162,8 @@ public void RemoveReadOnlyVariableUsingForce()
157162
});
158163

159164
ErrorRecorderror=ReferenceHost.GetLastRawErrorRecords().Single();
160-
Assert.AreEqual("Cannot find a variable with name 'foo'.",error.Exception.Message);
165+
StringAssert.Contains("Cannot find a variable",error.Exception.Message);
166+
StringAssert.Contains("name 'foo'.",error.Exception.Message);
161167
}
162168

163169
[Test]
@@ -188,7 +194,8 @@ public void RemoveLocalScopeVariable()
188194
});
189195

190196
ErrorRecorderror=ReferenceHost.GetLastRawErrorRecords().Single();
191-
Assert.AreEqual("Cannot find a variable with name 'test'.",error.Exception.Message);
197+
StringAssert.Contains("Cannot find a variable",error.Exception.Message);
198+
StringAssert.Contains("name 'test'.",error.Exception.Message);
192199
}
193200

194201
[Test]
@@ -205,7 +212,8 @@ public void RemoveGlobalScopeVariable()
205212
});
206213

207214
ErrorRecorderror=ReferenceHost.GetLastRawErrorRecords().Single();
208-
Assert.AreEqual("Cannot find a variable with name 'test'.",error.Exception.Message);
215+
StringAssert.Contains("Cannot find a variable",error.Exception.Message);
216+
StringAssert.Contains("name 'test'.",error.Exception.Message);
209217
}
210218

211219
[Test]
@@ -223,8 +231,10 @@ public void WildcardRemovesMultipleVariableValues()
223231

224232
ErrorRecorderror1=ReferenceHost.GetLastRawErrorRecords().First();
225233
ErrorRecorderror2=ReferenceHost.GetLastRawErrorRecords().Last();
226-
Assert.AreEqual("Cannot find a variable with name 'testaa'.",error1.Exception.Message);
227-
Assert.AreEqual("Cannot find a variable with name 'testab'.",error2.Exception.Message);
234+
StringAssert.Contains("Cannot find a variable",error1.Exception.Message);
235+
StringAssert.Contains("name 'testaa'.",error1.Exception.Message);
236+
StringAssert.Contains("Cannot find a variable",error2.Exception.Message);
237+
StringAssert.Contains("name 'testab'.",error2.Exception.Message);
228238
}
229239

230240
[Test]
@@ -241,7 +251,8 @@ public void NameIsWildcardAndLocalScope()
241251
});
242252

243253
ErrorRecorderror=ReferenceHost.GetLastRawErrorRecords().Single();
244-
Assert.AreEqual("Cannot find a variable with name 'test2'.",error.Exception.Message);
254+
StringAssert.Contains("Cannot find a variable",error.Exception.Message);
255+
StringAssert.Contains("name 'test2'.",error.Exception.Message);
245256
}
246257

247258
[Test]
@@ -257,7 +268,8 @@ public void NameIsWildcardAndGlobalScope()
257268
});
258269

259270
ErrorRecorderror=ReferenceHost.GetLastRawErrorRecords().Single();
260-
Assert.AreEqual("Cannot find a variable with name 'test1'.",error.Exception.Message);
271+
StringAssert.Contains("Cannot find a variable",error.Exception.Message);
272+
StringAssert.Contains("name 'test1'.",error.Exception.Message);
261273
}
262274

263275
[Test]
@@ -281,7 +293,8 @@ public void UnknownVariableWithWildcardEscaped()
281293
});
282294

283295
ErrorRecorderror=ReferenceHost.GetLastRawErrorRecords().Single();
284-
Assert.AreEqual("Cannot find a variable with name '`?unknown`?'.",error.Exception.Message);
296+
StringAssert.Contains("Cannot find a variable",error.Exception.Message);
297+
StringAssert.Contains("name '`?unknown`?'.",error.Exception.Message);
285298
Assert.AreEqual("`?unknown`?",error.TargetObject);
286299
Assert.AreEqual("`?unknown`?",error.CategoryInfo.TargetName);
287300
}
@@ -299,7 +312,8 @@ public void WildcardEscapedToRemoveVariableWithWildcardInName()
299312
});
300313

301314
ErrorRecorderror=ReferenceHost.GetLastRawErrorRecords().Single();
302-
Assert.AreEqual("Cannot find a variable with name 'a`?b'.",error.Exception.Message);
315+
StringAssert.Contains("Cannot find a variable",error.Exception.Message);
316+
StringAssert.Contains("name 'a`?b'.",error.Exception.Message);
303317
}
304318

305319
[Test]
@@ -316,7 +330,8 @@ public void IncludeNamesByWildcard()
316330
});
317331

318332
ErrorRecorderror=ReferenceHost.GetLastRawErrorRecords().Single();
319-
Assert.AreEqual("Cannot find a variable with name 'ba'.",error.Exception.Message);
333+
StringAssert.Contains("Cannot find a variable",error.Exception.Message);
334+
StringAssert.Contains("name 'ba'.",error.Exception.Message);
320335
}
321336

322337
[Test]
@@ -333,7 +348,8 @@ public void ExcludeNamesByWildcard()
333348
});
334349

335350
ErrorRecorderror=ReferenceHost.GetLastRawErrorRecords().Single();
336-
Assert.AreEqual("Cannot find a variable with name 'aa'.",error.Exception.Message);
351+
StringAssert.Contains("Cannot find a variable",error.Exception.Message);
352+
StringAssert.Contains("name 'aa'.",error.Exception.Message);
337353
}
338354

339355
[Test]
@@ -350,7 +366,8 @@ public void WildcardAndExcludeOneVariableName()
350366
});
351367

352368
ErrorRecorderror=ReferenceHost.GetLastRawErrorRecords().Single();
353-
Assert.AreEqual("Cannot find a variable with name 'testab'.",error.Exception.Message);
369+
StringAssert.Contains("Cannot find a variable",error.Exception.Message);
370+
StringAssert.Contains("name 'testab'.",error.Exception.Message);
354371
}
355372
}
356373
}

‎Source/ReferenceTests/Commands/SetVariableTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ public void CreateVisibilityPrivateVariableThenTryToChangeDescription()
271271
varsessionStateException=error.ExceptionasSessionStateException;
272272

273273
Assert.AreEqual("foo",error.TargetObject);
274-
Assert.AreEqual("Cannot access the variable '$foo' because it is a private variable",error.Exception.Message);
274+
StringAssert.Contains("Cannot access the variable '$foo' because it is a private variable",error.Exception.Message);
275275
Assert.AreEqual("VariableIsPrivate,Microsoft.PowerShell.Commands.SetVariableCommand",error.FullyQualifiedErrorId);
276276
Assert.AreEqual(ErrorCategory.PermissionDenied,error.CategoryInfo.Category);
277277
Assert.AreEqual("foo",sessionStateException.ItemName);
@@ -293,8 +293,8 @@ public void CreateTwoVisibilityPrivateVariablesThenTryToChangeDescriptionOfBothI
293293
ErrorRecorderror1=ReferenceHost.GetLastRawErrorRecords().First();
294294
ErrorRecorderror2=ReferenceHost.GetLastRawErrorRecords().Last();
295295
Assert.AreEqual(2,ReferenceHost.GetLastRawErrorRecords().Count());
296-
Assert.AreEqual("Cannot access the variable '$foo' because it is a private variable",error1.Exception.Message);
297-
Assert.AreEqual("Cannot access the variable '$bar' because it is a private variable",error2.Exception.Message);
296+
StringAssert.Contains("Cannot access the variable '$foo' because it is a private variable",error1.Exception.Message);
297+
StringAssert.Contains("Cannot access the variable '$bar' because it is a private variable",error2.Exception.Message);
298298
}
299299

300300
[Test]

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp