Skip to content

Commit e81993d

Browse files
author
James Brundage
committed
Merge branch 'PipeScriptKeywordsAndRestfulImprovements' of https://github.com/StartAutomating/PipeScript into PipeScriptKeywordsAndRestfulImprovements
2 parents 423dec5 + e972302 commit e81993d

File tree

1 file changed

+78
-0
lines changed

1 file changed

+78
-0
lines changed

docs/Assert.md

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
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+

0 commit comments

Comments
 (0)