Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor: Assert #318

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

Splaxi
Copy link
Contributor

@Splaxi Splaxi commented Apr 14, 2022

Convert parameter names into pascal

Description

Convert parameter names into pascal

Related Issue

#308

Motivation and Context

How Has This Been Tested?

ps>Get-Help Assert -Full

NAME
    Assert

SYNOPSIS
    Helper function for "Design by Contract" assertion checking.


SYNTAX
    Assert [-ConditionToCheck] <Object> [-FailureMessage] <String> [<CommonParameters>]


DESCRIPTION
    This is a helper function that makes the code less noisy by eliminating many of the
    "if" statements that are normally required to verify assumptions in the code.


PARAMETERS
    -ConditionToCheck <Object>
        The boolean condition to evaluate

        Required?                    true
        Position?                    1
        Default value
        Accept pipeline input?       false
        Accept wildcard characters?  false

    -FailureMessage <String>
        The error message used for the exception if the ConditionToCheck parameter is
        false

        Required?                    true
        Position?                    2
        Default value
        Accept pipeline input?       false
        Accept wildcard characters?  false

    <CommonParameters>
        This cmdlet supports the common parameters: Verbose, Debug,
        ErrorAction, ErrorVariable, WarningAction, WarningVariable,
        OutBuffer, PipelineVariable, and OutVariable. For more information, see
        about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).

INPUTS

OUTPUTS

    -------------------------- EXAMPLE 1 --------------------------

    C:\PS>Assert $false "This always throws an exception"

    Example of an assertion that will always fail.




    -------------------------- EXAMPLE 2 --------------------------

    C:\PS>Assert ( ($i % 2) -eq 0 ) "$i is not an even number"

    This exmaple may throw an exception if $i is not an even number

    Note:
    It might be necessary to wrap the condition with paranthesis to force PS to evaluate
    the condition
    so that a boolean value is calculated and passed into the 'ConditionToCheck'
    parameter.

    Example:
        Assert 1 -eq 2 "1 doesn't equal 2"

    PS will pass 1 into the condtionToCheck variable and PS will look for a parameter
    called "eq" and
    throw an exception with the following message "A parameter cannot be found that
    matches parameter name 'eq'"

    The solution is to wrap the condition in () so that PS will evaluate it first.

    Assert (1 -eq 2) "1 doesn't equal 2"





RELATED LINKS
    Exec
    FormatTaskName
    Framework
    Get-PSakeScriptTasks
    Include
    Invoke-psake
    Properties
    Task
    TaskSetup
    TaskTearDown

Screenshots (if appropriate):

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@Splaxi Splaxi changed the title Refactor assert pascal Refactor: Assert Apr 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant