$ErrorActionPreference = 'Stop' . (Join-Path (Split-Path $PSScriptRoot -Parent) 'NDTrack-Geprueft.ps1') -LibraryOnly $root = Join-Path ([IO.Path]::GetTempPath()) ('ndtrack-test-' + [guid]::NewGuid().ToString('N')) $script:checks=0 function Assert { param($Condition,$Message) if(-not $Condition){throw $Message}; $script:checks++ } function Assert-Fails { param([scriptblock]$Action,[string]$Pattern) $message='' try { & $Action } catch { $message=$_.Exception.Message } Assert ($message -like $Pattern) "Erwarteter Fehler fehlt: $Pattern / $message" } try { $script:ScriptFolder=Join-Path $root 'SCRIPT' $script:SourcePath=Join-Path $root 'NDTRACK' $script:LinuxSourcePath=$script:SourcePath $script:Ergebnisordner=Join-Path $root 'RESULTS' $script:LogFolder=Join-Path $script:ScriptFolder 'Logs' CheckDirectory foreach($path in @($script:ScriptFolder,$script:SourcePath,$script:Ergebnisordner,$script:LogFolder)) { Assert (Test-Path -LiteralPath $path -PathType Container) "Ordner fehlt: $path" } CheckDirectory # Wiederholbarer Aufruf Assert-Fails { Test-SourceFiles $script:SourcePath } '*Keine Dateien*' New-Item -Path (Join-Path $script:SourcePath 'empty') -ItemType Directory | Out-Null Assert-Fails { Test-SourceFiles $script:SourcePath } '*Keine Dateien*' Set-Content -LiteralPath (Join-Path $script:SourcePath 'payload.dat') -Value 'test' Test-SourceFiles $script:SourcePath $script:checks++ Assert-Fails { Test-SourceFiles $script:SourcePath 'Run.cmd' } '*Startdatei fehlt*' [IO.File]::WriteAllText((Join-Path $script:SourcePath 'Run.cmd'),'') Assert-Fails { Test-SourceFiles $script:SourcePath 'Run.cmd' } '*Startdatei ist leer*' Set-Content -LiteralPath (Join-Path $script:SourcePath 'Run.cmd') -Value '@echo test' Test-SourceFiles $script:SourcePath 'Run.cmd' $script:checks++ $script:ScriptFolder=Join-Path $root 'file-instead-of-folder' Set-Content -LiteralPath $script:ScriptFolder -Value 'keep' Assert-Fails { CheckDirectory } '*Datei statt eines Ordners*' Assert ((Get-Content -LiteralPath $script:ScriptFolder) -eq 'keep') 'Bestehende Datei veraendert' Write-Host "$script:checks Ordner-/Dateipruefungen bestanden." } finally { if(Test-Path -LiteralPath $root){Remove-Item -LiteralPath $root -Recurse -Force} }