Skip to content

Commit

Permalink
feat(execution): consider string members to violate requirements when…
Browse files Browse the repository at this point in the history
… empty or whitespace
  • Loading branch information
matkoch committed Dec 15, 2023
1 parent c8c3f82 commit 926ffbc
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions source/Nuke.Build/Execution/DelegateRequirementService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,21 @@ public static void ValidateRequirements(INukeBuild build, IReadOnlyCollection<Ex
if (requirement is Expression<Func<bool>> boolExpression)
// TODO: same as HasSkippingCondition.GetSkipReason
Assert.True(boolExpression.Compile().Invoke(), $"Target '{target.Name}' requires '{requirement.Body}'");
else if (IsMemberNull(requirement.GetMemberInfo(), build, target))
Assert.Fail($"Target '{target.Name}' requires member '{GetMemberName(requirement.GetMemberInfo())}' to be not null");
else if (IsMemberNullOrEmpty(requirement.GetMemberInfo(), build, target))
Assert.Fail($"Target '{target.Name}' requires member '{GetMemberName(requirement.GetMemberInfo())}' to be not null or empty");
}

var requiredMembers = ValueInjectionUtility.GetInjectionMembers(build.GetType())
.Select(x => x.Member)
.Where(x => x.HasCustomAttribute<RequiredAttribute>());
foreach (var member in requiredMembers)
{
if (IsMemberNull(member, build))
Assert.Fail($"Member '{GetMemberName(member)}' is required to be not null");
if (IsMemberNullOrEmpty(member, build))
Assert.Fail($"Member '{GetMemberName(member)}' is required to be not null or empty");
}
}

private static bool IsMemberNull(MemberInfo member, INukeBuild build, ExecutableTarget target = null)
private static bool IsMemberNullOrEmpty(MemberInfo member, INukeBuild build, ExecutableTarget target = null)
{
member = member.DeclaringType != build.GetType()
? build.GetType().GetMember(member.Name).SingleOrDefault() ?? member
Expand All @@ -52,7 +52,9 @@ private static bool IsMemberNull(MemberInfo member, INukeBuild build, Executable
if (build.Host is Terminal)
TryInjectValueInteractive(member, build);

return member.GetValue(build) == null;
return member.GetMemberType() != typeof(string)
? member.GetValue(build) == null
: member.GetValue<string>(build).IsNullOrWhiteSpace();
}

private static void TryInjectValueInteractive(MemberInfo member, INukeBuild build)
Expand Down

0 comments on commit 926ffbc

Please sign in to comment.