PS: Add tests for flow sources.

This commit is contained in:
Mathias Vorreiter Pedersen
2025-04-15 17:03:14 +01:00
parent 826e6a9ee8
commit 396a283da9
15 changed files with 79 additions and 0 deletions

View File

@@ -0,0 +1,8 @@
$data = Read-Host -Prompt "Enter your name" # $ type="read from stdin"
$xmlQuery = "/Users/User"
$path = "C:/Users/MyData.xml"
$xmldata = Select-Xml -Path $path -XPath $xmlQuery # $ type="file stream"
$hexdata = Format-Hex -Path $path -Count 48 # $ type="file stream"

View File

@@ -0,0 +1 @@
import TestUtilities.InlineFlowSourceTest

View File

@@ -0,0 +1,16 @@
$registryPath = "HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Windows NT/CurrentVersion"
$valueName = "ProductName"
$productName = [Microsoft.Win32.Registry]::GetValue($registryPath, $valueName, $null) # $ type="a value from the Windows registry"
$registryKey = [Microsoft.Win32.Registry]::LocalMachine.OpenSubKey($registryPath)
# Get the value of a registry key
$productName2 = $registryKey.GetValue($valueName) # $ type="a value from the Windows registry"
# Get all value names in the registry key
$valueNames = $registryKey.GetValueNames() # $ type="a value from the Windows registry"
# TODO: I think this should also have a positional element on the access path
$subKeyNames = $registryKey.GetSubKeyNames() # $ type="a value from the Windows registry"

View File

@@ -0,0 +1 @@
import TestUtilities.InlineFlowSourceTest

View File

@@ -0,0 +1,11 @@
$char = [System.Console]::Read() # $ type="read from stdin"
$keyInfo = [System.Console]::ReadKey($true) # $ type="read from stdin"
$userName = [System.Console]::ReadLine() # $ type="read from stdin"
# $input = [System.Console]::ReadToEnd() # TODO we need to model this one
$path = "%USERPROFILE%\Documents"
$expandedPath = [System.Environment]::ExpandEnvironmentVariables($path) # $ type="environment variable"
$args = [System.Environment]::GetCommandLineArgs() # $ type="command line argument"
$variableValue = [System.Environment]::GetEnvironmentVariable("PATH") # $ type="environment variable"
$envVariables = [System.Environment]::GetEnvironmentVariables() # $ type="environment variable"

View File

@@ -0,0 +1 @@
import TestUtilities.InlineFlowSourceTest

View File

@@ -0,0 +1,21 @@
$filePath = "C:\Temp\example.txt"
$fileStream = [System.IO.File]::Open($filePath, [System.IO.FileMode]::OpenOrCreate, [System.IO.FileAccess]::ReadWrite) # $ type="file stream"
$fileStream2 = [System.IO.File]::OpenRead($filePath) # $ type="file stream"
$reader = [System.IO.File]::OpenText($filePath) # $ type="file stream"
$bytes = [System.IO.File]::ReadAllBytes($filePath) # $ type="file stream"
$lines = [System.IO.File]::ReadAllLines($filePath) # $ type="file stream"
$bytesTask = [System.IO.File]::ReadAllBytesAsync($filePath) # $ type="file stream"
$linesTask = [System.IO.File]::ReadAllLinesAsync($filePath) # $ type="file stream"
$stream = [System.IO.File]::ReadAllText($filePath) # $ type="file stream"
$streamTask = [System.IO.File]::ReadAllTextAsync($filePath) # $ type="file stream"
$lines2 = [System.IO.File]::ReadLines($filePath) # $ type="file stream"
$lines3 = [System.IO.File]::ReadLinesAsync($filePath) # $ type="file stream"
$fileInfo = [System.IO.FileInfo]::new("C:\Temp\example.txt")
# Open the file for reading and writing
$fileStream3 = $fileInfo.Open([System.IO.FileMode]::OpenOrCreate, [System.IO.FileAccess]::ReadWrite) # $ type="file stream"
$fileStream4 = $fileInfo.OpenRead() # $ type="file stream"
$reader2 = $fileInfo.OpenText() # $ type="file stream"

View File

@@ -0,0 +1 @@
import TestUtilities.InlineFlowSourceTest

View File

@@ -0,0 +1 @@
| test.ps1:1:1:18:0 | [synth] pipeline | Unexpected result: type="command line argument" |

View File

@@ -0,0 +1,17 @@
param($server) # $ type="command line argument"
$tcpClient = [System.Net.Sockets.TcpClient]::new($server, 8080)
$networkStream = $tcpClient.GetStream() # $ type="remote flow source"
$localEndpoint = [System.Net.IPEndPoint]::new([System.Net.IPAddress]::Any, 8080)
$udpClient = [System.Net.Sockets.UdpClient]::new($localEndpoint)
$asyncResult = $udpClient.BeginReceive($null, $null)
$asyncResult.AsyncWaitHandle.WaitOne()
$remoteEndpoint = $null
$data = $udpClient.EndReceive($asyncResult, [ref]$remoteEndpoint) # $ type="remote flow source"
$remoteEndpoint2 = $null
$data2 = $udpClient.Receive([ref]$remoteEndpoint2) # $ type="remote flow source"
$receiveTask = $udpClient.ReceiveAsync() # $ type="remote flow source"

View File

@@ -0,0 +1 @@
import TestUtilities.InlineFlowSourceTest