master
ps1 58 lines 2.11 KB
Raw
1 <#
2 .SYNOPSIS
3 Copies linux unit tests to a given WSL distribution.
4 .PARAMETER WslTestDirPath
5 The absolute path to the location of the \wsl-build\test\linux directory.
6 .PARAMETER DistroName
7 The name of the WSL distribution to copy the unit tests inside of.
8 Defaults to "test_distro"
9 #>
10
11 param (
12 [Parameter( ValueFromPipeline = $true,
13 ValueFromPipelineByPropertyName = $true,
14 ParameterSetName = "WslTestDirPath",
15 HelpMessage = "Path to \wsl-build\test\linux\ location")]
16 [Parameter( ParameterSetName = "CopyTestAll ")]
17 [Alias('testpath')]
18 [string[]]$WslTestDirPath,
19 [Parameter( ValueFromPipeline = $true,
20 ValueFromPipelineByPropertyName = $true,
21 Mandatory = $false,
22 ParameterSetName = "DistroName",
23 HelpMessage = "Name of WSL distro to run tests in; defaults to test_distro")]
24 [Parameter( ParameterSetName = "CopyTestAll ")]
25 [Alias('distro')]
26 [string[]]$DistroName = 'test_distro'
27 )
28
29 Write-Output "WslTestDirPath: $WslTestDirPath"
30 Write-Output "DistroName: $DistroName"
31
32 $ErrorActionPreference = "Stop"
33 Set-StrictMode -Version Latest
34
35 function Run {
36 [CmdletBinding()]
37 param([ScriptBlock]$cmd)
38
39 Invoke-Command -ScriptBlock $cmd
40 if ($LastExitCode -ne 0) {
41 throw ("$cmd failed with exit code: " + $lastexitcode)
42 }
43 }
44
45 $DistroPath = "$env:LocalAppData\lxss"
46
47 Write-Output "Copying unit tests to $DistroPath\rootfs\data\test"
48
49 # get wslpath to unit tests
50 $WslUnitTestPath = Run { wsl.exe --exec wslpath "$WslTestDirPath\unit_tests" }
51
52 # set-up the folder structure for the tests and copy them into the linux distro
53 Run { wsl.exe --distribution $DistroName --user root --exec bash -c "umask 0; mkdir -p /data;" }
54 Run { wsl.exe --distribution $DistroName --user root --exec bash -c "umask 0; cp -r $WslUnitTestPath /data/test" }
55 Run { wsl.exe --distribution $DistroName --user root --exec bash -c "umask 0; mkdir -p /data/test/log; ls -la /data/test" }
56
57 # ensure that /etc/fstab exists for the unit tests that expect it
58 Run { wsl.exe --distribution $DistroName --user root --exec bash -c "( [ -e `"/etc/fstab`" ] || touch `"/etc/fstab`" )" }