File tree Expand file tree Collapse file tree 1 file changed +78
-0
lines changed
Expand file tree Collapse file tree 1 file changed +78
-0
lines changed Original file line number Diff line number Diff line change 1+
2+ Assert
3+ ------
4+ ### Synopsis
5+ Assert keyword
6+
7+ ---
8+ ### Description
9+
10+ Assert is a common keyword in many programming languages.
11+
12+ In PipeScript, Asset will take a condition and an optional action.
13+
14+ The condtion may be contained in either parenthesis or a [ ScriptBlock] .
15+
16+ If there is no action, the assertion will throw an exception containing the condition.
17+
18+ If the action is a string, the assertion will throw that error as a string.
19+
20+ If the action is a ScriptBlock, it will be run if the assertion is false.
21+
22+ Assertions will not be transpiled or included if -Verbose or -Debug has not been set.
23+
24+ Additionally, while running, Assertions will be ignored if -Verbose or -Debug has not been set.
25+
26+ ---
27+ ### Examples
28+ #### EXAMPLE 1
29+ ``` PowerShell
30+ # With no second argument, assert will throw an error with the condition of the assertion.
31+ Invoke-PipeScript {
32+ assert (1 -eq 1)
33+ } -Debug
34+ ```
35+
36+ #### EXAMPLE 2
37+ ``` PowerShell
38+ # With a second argument of a string, assert will throw an error
39+ Invoke-PipeScript {
40+ assert ($true) "It's true"
41+ } -Debug
42+ ```
43+
44+ #### EXAMPLE 3
45+ ``` PowerShell
46+ # Conditions can also be written as a ScriptBlock
47+ Invoke-PipeScript {
48+ assert {$true} "Process id '$pid' Asserted"
49+ } -Verbose
50+ ```
51+
52+ #### EXAMPLE 4
53+ ``` PowerShell
54+ # If the assertion action was a ScriptBlock, no exception is automatically thrown
55+ Invoke-PipeScript {
56+ assert ($true) { Write-Information "Assertion was true"}
57+ } -Verbose
58+ ```
59+
60+ ---
61+ ### Parameters
62+ #### ** CommandAst**
63+
64+ The CommandAst
65+
66+
67+
68+ | Type | Requried| Postion| PipelineInput |
69+ | ------------------| --------| -------| --------------|
70+ | ``` [CommandAst] ``` | true | named | true (ByValue)|
71+ ---
72+ ### Syntax
73+ ``` PowerShell
74+ Assert -CommandAst <CommandAst> [<CommonParameters>]
75+ ```
76+ ---
77+
78+
You can’t perform that action at this time.
0 commit comments