Skip to content

Commit d10f367

Browse files
Check on error called.
Also changed IList<Attribute> to IEnumerable<Attribute>.
1 parent 55a3f35 commit d10f367

2 files changed

Lines changed: 23 additions & 5 deletions

File tree

src/CommandLine/Infrastructure/ReflectionHelper.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ static class ReflectionHelper
2828
/// Attributes that replace the existing assembly attributes or null,
2929
/// to clear any testing attributes.
3030
/// </param>
31-
public static void SetAttributeOverride(IList<Attribute> overrides)
31+
public static void SetAttributeOverride(IEnumerable<Attribute> overrides)
3232
{
3333
if (overrides != null)
3434
{
@@ -46,7 +46,7 @@ public static Maybe<TAttribute> GetAttribute<TAttribute>()
4646
// Test support
4747
if (_overrides != null)
4848
{
49-
return
49+
return
5050
_overrides.ContainsKey(typeof(TAttribute)) ?
5151
Maybe.Just((TAttribute)_overrides[typeof(TAttribute)]) :
5252
Maybe.Nothing< TAttribute>();

tests/CommandLine.Tests/Unit/Text/HelpTextTests.cs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -579,8 +579,14 @@ public void AutoBuild_when_no_assembly_attributes()
579579

580580
ParserResult<Simple_Options> fakeResult = new NotParsed<Simple_Options>(
581581
TypeInfo.Create(typeof (Simple_Options)), new Error[0]);
582-
HelpText actualResult = HelpText.AutoBuild(fakeResult, ht => ht, ex => ex);
582+
bool onErrorCalled = false;
583+
HelpText actualResult = HelpText.AutoBuild(fakeResult, ht =>
584+
{
585+
onErrorCalled = true;
586+
return ht;
587+
}, ex => ex);
583588

589+
onErrorCalled.Should().BeTrue();
584590
actualResult.Copyright.Should().Be(expectedCopyright);
585591
}
586592
finally
@@ -605,8 +611,14 @@ public void AutoBuild_with_assembly_title_and_version_attributes_only()
605611

606612
ParserResult<Simple_Options> fakeResult = new NotParsed<Simple_Options>(
607613
TypeInfo.Create(typeof (Simple_Options)), new Error[0]);
608-
HelpText actualResult = HelpText.AutoBuild(fakeResult, ht => ht, ex => ex);
614+
bool onErrorCalled = false;
615+
HelpText actualResult = HelpText.AutoBuild(fakeResult, ht =>
616+
{
617+
onErrorCalled = true;
618+
return ht;
619+
}, ex => ex);
609620

621+
onErrorCalled.Should().BeTrue();
610622
actualResult.Heading.Should().Be(string.Format("{0} {1}", expectedTitle, expectedVersion));
611623
}
612624
finally
@@ -630,8 +642,14 @@ public void AutoBuild_with_assembly_company_attribute_only()
630642

631643
ParserResult<Simple_Options> fakeResult = new NotParsed<Simple_Options>(
632644
TypeInfo.Create(typeof (Simple_Options)), new Error[0]);
633-
HelpText actualResult = HelpText.AutoBuild(fakeResult, ht => ht, ex => ex);
645+
bool onErrorCalled = false;
646+
HelpText actualResult = HelpText.AutoBuild(fakeResult, ht =>
647+
{
648+
onErrorCalled = true;
649+
return ht;
650+
}, ex => ex);
634651

652+
onErrorCalled.Should().BeFalse(); // Other attributes have fallback logic
635653
actualResult.Copyright.Should().Be(string.Format("Copyright (C) {0} {1}", DateTime.Now.Year, expectedCompany));
636654
}
637655
finally

0 commit comments

Comments
 (0)