diff --git a/scripts/smoke-test-android.ps1 b/scripts/smoke-test-android.ps1 index 7d40fd837..bae17d93b 100644 --- a/scripts/smoke-test-android.ps1 +++ b/scripts/smoke-test-android.ps1 @@ -99,17 +99,17 @@ function PidOf([string] $deviceId, [string] $processName) return $processId } - Write-Host "Process '$processName' not found, retrying in 2 seconds..." + Write-Log "Process '$processName' not found, retrying in 2 seconds..." Start-Sleep -Seconds 2 } - Write-Host "Could not find PID for process '$processName' after 60 seconds" -ForegroundColor Red + Write-Log "Could not find PID for process '$processName' after 60 seconds" -ForegroundColor Red return $null } function OnError([string] $deviceId, [string] $deviceApi, [string] $appPID) { - Write-Host "Dumping logs for $device" + Write-Log "Dumping logs for $device" Write-Host "::group::logcat" LogCat $deviceId $appPID Write-Host "::endgroup::" @@ -140,7 +140,7 @@ If ($DeviceCount -eq 0) } Else { - Write-Host "Found $DeviceCount devices: $DeviceList" + Write-Log "Found $DeviceCount devices: $DeviceList" } # Check if APK was built. @@ -159,13 +159,13 @@ adb -s $device logcat -c $deviceApi = "$(adb -s $device shell getprop ro.build.version.sdk)".Trim() $deviceSdk = "$(adb -s $device shell getprop ro.build.version.release)".Trim() -Write-Host "`nChecking device $device with SDK '$deviceSdk' and API '$deviceApi'" +Write-Log "`nChecking device $device with SDK '$deviceSdk' and API '$deviceApi'" # Uninstall previous installation $stdout = adb -s $device shell "pm list packages -f" if ($null -ne ($stdout | Select-String $ProcessName)) { - Write-Host "Uninstalling previous $ProcessName." + Write-Log "Uninstalling previous $ProcessName." $stdout = adb -s $device uninstall $ProcessName } @@ -176,7 +176,7 @@ $stdout = adb -s $device shell input keyevent KEYCODE_HOME $adbInstallRetry = 5 do { - Write-Host "Installing test app" + Write-Log "Installing test app" $stdout = (adb -s $device install -r $BuildDir/$ApkFileName 2>&1) if ($stdout.Contains("Broken pipe")) @@ -190,7 +190,7 @@ do # Validate the installation If ($stdout -contains "Success") { - Write-Host "Successfully installed APK" + Write-Log "Successfully installed APK" } else { @@ -218,18 +218,18 @@ function RunTest([string] $Name, [string] $SuccessString, [string] $FailureStrin { Write-Host "::group::Test: '$name'" - Write-Host "Clearing logcat from '$device'" + Write-Log "Clearing logcat from '$device'" adb -s $device logcat -c $activityName = $TestActivityName - Write-Host "Setting configuration" + Write-Log "Setting configuration" # Mark the full-screen notification as acknowledged adb -s $device shell "settings put secure immersive_mode_confirmations confirmed" adb -s $device shell "input keyevent KEYCODE_HOME" - Write-Host "Starting app '$activityName'" + Write-Log "Starting app '$activityName'" # Start the adb command as a background job so we can wait for it to finish with a timeout $job = Start-Job -ScriptBlock { @@ -242,44 +242,44 @@ function RunTest([string] $Name, [string] $SuccessString, [string] $FailureStrin if ($null -eq $completed) { Stop-Job $job Remove-Job $job -Force - Write-Host "Activity start timed out after 60 seconds" + Write-Log "Activity start timed out after 60 seconds" return $false } $output = Receive-Job $job Remove-Job $job - - Write-Host "Checking if activity started" + + Write-Log "Checking if activity started" # Check if the activity failed to start if ($output -match "Error type 3" -or $output -match "Activity class \{$activityName\} does not exist.") { $activityName = $FallBackTestActivityName - Write-Host "Trying fallback activity $activityName" + Write-Log "Trying fallback activity $activityName" $output = & adb -s $device shell am start -n $activityName -e test $Name -W 2>&1 - + # Check if the fallback activity failed to start if ($output -match "Error type 3" -or $output -match "Activity class \{$activityName\} does not exist.") { - Write-Host "Activity does not exist" + Write-Log "Activity does not exist" return $false } } - - Write-Host "Activity started successfully" + + Write-Log "Activity started successfully" $appPID = PidOf $device $ProcessName if ($null -eq $appPID) { Write-Host "::endgroup::" - Write-Host "Retrieving process ID failed. Skipping test." -ForegroundColor Red + Write-Log "Retrieving process ID failed. Skipping test." -ForegroundColor Red return $false } - Write-Host "Retrieved ID for '$ProcessName': $appPID" + Write-Log "Retrieved ID for '$ProcessName': $appPID" - Write-Host "Waiting for tests to run..." + Write-Log "Waiting for tests to run..." $processFinished = $false $logCache = @() @@ -297,7 +297,7 @@ function RunTest([string] $Name, [string] $SuccessString, [string] $FailureStrin # For crash tests, we're checking for `sentry-native` logging "crash has been captured" to reliably inform when tests finished running. if (($newLogs | Select-String "SmokeTester is quitting.") -or ($newLogs | Select-String "crash has been captured")) { - Write-Host "Process finished marker detected. Finish waiting for tests to run." + Write-Log "Process finished marker detected. Finish waiting for tests to run." $processFinished = $true break } @@ -307,11 +307,11 @@ function RunTest([string] $Name, [string] $SuccessString, [string] $FailureStrin if ($processFinished) { - Write-Host "'$Name' test finished running." + Write-Log "'$Name' test finished running." } else - { - Write-Host "'$Name' tests timed out. See logcat for more details." + { + Write-Log "'$Name' tests timed out. See logcat for more details." } Write-Host "::endgroup::" @@ -320,7 +320,7 @@ function RunTest([string] $Name, [string] $SuccessString, [string] $FailureStrin $logCache = ProcessNewLogs -newLogs $newLogs -lastLogCount ([ref]$lastLogCount) -logCache $logCache Write-Host "::group::logcat" - $logCache | ForEach-Object { Write-Host $_ } + $logCache | ForEach-Object { Write-Host $_ } Write-Host "::endgroup::" $lineWithSuccess = $logCache | Select-String $SuccessString @@ -328,16 +328,16 @@ function RunTest([string] $Name, [string] $SuccessString, [string] $FailureStrin if ($null -ne $lineWithSuccess) { - Write-Host "'$Name' test passed." -ForegroundColor Green + Write-Log "'$Name' test passed." -ForegroundColor Green return $true } elseif ($null -ne $lineWithFailure) { - Write-Host "'$Name' test failed. See logcat for more details." -ForegroundColor Red + Write-Log "'$Name' test failed. See logcat for more details." -ForegroundColor Red return $false } - - Write-Host "'$Name' test execution failed." -ForegroundColor Red + + Write-Log "'$Name' test execution failed." -ForegroundColor Red return $false } @@ -347,29 +347,29 @@ function RunTestWithRetry([string] $Name, [string] $SuccessString, [string] $Fai { if ($retryCount -gt 0) { - Write-Host "Retry attempt $retryCount for test '$Name'" + Write-Log "Retry attempt $retryCount for test '$Name'" Start-Sleep -Seconds 2 # Brief pause between retries } - Write-Host "Running test attempt $($retryCount + 1)/$MaxRetries" + Write-Log "Running test attempt $($retryCount + 1)/$MaxRetries" $result = RunTest -Name $Name -SuccessString $SuccessString -FailureString $FailureString - + if ($result) { - Write-Host "'$Name' test passed on attempt $($retryCount + 1)." -ForegroundColor Green + Write-Log "'$Name' test passed on attempt $($retryCount + 1)." -ForegroundColor Green return $true } - + if ($retryCount + 1 -lt $MaxRetries) { - Write-Host "'$Name' test failed. Retrying..." -ForegroundColor Yellow + Write-Log "'$Name' test failed. Retrying..." -ForegroundColor Yellow continue } - - Write-Host "'$Name' test failed after $MaxRetries attempts." -ForegroundColor Red + + Write-Log "'$Name' test failed after $MaxRetries attempts." -ForegroundColor Red return $false } - + return $false } @@ -392,35 +392,35 @@ try } catch { - Write-Host "Caught exception: $_" - Write-Host $_.ScriptStackTrace + Write-Log "Caught exception: $_" + Write-Log $_.ScriptStackTrace OnError $device $deviceApi exit 1 } $failed = $false -if (-not $results.smoketestPassed) +if (-not $results.smoketestPassed) { - Write-Host "Smoke test failed" + Write-Log "Smoke test failed" $failed = $true } if (-not $results.hasntCrashedTestPassed) { - Write-Host "HasntCrashed test failed" + Write-Log "HasntCrashed test failed" $failed = $true } if (-not $results.crashTestPassed) { - Write-Host "Crash test failed" + Write-Log "Crash test failed" $failed = $true } if (-not $results.hasCrashTestPassed) { - Write-Host "HasCrashed test failed" + Write-Log "HasCrashed test failed" $failed = $true } @@ -429,5 +429,5 @@ if ($failed) exit 1 } -Write-Host "All tests passed" -ForegroundColor Green +Write-Log "All tests passed" -ForegroundColor Green exit 0 diff --git a/scripts/smoke-test-ios.ps1 b/scripts/smoke-test-ios.ps1 index 4742998a7..c7efb8dd7 100644 --- a/scripts/smoke-test-ios.ps1 +++ b/scripts/smoke-test-ios.ps1 @@ -6,7 +6,6 @@ param ( [string] $UnityVersion = "", [string] $iOSMinVersion = "" ) -Write-Host "Args received Action=$Action, SelectedRuntime=$SelectedRuntime, IsIntegrationTest=$IsIntegrationTest" # $Action: 'Build' for build only # 'Test' for Smoke test only # null for building and testing @@ -18,6 +17,8 @@ Write-Host "Args received Action=$Action, SelectedRuntime=$SelectedRuntime, IsIn . $PSScriptRoot/../test/Scripts.Integration.Test/common.ps1 +Write-Log "Args received Action=$Action, SelectedRuntime=$SelectedRuntime, IsIntegrationTest=$IsIntegrationTest" + $ProjectName = "Unity-iPhone" $XcodeArtifactPath = "samples/IntegrationTest/Build" $ArchivePath = "$XcodeArtifactPath/archive" @@ -86,7 +87,7 @@ function Build() function Test { - Write-Host "Retrieving list of available simulators" -ForegroundColor Green + Write-Log "Retrieving list of available simulators" -ForegroundColor Green $deviceListRaw = xcrun simctl list devices Write-Host "::group::Available simulators:" $deviceListRaw | Write-Host @@ -94,8 +95,8 @@ function Test [AppleDevice[]]$deviceList = @() - Write-Host "Picking simulator based on selected runtime" -ForegroundColor Green - + Write-Log "Picking simulator based on selected runtime" -ForegroundColor Green + # Find the index of the selected runtime $runtimeIndex = ($deviceListRaw | Select-String "-- $SelectedRuntime --").LineNumber If ($null -eq $runtimeIndex) @@ -130,25 +131,25 @@ function Test { If ($devicesRan -ge $DevicesToRun) { - # Write-Host "Skipping Simulator $($device.Name) UUID $($device.UUID)" -ForegroundColor Green + # Write-Log "Skipping Simulator $($device.Name) UUID $($device.UUID)" -ForegroundColor Green $device.TestSkipped = $true continue } $devicesRan++ - Write-Host "Starting Simulator $($device.Name) UUID $($device.UUID)" -ForegroundColor Green + Write-Log "Starting Simulator $($device.Name) UUID $($device.UUID)" -ForegroundColor Green xcrun simctl boot $($device.UUID) - Write-Host -NoNewline "Installing Smoke Test on $($device.Name): " + Write-Log -NoNewline "Installing Smoke Test on $($device.Name): " If (!(Test-Path $AppPath)) { Write-Error "App doesn't exist at the expected path $AppPath. Did you forget to run Build first?" } xcrun simctl install $($device.UUID) "$AppPath" - Write-Host "OK" -ForegroundColor Green + Write-Log "OK" -ForegroundColor Green function RunTest([string] $Name, [string] $SuccessString) { - Write-Host "Test: '$name'" - Write-Host "Launching '$Name' test on '$($device.Name)'" -ForegroundColor Green + Write-Log "Test: '$name'" + Write-Log "Launching '$Name' test on '$($device.Name)'" -ForegroundColor Green $consoleOut = xcrun simctl launch --console-pty $($device.UUID) $AppName "--test" $Name if ("$SuccessString" -eq "") @@ -156,16 +157,16 @@ function Test $SuccessString = "$($Name.ToUpper()) TEST: PASS" } - Write-Host -NoNewline "'$Name' test STATUS: " + Write-Log -NoNewline "'$Name' test STATUS: " $stdout = $consoleOut | Select-String $SuccessString If ($null -ne $stdout) { - Write-Host "PASSED" -ForegroundColor Green + Write-Log "PASSED" -ForegroundColor Green } Else { $device.TestFailed = $True - Write-Host "FAILED" -ForegroundColor Red + Write-Log "FAILED" -ForegroundColor Red } Write-Host "::group::$($device.Name) Console Output" @@ -198,36 +199,36 @@ function Test throw; } - Write-Host -NoNewline "Removing Smoke Test from $($device.Name): " + Write-Log -NoNewline "Removing Smoke Test from $($device.Name): " xcrun simctl uninstall $($device.UUID) $AppName - Write-Host "OK" -ForegroundColor Green + Write-Log "OK" -ForegroundColor Green - Write-Host -NoNewline "Requesting shutdown for $($device.Name): " + Write-Log -NoNewline "Requesting shutdown for $($device.Name): " # Do not wait for the Simulator to close and continue testing the other simulators. Start-Process xcrun -ArgumentList "simctl shutdown `"$($device.UUID)`"" - Write-Host "OK" -ForegroundColor Green + Write-Log "OK" -ForegroundColor Green } $testFailed = $false - Write-Host "Test result" + Write-Log "Test result" foreach ($device in $deviceList) { - Write-Host -NoNewline "$($device.Name) UUID $($device.UUID): " + Write-Log -NoNewline "$($device.Name) UUID $($device.UUID): " If ($device.TestFailed) { - Write-Host "FAILED" -ForegroundColor Red + Write-Log "FAILED" -ForegroundColor Red $testFailed = $true } ElseIf ($device.TestSkipped) { - Write-Host "SKIPPED" -ForegroundColor Gray + Write-Log "SKIPPED" -ForegroundColor Gray } Else { - Write-Host "PASSED" -ForegroundColor Green + Write-Log "PASSED" -ForegroundColor Green } } - Write-Host "End of test." + Write-Log "End of test." If ($testFailed -eq $true) { @@ -245,14 +246,14 @@ function LatestRuntime Throw "Last runtime was not found, result: $result" } $lastRuntimeParsed = $result.Groups["runtime"].Value - Write-Host "Using latest runtime = $lastRuntimeParsed" + Write-Log "Using latest runtime = $lastRuntimeParsed" return $lastRuntimeParsed } # MAIN If (-not $IsMacOS) { - Write-Host "This script should only be run on a MacOS." -ForegroundColor Yellow + Write-Log "This script should only be run on a MacOS." -ForegroundColor Yellow } If ($null -eq $action -Or $action -eq "Build") { diff --git a/test/Scripts.Integration.Test/add-sentry.ps1 b/test/Scripts.Integration.Test/add-sentry.ps1 index ba21c9c6c..f1cd6762e 100644 --- a/test/Scripts.Integration.Test/add-sentry.ps1 +++ b/test/Scripts.Integration.Test/add-sentry.ps1 @@ -14,6 +14,6 @@ $UnityPath = FormatUnityPath $UnityPath RunUnityAndExpect $UnityPath "AddSentryPackage" "Sentry Package Installation: SUCCESS" @( ` "-batchmode", "-projectPath ", "$(GetNewProjectPath)", "-installSentry", "Disk") -Write-Host "Copying Integration Test Files" +Write-Log "Copying Integration Test Files" New-Item -Path "$(GetNewProjectAssetsPath)" -Name "Scripts" -ItemType "directory" Copy-Item -Recurse "$IntegrationScriptsPath/Scripts/*" -Destination "$(GetNewProjectAssetsPath)/Scripts/" diff --git a/test/Scripts.Integration.Test/build-project.ps1 b/test/Scripts.Integration.Test/build-project.ps1 index eb29aca5e..d02a8d159 100644 --- a/test/Scripts.Integration.Test/build-project.ps1 +++ b/test/Scripts.Integration.Test/build-project.ps1 @@ -16,7 +16,7 @@ $unityPath = FormatUnityPath $UnityPath $buildMethod = BuildMethodFor $Platform $outputPath = "$(GetNewProjectBuildPath)/$(GetTestAppName $buildMethod)" -Write-Host "Executing ${buildMethod}:" +Write-Log "Executing ${buildMethod}:" $unityArgs = @("-batchmode", "-projectPath ", "$(GetNewProjectPath)", "-executeMethod", $buildMethod , "-buildPath", $outputPath, "-quit") if ($CheckSymbols) @@ -36,5 +36,5 @@ if ($Platform -eq "Android-Export") Copy-Item -Force -Recurse "$IntegrationScriptsPath/gradle/$gradleVersion/*" -Destination $outputPath } -Write-Host "Project built successfully" -ForegroundColor Green +Write-Log "Project built successfully" -ForegroundColor Green Get-ChildItem $(GetNewProjectBuildPath) diff --git a/test/Scripts.Integration.Test/common.ps1 b/test/Scripts.Integration.Test/common.ps1 index 164e7a9dd..0d42a35a4 100644 --- a/test/Scripts.Integration.Test/common.ps1 +++ b/test/Scripts.Integration.Test/common.ps1 @@ -4,6 +4,28 @@ Set-StrictMode -Version latest $ErrorActionPreference = "Stop" +function Write-Log +{ + param( + [Parameter(Mandatory = $true, ValueFromPipeline = $true)] + [string]$Message, + [string]$ForegroundColor = "White", + [switch]$NoNewline + ) + + $timestamp = Get-Date -Format "HH:mm:ss.fff" + $output = "$timestamp | $Message" + + if ($NoNewline) + { + Write-Host $output -ForegroundColor $ForegroundColor -NoNewline + } + else + { + Write-Host $output -ForegroundColor $ForegroundColor + } +} + function RunApiServer([string] $ServerScript, [string] $Uri) { if ([string]::IsNullOrEmpty($Uri)) @@ -12,7 +34,7 @@ function RunApiServer([string] $ServerScript, [string] $Uri) } $result = "" | Select-Object -Property process, outFile, errFile, stop, output, dispose - Write-Host "Starting the $ServerScript on $Uri" + Write-Log "Starting the $ServerScript on $Uri" $result.outFile = New-TemporaryFile $result.errFile = New-TemporaryFile @@ -39,16 +61,18 @@ function RunApiServer([string] $ServerScript, [string] $Uri) return "$stdout`n$stderr" }.GetNewClosure() + # Capture Write-Log function so it can be used inside the closure (GetNewClosure captures variables but not functions) + $writeLog = ${function:Write-Log} $result.stop = { # Stop the HTTP server - Write-Host "Stopping the $ServerScript ... " -NoNewline + & $writeLog "Stopping the $ServerScript ... " -NoNewline try { Write-Host (Invoke-WebRequest -Uri "$Uri/STOP").StatusDescription } catch { - Write-Host "/STOP request failed: $_ - killing the server process instead" + & $writeLog "/STOP request failed: $_ - killing the server process instead" $result.process | Stop-Process -Force -ErrorAction SilentlyContinue } $result.process | Wait-Process -Timeout 10 -ErrorAction Continue @@ -59,10 +83,10 @@ function RunApiServer([string] $ServerScript, [string] $Uri) Start-Sleep -Second 1 if ($result.process.HasExited) { - Write-Host "Couldn't start the $ServerScript" -ForegroundColor Red - Write-Host "Standard Output:" -ForegroundColor Yellow + Write-Log "Couldn't start the $ServerScript" -ForegroundColor Red + Write-Log "Standard Output:" -ForegroundColor Yellow Get-Content $result.outFile - Write-Host "Standard Error:" -ForegroundColor Yellow + Write-Log "Standard Error:" -ForegroundColor Yellow Get-Content $result.errFile Remove-Item $result.outFile Remove-Item $result.errFile @@ -79,7 +103,7 @@ function CrashTestWithServer([ScriptBlock] $CrashTestCallback, [string] $Success throw "SuccessString cannot be empty" } - Write-Host "Running crash test with server" -ForegroundColor Yellow + Write-Log "Running crash test with server" -ForegroundColor Yellow # You can increase this to retry multiple times. Seems a bit flaky at the moment in CI. if ($null -eq $env:CI) @@ -97,7 +121,7 @@ function CrashTestWithServer([ScriptBlock] $CrashTestCallback, [string] $Success { if ($run -ne 1) { - Write-Host "Sleeping for $run seconds before the next retry..." + Write-Log "Sleeping for $run seconds before the next retry..." Start-Sleep -Seconds $run } @@ -127,7 +151,7 @@ function CrashTestWithServer([ScriptBlock] $CrashTestCallback, [string] $Success # evaluate the result for ($i = $timeout; $i -gt 0; $i--) { - Write-Host "Waiting for the expected message to appear in the server output logs; $i seconds remaining..." + Write-Log "Waiting for the expected message to appear in the server output logs; $i seconds remaining..." if ("$($httpServer.output.Invoke())".Contains($SuccessString)) { break @@ -136,13 +160,13 @@ function CrashTestWithServer([ScriptBlock] $CrashTestCallback, [string] $Success } $output = $httpServer.dispose.Invoke() - Write-Host "Looking for the SuccessString ($SuccessString) in the server output..." + Write-Log "Looking for the SuccessString ($SuccessString) in the server output..." if ("$output".Contains($SuccessString)) { - Write-Host "crash test $run/$runs : PASSED" -ForegroundColor Green + Write-Log "crash test $run/$runs : PASSED" -ForegroundColor Green break } - Write-Host "SuccessString ($SuccessString) not found..." -ForegroundColor Red + Write-Log "SuccessString ($SuccessString) not found..." -ForegroundColor Red if ($run -eq $runs) { throw "crash test $run/$runs : FAILED" @@ -183,7 +207,7 @@ function RunWithSymbolServer([ScriptBlock] $Callback) function CheckSymbolServerOutput([string] $buildMethod, [string] $symbolServerOutput, [string] $unityVersion) { - Write-Host "Checking symbol server output" -ForegroundColor Yellow + Write-Log "Checking symbol server output" -ForegroundColor Yellow # Server stats contains: # filename @@ -296,7 +320,7 @@ function CheckSymbolServerOutput([string] $buildMethod, [string] $symbolServerOu } ElseIf ($buildMethod.contains('WebGL')) { - Write-Host 'No symbols are uploaded for WebGL - nothing to test.' -ForegroundColor Yellow + Write-Log 'No symbols are uploaded for WebGL - nothing to test.' -ForegroundColor Yellow return } Else @@ -304,7 +328,7 @@ function CheckSymbolServerOutput([string] $buildMethod, [string] $symbolServerOu Throw "Cannot CheckSymbolServerOutput() for an unknown buildMethod: '$buildMethod'" } - Write-Host 'Verifying debug symbol upload...' + Write-Log 'Verifying debug symbol upload...' $successful = $true :nextExpectedFile foreach ($file in $expectedFiles) { @@ -314,7 +338,7 @@ function CheckSymbolServerOutput([string] $buildMethod, [string] $symbolServerOu # It's enough if a single symbol alternative is found if ($symbolServerOutput -match " $([Regex]::Escape($file))\b") { - Write-Host " $file - OK" + Write-Log " $file - OK" continue nextExpectedFile } } @@ -328,11 +352,11 @@ function CheckSymbolServerOutput([string] $buildMethod, [string] $symbolServerOu $successful = $false } - Write-Host " $alternatives - MISSING `n Server received '$actualCount' instead." -ForegroundColor Red + Write-Log " $alternatives - MISSING `n Server received '$actualCount' instead." -ForegroundColor Red } if ($successful) { - Write-Host 'All expected debug symbols have been uploaded' -ForegroundColor Green + Write-Log 'All expected debug symbols have been uploaded' -ForegroundColor Green } else { @@ -346,7 +370,7 @@ function RunUnityAndExpect([string] $UnityPath, [string] $name, [string] $succes $lineWithSuccess = $stdout | Select-String $successMessage If ($null -ne $lineWithSuccess) { - Write-Host "`n$name | SUCCESS because the following text was found: '$lineWithSuccess'" -ForegroundColor Green + Write-Log "`n$name | SUCCESS because the following text was found: '$lineWithSuccess'" -ForegroundColor Green } Else { @@ -358,8 +382,8 @@ function MakeExecutable([string] $file) { If ((Test-Path -Path $file) -and (Get-Command 'chmod' -ErrorAction SilentlyContinue)) { - Write-Host -NoNewline "Fixing permission for $file : " + Write-Log -NoNewline "Fixing permission for $file : " chmod +x $file - Write-Host "OK" -ForegroundColor Green + Write-Log "OK" -ForegroundColor Green } } diff --git a/test/Scripts.Integration.Test/create-project.ps1 b/test/Scripts.Integration.Test/create-project.ps1 index 409c5ee99..f18cfea52 100644 --- a/test/Scripts.Integration.Test/create-project.ps1 +++ b/test/Scripts.Integration.Test/create-project.ps1 @@ -7,30 +7,32 @@ if (-not $Global:NewProjectPathCache) . ./test/Scripts.Integration.Test/globals.ps1 } +. ./test/Scripts.Integration.Test/common.ps1 + $UnityPath = FormatUnityPath $UnityPath # Delete previous integration test project folder if found If (Test-Path -Path "$(GetNewProjectPath)" ) { - Write-Host -NoNewline "Removing previous integration test:" + Write-Log -NoNewline "Removing previous integration test:" Remove-Item -LiteralPath "$(GetNewProjectPath)" -Force -Recurse - Write-Host " OK" + Write-Log " OK" } -Write-Host -NoNewline "Creating directory for integration test: '$(GetNewProjectName)'" +Write-Log -NoNewline "Creating directory for integration test: '$(GetNewProjectName)'" New-Item -Path "$(ProjectRoot)/samples" -Name $(GetNewProjectName) -ItemType "directory" -Write-Host " OK" +Write-Log " OK" -Write-Host "Creating integration project:" +Write-Log "Creating integration project:" RunUnityCustom $UnityPath @("-batchmode", "-createProject", "$(GetNewProjectPath)", "-quit") -Write-Host "Copying Editor scripts to integration project:" +Write-Log "Copying Editor scripts to integration project:" New-Item -Path "$(GetNewProjectAssetsPath)" -Name "Editor" -ItemType "directory" Copy-Item -Recurse "$IntegrationScriptsPath/Editor/*" -Destination "$(GetNewProjectAssetsPath)/Editor/" ` -Exclude "BuildTimeOptions.cs" New-Item -Path "$(GetNewProjectAssetsPath)" -Name "Scenes" -ItemType "directory" Copy-Item -Recurse "$IntegrationScriptsPath/Scenes/*" -Destination "$(GetNewProjectAssetsPath)/Scenes/" -Write-Host " OK" +Write-Log " OK" # Update ProjectSettings $projectSettingsPath = "$(GetNewProjectPath)/ProjectSettings/ProjectSettings.asset" @@ -45,16 +47,16 @@ $projectSettings | Out-File $projectSettingsPath # Add Unity UI package to manifest.json if not already present # Creating a new project via command line doesn't include the Unity UI package by default while creating it via the Hub does. -Write-Host -NoNewline "Checking Unity UI package in manifest.json:" +Write-Log -NoNewline "Checking Unity UI package in manifest.json:" $manifestPath = "$(GetNewProjectPath)/Packages/manifest.json" $manifest = Get-Content $manifestPath | ConvertFrom-Json if (-not ($manifest.dependencies.PSObject.Properties.Name -contains "com.unity.ugui")) { - Write-Host " Adding Unity UI package" + Write-Log " Adding Unity UI package" $manifest.dependencies | Add-Member -MemberType NoteProperty -Name "com.unity.ugui" -Value "2.0.0" $manifest | ConvertTo-Json -Depth 10 | Out-File $manifestPath -Encoding utf8 } else { - Write-Host " Unity UI package already exists" + Write-Log " Unity UI package already exists" } -Write-Host "`nProject created!!" +Write-Log "`nProject created!!" diff --git a/test/Scripts.Integration.Test/extract-package.ps1 b/test/Scripts.Integration.Test/extract-package.ps1 index 2e137a11d..a78673983 100644 --- a/test/Scripts.Integration.Test/extract-package.ps1 +++ b/test/Scripts.Integration.Test/extract-package.ps1 @@ -3,25 +3,27 @@ if (-not $Global:NewProjectPathCache) . ./test/Scripts.Integration.Test/globals.ps1 } +. ./test/Scripts.Integration.Test/common.ps1 + # Check if SDK is packed. $packageFile = "package-release.zip" If (Test-Path -Path "$(ProjectRoot)/$packageFile" ) { - Write-Host "Found $packageFile" + Write-Log "Found $packageFile" } Else { Throw "$packageFile on $(ProjectRoot) but it was not found. Be sure you run ./scripts/pack.ps1" } -Write-Host -NoNewline "clearing $PackageReleaseOutput and Extracting $packageFile :" +Write-Log -NoNewline "clearing $PackageReleaseOutput and Extracting $packageFile :" if (Test-Path -Path "$PackageReleaseOutput") { Remove-Item -Path "$PackageReleaseOutput" -Recurse } Expand-Archive -LiteralPath "$(ProjectRoot)/$packageFile" -DestinationPath "$PackageReleaseOutput" -Write-Host "OK" +Write-Log "OK" If (-not(Test-Path -Path "$PackageReleaseOutput")) { diff --git a/test/Scripts.Integration.Test/run-smoke-test.ps1 b/test/Scripts.Integration.Test/run-smoke-test.ps1 index 8c4423efa..9b16d4aff 100644 --- a/test/Scripts.Integration.Test/run-smoke-test.ps1 +++ b/test/Scripts.Integration.Test/run-smoke-test.ps1 @@ -19,11 +19,11 @@ if (-not $Global:NewProjectPathCache) . $PSScriptRoot/common.ps1 -Write-Host "Given parameters:" -Write-Host " TestAppPath: $TestAppPath" -Write-Host " AppDataDir: $AppDataDir" -Write-Host " Smoke: $Smoke" -Write-Host " Crash: $Crash" +Write-Log "Given parameters:" +Write-Log " TestAppPath: $TestAppPath" +Write-Log " AppDataDir: $AppDataDir" +Write-Log " Smoke: $Smoke" +Write-Log " Crash: $Crash" If (!$Smoke -and !$Crash) { @@ -63,9 +63,9 @@ if ("$TestAppPath" -eq "") } } -Write-Host "Resolved parameters:" -Write-Host " TestAppPath: $TestAppPath" -Write-Host " AppDataDir: $AppDataDir" +Write-Log "Resolved parameters:" +Write-Log " TestAppPath: $TestAppPath" +Write-Log " AppDataDir: $AppDataDir" if ("$AppDataDir" -ne "") { @@ -89,12 +89,12 @@ function RunTest([string] $type) { if ($IsLinux -and "$env:XDG_CURRENT_DESKTOP" -eq "" -and (Get-Command "xvfb-run" -ErrorAction SilentlyContinue)) { - Write-Host "Running xvfb-run -ae /dev/stdout $TestAppPath --test $type" + Write-Log "Running xvfb-run -ae /dev/stdout $TestAppPath --test $type" $process = Start-Process "xvfb-run" -ArgumentList "-ae", "/dev/stdout", "$TestAppPath", "--test", $type -PassThru } else { - Write-Host "Running $TestAppPath --test $type" + Write-Log "Running $TestAppPath --test $type" $process = Start-Process "$TestAppPath" -ArgumentList "--test", $type -PassThru } @@ -110,18 +110,18 @@ function RunTest([string] $type) $appLog = "" if ("$AppDataDir" -ne "") { - Write-Host "$type test: Player.log contents:" -ForegroundColor Yellow + Write-Log "$type test: Player.log contents:" -ForegroundColor Yellow $appLog = Get-Content "$AppDataDir/Player.log" $appLog - Write-Host "================================================================================" -ForegroundColor Yellow - Write-Host "$type test: Player.log contents END" -ForegroundColor Yellow + Write-Log "================================================================================" -ForegroundColor Yellow + Write-Log "$type test: Player.log contents END" -ForegroundColor Yellow } - # Relying on ExitCode does not seem reliable. We're looking for the line "SmokeTester is quitting." instead to indicate + # Relying on ExitCode does not seem reliable. We're looking for the line "SmokeTester is quitting." instead to indicate # a successful shut-down. If ($appLog | Select-String "SmokeTester is quitting.") { - Write-Host "$type test: PASSED" -ForegroundColor Green + Write-Log "$type test: PASSED" -ForegroundColor Green } ElseIf ($timedOut) { @@ -136,7 +136,7 @@ function RunTest([string] $type) { throw $info } - Write-Host $info + Write-Log $info } } finally