Move tests to "test" directory. NFC. (#745)
This commit is contained in:
7
test/test.bat
Executable file
7
test/test.bat
Executable file
@@ -0,0 +1,7 @@
|
||||
:: equivilent of test.sh as windows bat file
|
||||
set PATH=%PATH%;%PYTHON_BIN%
|
||||
CALL emsdk install latest
|
||||
CALL emsdk activate latest
|
||||
CALL emsdk_env.bat
|
||||
CALL python -c "import sys; print(sys.executable)"
|
||||
CALL emcc.bat -v
|
||||
265
test/test.py
Executable file
265
test/test.py
Executable file
@@ -0,0 +1,265 @@
|
||||
#!/usr/bin/env python3
|
||||
import json
|
||||
import os
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
WINDOWS = sys.platform.startswith('win')
|
||||
MACOS = sys.platform == 'darwin'
|
||||
|
||||
assert 'EM_CONFIG' in os.environ, "emsdk should be activated before running this script"
|
||||
|
||||
# Remove the EM_CACHE environment variable. It interferes with testing since
|
||||
# it would otherwise be fixed for the duration of the script and we expect
|
||||
# "emsdk activate" to be able switch between SDKs during the running of this
|
||||
# script.
|
||||
del os.environ['EM_CACHE']
|
||||
|
||||
emconfig = os.environ['EM_CONFIG']
|
||||
upstream_emcc = os.path.join('upstream', 'emscripten', 'emcc')
|
||||
fastcomp_emcc = os.path.join('fastcomp', 'emscripten', 'emcc')
|
||||
emsdk = './emsdk'
|
||||
if WINDOWS:
|
||||
upstream_emcc += '.bat'
|
||||
fastcomp_emcc += '.bat'
|
||||
emsdk = 'emsdk.bat'
|
||||
else:
|
||||
emsdk = './emsdk'
|
||||
|
||||
# Utilities
|
||||
|
||||
|
||||
def listify(x):
|
||||
if type(x) == list or type(x) == tuple:
|
||||
return x
|
||||
return [x]
|
||||
|
||||
|
||||
def check_call(cmd, **args):
|
||||
if type(cmd) != list:
|
||||
cmd = cmd.split()
|
||||
print('running: %s' % cmd)
|
||||
args['universal_newlines'] = True
|
||||
subprocess.check_call(cmd, **args)
|
||||
|
||||
|
||||
def checked_call_with_output(cmd, expected=None, unexpected=None, stderr=None):
|
||||
cmd = cmd.split(' ')
|
||||
print('running: %s' % cmd)
|
||||
try:
|
||||
stdout = subprocess.check_output(cmd, stderr=stderr, universal_newlines=True)
|
||||
except subprocess.CalledProcessError as e:
|
||||
print(e.stderr)
|
||||
print(e.stdout)
|
||||
raise e
|
||||
|
||||
if expected:
|
||||
for x in listify(expected):
|
||||
assert x in stdout, 'call had the right output: ' + stdout + '\n[[[' + x + ']]]'
|
||||
if unexpected:
|
||||
for x in listify(unexpected):
|
||||
assert x not in stdout, 'call had the wrong output: ' + stdout + '\n[[[' + x + ']]]'
|
||||
|
||||
|
||||
def failing_call_with_output(cmd, expected):
|
||||
proc = subprocess.Popen(cmd.split(' '), stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)
|
||||
stdout, stderr = proc.communicate()
|
||||
if WINDOWS:
|
||||
print('warning: skipping part of failing_call_with_output() due to error codes not being propagated (see #592)')
|
||||
else:
|
||||
assert proc.returncode, 'call must have failed: ' + str([stdout, "\n========\n", stderr])
|
||||
assert expected in stdout or expected in stderr, 'call did not have the right output'
|
||||
|
||||
|
||||
def hack_emsdk(marker, replacement):
|
||||
with open('emsdk.py') as f:
|
||||
src = f.read()
|
||||
assert marker in src
|
||||
src = src.replace(marker, replacement)
|
||||
name = '__test_emsdk'
|
||||
with open(name, 'w') as f:
|
||||
f.write(src)
|
||||
return name
|
||||
|
||||
|
||||
# Set up
|
||||
|
||||
TAGS = json.loads(open('emscripten-releases-tags.txt').read())
|
||||
|
||||
# Tests
|
||||
|
||||
|
||||
def do_lib_building(emcc):
|
||||
cache_building_messages = ['generating system library: ']
|
||||
|
||||
def do_build(args, expected):
|
||||
if expected:
|
||||
expected = cache_building_messages
|
||||
unexpected = []
|
||||
else:
|
||||
expected = []
|
||||
unexpected = cache_building_messages
|
||||
checked_call_with_output(emcc + ' hello_world.c' + args,
|
||||
expected=expected,
|
||||
unexpected=unexpected,
|
||||
stderr=subprocess.STDOUT)
|
||||
|
||||
# The emsdk ships all system libraries so we don't expect to see any
|
||||
# cache population unless we explicly --clear-cache.
|
||||
do_build('', expected=False)
|
||||
check_call(emcc + ' --clear-cache')
|
||||
do_build(' -O2', expected=True)
|
||||
do_build(' -s WASM=0', expected=False)
|
||||
do_build(' -O2 -s WASM=0', expected=False)
|
||||
|
||||
|
||||
def run_emsdk(cmd):
|
||||
if type(cmd) != list:
|
||||
cmd = cmd.split()
|
||||
check_call([emsdk] + cmd)
|
||||
|
||||
|
||||
class Emsdk(unittest.TestCase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
with open('hello_world.c', 'w') as f:
|
||||
f.write('''\
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
printf("Hello, world!\\n");
|
||||
return 0;
|
||||
}
|
||||
''')
|
||||
|
||||
def setUp(self):
|
||||
run_emsdk('install latest')
|
||||
run_emsdk('activate latest')
|
||||
|
||||
def test_already_installed(self):
|
||||
# Test we don't re-download unnecessarily
|
||||
checked_call_with_output(emsdk + ' install latest', expected='already installed', unexpected='Downloading:')
|
||||
|
||||
def test_list(self):
|
||||
# Test we report installed tools properly. The latest version should be
|
||||
# installed, but not some random old one.
|
||||
checked_call_with_output(emsdk + ' list', expected=TAGS['latest'] + ' INSTALLED', unexpected='1.39.15 INSTALLED:')
|
||||
|
||||
def test_config_contents(self):
|
||||
print('test .emscripten contents')
|
||||
with open(emconfig) as f:
|
||||
config = f.read()
|
||||
assert 'fastcomp' not in config
|
||||
assert 'upstream' in config
|
||||
|
||||
def test_lib_building(self):
|
||||
print('building proper system libraries')
|
||||
do_lib_building(upstream_emcc)
|
||||
|
||||
def test_fastcomp(self):
|
||||
print('test the last fastcomp release')
|
||||
run_emsdk('install 1.40.1-fastcomp')
|
||||
run_emsdk('activate 1.40.1-fastcomp')
|
||||
|
||||
do_lib_building(fastcomp_emcc)
|
||||
with open(emconfig) as f:
|
||||
config = f.read()
|
||||
assert config.count('LLVM_ROOT') == 1
|
||||
assert 'upstream' not in config
|
||||
assert 'fastcomp' in config
|
||||
|
||||
print('verify latest fastcomp version is fixed at 1.40.1')
|
||||
checked_call_with_output(fastcomp_emcc + ' -v', '1.40.1', stderr=subprocess.STDOUT)
|
||||
|
||||
def test_fastcomp_missing(self):
|
||||
print('verify that attempting to use newer fastcomp gives an error')
|
||||
fastcomp_error = 'The fastcomp backend is not getting new builds or releases. Please use the upstream llvm backend or use an older version than 2.0.0 (such as 1.40.1).'
|
||||
failing_call_with_output(emsdk + ' install latest-fastcomp', fastcomp_error)
|
||||
failing_call_with_output(emsdk + ' install tot-fastcomp', fastcomp_error)
|
||||
failing_call_with_output(emsdk + ' install 2.0.0-fastcomp', fastcomp_error)
|
||||
|
||||
def test_redownload(self):
|
||||
print('go back to using upstream')
|
||||
run_emsdk('activate latest')
|
||||
|
||||
# Test the normal tools like node don't re-download on re-install
|
||||
print('another install must re-download')
|
||||
checked_call_with_output(emsdk + ' uninstall node-14.15.5-64bit')
|
||||
checked_call_with_output(emsdk + ' install node-14.15.5-64bit', expected='Downloading:', unexpected='already installed')
|
||||
checked_call_with_output(emsdk + ' install node-14.15.5-64bit', unexpected='Downloading:', expected='already installed')
|
||||
|
||||
def test_tot_upstream(self):
|
||||
print('test update-tags')
|
||||
run_emsdk('update-tags')
|
||||
print('test tot-upstream')
|
||||
run_emsdk('install tot-upstream')
|
||||
with open(emconfig) as f:
|
||||
config = f.read()
|
||||
run_emsdk('activate tot-upstream')
|
||||
with open(emconfig + '.old') as f:
|
||||
old_config = f.read()
|
||||
self.assertEqual(config, old_config)
|
||||
# TODO; test on latest as well
|
||||
check_call(upstream_emcc + ' hello_world.c')
|
||||
|
||||
def test_specific_old(self):
|
||||
print('test specific release (old, using sdk-* notation)')
|
||||
run_emsdk('install sdk-fastcomp-1.38.31-64bit')
|
||||
run_emsdk('activate sdk-fastcomp-1.38.31-64bit')
|
||||
|
||||
def test_specific_version(self):
|
||||
print('test specific release (new, short name)')
|
||||
run_emsdk('install 1.38.33')
|
||||
print('another install, but no need for re-download')
|
||||
checked_call_with_output(emsdk + ' install 1.38.33', expected='Skipped', unexpected='Downloading:')
|
||||
run_emsdk('activate 1.38.33')
|
||||
with open(emconfig) as f:
|
||||
config = f.read()
|
||||
assert 'upstream' not in config
|
||||
assert 'fastcomp' in config
|
||||
|
||||
def test_specific_version_full(self):
|
||||
print('test specific release (new, full name)')
|
||||
run_emsdk('install sdk-1.38.33-upstream-64bit')
|
||||
run_emsdk('activate sdk-1.38.33-upstream-64bit')
|
||||
print('test specific release (new, tag name)')
|
||||
run_emsdk('install sdk-tag-1.38.33-64bit')
|
||||
run_emsdk('activate sdk-tag-1.38.33-64bit')
|
||||
|
||||
def test_binaryen_from_source(self):
|
||||
print('test binaryen source build')
|
||||
run_emsdk(['install', '--build=Release', '--generator=Unix Makefiles', 'binaryen-master-64bit'])
|
||||
|
||||
def test_no_32bit(self):
|
||||
print('test 32-bit error')
|
||||
emsdk_hacked = hack_emsdk('not is_os_64bit()', 'True')
|
||||
failing_call_with_output('python %s install latest' % emsdk_hacked, 'this tool is only provided for 64-bit OSes')
|
||||
os.remove(emsdk_hacked)
|
||||
|
||||
def test_update_no_git(self):
|
||||
print('test non-git update')
|
||||
|
||||
temp_dir = tempfile.mkdtemp()
|
||||
for filename in os.listdir('.'):
|
||||
if not filename.startswith('.') and not os.path.isdir(filename):
|
||||
shutil.copy2(filename, os.path.join(temp_dir, filename))
|
||||
|
||||
os.chdir(temp_dir)
|
||||
run_emsdk('update')
|
||||
|
||||
print('second time')
|
||||
run_emsdk('update')
|
||||
|
||||
def test_install_arbitrary(self):
|
||||
# Test that its possible to install arbrary emscripten-releases SDKs
|
||||
run_emsdk('install sdk-releases-upstream-5c776e6a91c0cb8edafca16a652ee1ee48f4f6d2')
|
||||
|
||||
# Check that its not re-downloaded
|
||||
checked_call_with_output(emsdk + ' install sdk-releases-upstream-5c776e6a91c0cb8edafca16a652ee1ee48f4f6d2', expected='Skipped', unexpected='Downloading:')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main(verbosity=2)
|
||||
23
test/test.sh
Executable file
23
test/test.sh
Executable file
@@ -0,0 +1,23 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
echo "test the standard workflow (as close as possible to how a user would do it, in the shell)"
|
||||
|
||||
set -x
|
||||
set -e
|
||||
|
||||
# Test that arbitrary (non-released) versions can be installed and
|
||||
# activated.
|
||||
./emsdk install sdk-upstream-5c776e6a91c0cb8edafca16a652ee1ee48f4f6d2
|
||||
./emsdk activate sdk-upstream-5c776e6a91c0cb8edafca16a652ee1ee48f4f6d2
|
||||
source ./emsdk_env.sh
|
||||
which emcc
|
||||
emcc -v
|
||||
|
||||
./emsdk install latest
|
||||
./emsdk activate latest
|
||||
source ./emsdk_env.sh --build=Release
|
||||
# On mac and windows python3 should be in the path and point to the
|
||||
# bundled version.
|
||||
which python3
|
||||
which emcc
|
||||
emcc -v
|
||||
114
test/test_activation.ps1
Normal file
114
test/test_activation.ps1
Normal file
@@ -0,0 +1,114 @@
|
||||
# This test installs emsdk and activates the latest toolchain using `--system` or `--permanent` flags,
|
||||
# and checks if the environment variables and PATH are correctly updated. Set $env:SYSTEM_FLAG and $env:PERMANENT_FLAG to test each.
|
||||
# If no flag is provided the process/shell values are tested. See the CI file for an example.
|
||||
|
||||
refreshenv
|
||||
|
||||
$repo_root = [System.IO.Path]::GetDirectoryName((resolve-path "$PSScriptRoot"))
|
||||
|
||||
$PATH_USER_BEFORE = [System.Environment]::GetEnvironmentVariable("PATH", "User")
|
||||
$PATH_MACHINE_BEFORE = [System.Environment]::GetEnvironmentVariable("PATH", "Machine")
|
||||
$PATH_Process_BEFORE = [System.Environment]::GetEnvironmentVariable("PATH", "Process")
|
||||
|
||||
|
||||
try {
|
||||
|
||||
& "$repo_root/emsdk.ps1" install latest
|
||||
|
||||
$esc = '--%'
|
||||
& "$repo_root/emsdk.ps1" activate latest $esc $env:PERMANENT_FLAG $env:SYSTEM_FLAG
|
||||
|
||||
if ($env:SYSTEM_FLAG) {
|
||||
$env_type = "Machine"
|
||||
}
|
||||
elseif ($env:PERMANENT_FLAG) {
|
||||
$env_type = "User"
|
||||
} else {
|
||||
$env_type = "Process"
|
||||
}
|
||||
|
||||
$EMSDK = [System.Environment]::GetEnvironmentVariable("EMSDK", $env_type)
|
||||
$EM_CONFIG = [System.Environment]::GetEnvironmentVariable("EM_CONFIG", $env_type)
|
||||
$EMSDK_NODE = [System.Environment]::GetEnvironmentVariable("EMSDK_NODE", $env_type)
|
||||
$EMSDK_PYTHON = [System.Environment]::GetEnvironmentVariable("EMSDK_PYTHON", $env_type)
|
||||
$JAVA_HOME = [System.Environment]::GetEnvironmentVariable("JAVA_HOME", $env_type)
|
||||
$EM_CACHE = [System.Environment]::GetEnvironmentVariable("EM_CACHE", $env_type)
|
||||
$PATH = [System.Environment]::GetEnvironmentVariable("PATH", $env_type)
|
||||
|
||||
if (!$EMSDK) {
|
||||
throw "EMSDK is not set for the user"
|
||||
}
|
||||
if (!$EM_CONFIG) {
|
||||
throw "EM_CONFIG is not set for the user"
|
||||
}
|
||||
if (!$EMSDK_NODE) {
|
||||
throw "EMSDK_NODE is not set for the user"
|
||||
}
|
||||
if (!$JAVA_HOME) {
|
||||
throw "JAVA_HOME is not set for the user"
|
||||
}
|
||||
if (!$EMSDK_PYTHON) {
|
||||
throw "EMSDK_PYTHON is not set for the user"
|
||||
}
|
||||
if (!$EM_CACHE) {
|
||||
throw "EM_CACHE is not set for the user"
|
||||
}
|
||||
|
||||
|
||||
$path_split = $PATH.Split(';')
|
||||
|
||||
$EMSDK_Path = $path_split | Where-Object { $_ -like "$repo_root*" }
|
||||
if (!$EMSDK_Path) {
|
||||
throw "No path is added!"
|
||||
}
|
||||
$EMSDK_NODE_Path = $path_split | Where-Object { $_ -like "$repo_root\node*" }
|
||||
if (!$EMSDK_NODE_Path) {
|
||||
throw "$repo_root\\node is not added to path."
|
||||
}
|
||||
|
||||
$EMSDK_UPSTREAM_Path = $path_split | Where-Object { $_ -like "$repo_root\upstream\emscripten*" }
|
||||
if (!$EMSDK_UPSTREAM_Path) {
|
||||
throw "$repo_root\\upstream\emscripten is not added to path."
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
finally {
|
||||
# Recover pre-split PATH
|
||||
refreshenv
|
||||
|
||||
[Environment]::SetEnvironmentVariable("Path", $PATH_USER_BEFORE, "User")
|
||||
try {
|
||||
[Environment]::SetEnvironmentVariable("Path", $PATH_MACHINE_BEFORE, "Machine")
|
||||
}
|
||||
catch {}
|
||||
|
||||
[Environment]::SetEnvironmentVariable("Path", $PATH_Process_BEFORE, "Process")
|
||||
|
||||
# Recover pre activation env variables
|
||||
[Environment]::SetEnvironmentVariable("EMSDK", $null, "User")
|
||||
[Environment]::SetEnvironmentVariable("EM_CONFIG", $null, "User")
|
||||
[Environment]::SetEnvironmentVariable("EMSDK_NODE", $null, "User")
|
||||
[Environment]::SetEnvironmentVariable("EMSDK_PYTHON", $null, "User")
|
||||
[Environment]::SetEnvironmentVariable("JAVA_HOME", $null, "User")
|
||||
[Environment]::SetEnvironmentVariable("EM_CACHE", $null, "User")
|
||||
|
||||
try {
|
||||
[Environment]::SetEnvironmentVariable("EMSDK", $null, "Machine")
|
||||
[Environment]::SetEnvironmentVariable("EM_CONFIG", $null, "Machine")
|
||||
[Environment]::SetEnvironmentVariable("EMSDK_NODE", $null, "Machine")
|
||||
[Environment]::SetEnvironmentVariable("EMSDK_PYTHON", $null, "Machine")
|
||||
[Environment]::SetEnvironmentVariable("JAVA_HOME", $null, "Machine")
|
||||
[Environment]::SetEnvironmentVariable("EM_CACHE", $null, "Machine")
|
||||
} catch {}
|
||||
|
||||
|
||||
[Environment]::SetEnvironmentVariable("EMSDK", $null, "Process")
|
||||
[Environment]::SetEnvironmentVariable("EM_CONFIG", $null, "Process")
|
||||
[Environment]::SetEnvironmentVariable("EMSDK_NODE", $null, "Process")
|
||||
[Environment]::SetEnvironmentVariable("EMSDK_PYTHON", $null, "Process")
|
||||
[Environment]::SetEnvironmentVariable("JAVA_HOME", $null, "Process")
|
||||
[Environment]::SetEnvironmentVariable("EM_CACHE", $null, "Process")
|
||||
|
||||
refreshenv
|
||||
}
|
||||
25
test/test_bazel.sh
Executable file
25
test/test_bazel.sh
Executable file
@@ -0,0 +1,25 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
echo "test bazel"
|
||||
|
||||
set -x
|
||||
set -e
|
||||
|
||||
# Get the latest version number from emscripten-releases-tag.txt.
|
||||
VER=$(grep -oP '(?<=latest\": \")([\d\.]+)(?=\")' \
|
||||
emscripten-releases-tags.txt \
|
||||
| sed --expression "s/\./\\\./g")
|
||||
# Based on the latest version number, get the commit hash for that version.
|
||||
HASH=$(grep "${VER}" emscripten-releases-tags.txt \
|
||||
| grep -v latest \
|
||||
| cut -f4 -d\")
|
||||
|
||||
FAILMSG="!!! scripts/update_bazel_toolchain.sh needs to be run !!!"
|
||||
|
||||
# Ensure the WORKSPACE file is up to date with the latest version.
|
||||
grep ${VER} bazel/WORKSPACE || (echo ${FAILMSG} && false)
|
||||
grep ${HASH} bazel/WORKSPACE || (echo ${FAILMSG} && false)
|
||||
|
||||
cd bazel
|
||||
bazel build //hello-world:hello-world-wasm
|
||||
bazel build //hello-world:hello-world-wasm-simd
|
||||
151
test/test_path_preservation.ps1
Normal file
151
test/test_path_preservation.ps1
Normal file
@@ -0,0 +1,151 @@
|
||||
# This test installs emsdk and activates the latest toolchain using `--system` or `--permanent` flags,
|
||||
# and checks if parts of PATH are lost or overwritten. Set $env:SYSTEM_FLAG and $env:PERMANENT_FLAG to test each.
|
||||
# If no flag is provided the process/shell values are tested. See the CI file for an example.
|
||||
|
||||
refreshenv
|
||||
|
||||
$repo_root = [System.IO.Path]::GetDirectoryName((resolve-path "$PSScriptRoot"))
|
||||
|
||||
$PATH_USER_BEFORE = [System.Environment]::GetEnvironmentVariable("PATH", "User")
|
||||
$PATH_MACHINE_BEFORE = [System.Environment]::GetEnvironmentVariable("PATH", "Machine")
|
||||
$PATH_Process_BEFORE = [System.Environment]::GetEnvironmentVariable("PATH", "Process")
|
||||
|
||||
try {
|
||||
|
||||
|
||||
& "$repo_root/emsdk.ps1" install latest
|
||||
|
||||
$esc = '--%'
|
||||
& "$repo_root/emsdk.ps1" activate latest $esc $env:PERMANENT_FLAG $env:SYSTEM_FLAG
|
||||
|
||||
$PATH_USER = [System.Environment]::GetEnvironmentVariable("PATH", "User")
|
||||
$PATH_MACHINE = [System.Environment]::GetEnvironmentVariable("PATH", "Machine")
|
||||
$PATH_Process = [System.Environment]::GetEnvironmentVariable("PATH", "Process")
|
||||
|
||||
if ($env:SYSTEM_FLAG) {
|
||||
echo "--system test............................."
|
||||
$path_before_arr = $PATH_MACHINE_BEFORE.Split(';')
|
||||
$path_arr = $PATH_MACHINE.Split(';')
|
||||
}
|
||||
elseif ($env:PERMANENT_FLAG) {
|
||||
echo "--permanent test.........................."
|
||||
$path_before_arr = $PATH_USER_BEFORE.Split(';')
|
||||
$path_arr = $PATH_USER.Split(';')
|
||||
} else {
|
||||
echo "no flag test (shell/process).............."
|
||||
$path_before_arr = $PATH_Process_BEFORE.Split(';')
|
||||
$path_arr = $PATH_Process.Split(';')
|
||||
}
|
||||
|
||||
|
||||
$EMSDK_Path = $path_arr | Where-Object { $_ -like "$repo_root*" }
|
||||
$EMSDK_NODE_Path = $path_arr | Where-Object { $_ -like "$repo_root\node*" }
|
||||
$EMSDK_PYTHON_Path = $path_arr | Where-Object { $_ -like "$repo_root\python*" }
|
||||
$EMSDK_JAVA_Path = $path_arr | Where-Object { $_ -like "$repo_root\java*" }
|
||||
$EMSDK_UPSTREAM_Path = $path_arr | Where-Object { $_ -like "$repo_root\upstream\emscripten*" }
|
||||
|
||||
$number_of_items = $path_arr.count
|
||||
[System.Collections.ArrayList]$rest_of_path = @()
|
||||
Foreach ($item in $path_arr) {
|
||||
if (
|
||||
($item -like "$repo_root*") -or
|
||||
($item -like "$repo_root\node*") -or
|
||||
($item -like "$repo_root\python*") -or
|
||||
($item -like "$repo_root\java*") -or
|
||||
($item -like "$repo_root\upstream\emscripten*")
|
||||
) {
|
||||
echo "$item is on the PATH"
|
||||
}
|
||||
else {
|
||||
$rest_of_path.add($item) | Out-Null
|
||||
}
|
||||
}
|
||||
|
||||
# compare the PATHs before activation and after activation
|
||||
if (Compare-Object -ReferenceObject $path_before_arr -DifferenceObject $rest_of_path ) {
|
||||
echo "Old path is ............................."
|
||||
echo $path_before_arr
|
||||
echo "Current rest of path is ................."
|
||||
echo $rest_of_path
|
||||
throw "some parts of PATH are removed"
|
||||
}
|
||||
|
||||
# Compare the other untouched PATH
|
||||
if ($env:SYSTEM_FLAG) {
|
||||
if (Compare-Object -ReferenceObject $PATH_USER_BEFORE.Split(';') -DifferenceObject $PATH_USER.Split(';') ) {
|
||||
echo "Old user path is ...................."
|
||||
echo $PATH_USER_BEFORE
|
||||
echo "Current user path is ................"
|
||||
echo $PATH_USER
|
||||
throw "User PATH are changed while --system had been provided"
|
||||
}
|
||||
}
|
||||
elseif ($env:PERMANENT_FLAG) {
|
||||
if (Compare-Object -ReferenceObject $PATH_MACHINE_BEFORE.Split(';') -DifferenceObject $PATH_MACHINE.Split(';') ) {
|
||||
echo "Old machine path is.................."
|
||||
echo $PATH_MACHINE_BEFORE
|
||||
echo "Current machine path is.............."
|
||||
echo $PATH_MACHINE
|
||||
throw "MACHINE PATH are changed while --system was not provided"
|
||||
}
|
||||
} else {
|
||||
if (
|
||||
(Compare-Object -ReferenceObject $PATH_MACHINE_BEFORE.Split(';') -DifferenceObject $PATH_MACHINE.Split(';')) -or
|
||||
(Compare-Object -ReferenceObject $PATH_MACHINE_BEFORE.Split(';') -DifferenceObject $PATH_MACHINE.Split(';'))
|
||||
) {
|
||||
echo "Old machine path is.................."
|
||||
echo $PATH_MACHINE_BEFORE
|
||||
echo "Current machine path is.............."
|
||||
echo $PATH_MACHINE
|
||||
echo "Old user path is ...................."
|
||||
echo $PATH_USER_BEFORE
|
||||
echo "Current user path is ................"
|
||||
echo $PATH_USER
|
||||
throw "MACHINE/USER PATH are changed while no flag was provided"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
finally {
|
||||
# Recover pre-split PATH
|
||||
refreshenv
|
||||
|
||||
[Environment]::SetEnvironmentVariable("Path", $PATH_USER_BEFORE, "User")
|
||||
try {
|
||||
[Environment]::SetEnvironmentVariable("Path", $PATH_MACHINE_BEFORE, "Machine")
|
||||
}
|
||||
catch {}
|
||||
|
||||
[Environment]::SetEnvironmentVariable("Path", $PATH_Process_BEFORE, "Process")
|
||||
|
||||
# Recover pre activation env variables
|
||||
[Environment]::SetEnvironmentVariable("EMSDK", $null, "User")
|
||||
[Environment]::SetEnvironmentVariable("EM_CONFIG", $null, "User")
|
||||
[Environment]::SetEnvironmentVariable("EMSDK_NODE", $null, "User")
|
||||
[Environment]::SetEnvironmentVariable("EMSDK_PYTHON", $null, "User")
|
||||
[Environment]::SetEnvironmentVariable("JAVA_HOME", $null, "User")
|
||||
[Environment]::SetEnvironmentVariable("EM_CACHE", $null, "User")
|
||||
|
||||
try {
|
||||
[Environment]::SetEnvironmentVariable("EMSDK", $null, "Machine")
|
||||
[Environment]::SetEnvironmentVariable("EM_CONFIG", $null, "Machine")
|
||||
[Environment]::SetEnvironmentVariable("EMSDK_NODE", $null, "Machine")
|
||||
[Environment]::SetEnvironmentVariable("EMSDK_PYTHON", $null, "Machine")
|
||||
[Environment]::SetEnvironmentVariable("JAVA_HOME", $null, "Machine")
|
||||
[Environment]::SetEnvironmentVariable("EM_CACHE", $null, "Machine")
|
||||
} catch {}
|
||||
|
||||
|
||||
[Environment]::SetEnvironmentVariable("EMSDK", $null, "Process")
|
||||
[Environment]::SetEnvironmentVariable("EM_CONFIG", $null, "Process")
|
||||
[Environment]::SetEnvironmentVariable("EMSDK_NODE", $null, "Process")
|
||||
[Environment]::SetEnvironmentVariable("EMSDK_PYTHON", $null, "Process")
|
||||
[Environment]::SetEnvironmentVariable("JAVA_HOME", $null, "Process")
|
||||
[Environment]::SetEnvironmentVariable("EM_CACHE", $null, "Process")
|
||||
|
||||
refreshenv
|
||||
|
||||
}
|
||||
132
test/test_source_env.sh
Executable file
132
test/test_source_env.sh
Executable file
@@ -0,0 +1,132 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
echo "Test ability to source emsdk_env.sh in different shells"
|
||||
|
||||
if [ -n "$EMSDK" ]; then
|
||||
echo "EMSDK is already defined in this shell. Run tests in a shell without sourcing emsdk_env.sh first"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
DIR=$(dirname "$BASH_SOURCE")
|
||||
|
||||
# setup a symlink relative to the current dir
|
||||
REL_LINK_DIR="$DIR/tmp"
|
||||
if [ -d "$REL_LINK_DIR" ]; then
|
||||
rm -rf "$REL_LINK_DIR"
|
||||
fi
|
||||
echo "Creating links in $REL_LINK_DIR"
|
||||
mkdir -p "$REL_LINK_DIR"
|
||||
(cd $DIR/.. && ln -s `pwd` "$REL_LINK_DIR/emsdk")
|
||||
(cd $DIR/.. && ln -s `pwd`/emsdk_env.sh "$REL_LINK_DIR")
|
||||
|
||||
# setup a symlink in an absolute directory
|
||||
ABS_LINK_DIR="/tmp/emsdk_env_test"
|
||||
if [ -d "$ABS_LINK_DIR" ]; then
|
||||
rm -rf "$ABS_LINK_DIR"
|
||||
fi
|
||||
echo "Creating links in $ABS_LINK_DIR"
|
||||
mkdir -p "$ABS_LINK_DIR"
|
||||
(cd $DIR/.. && ln -s `pwd` "$ABS_LINK_DIR/emsdk")
|
||||
(cd $DIR/.. && ln -s `pwd`/emsdk_env.sh "$ABS_LINK_DIR")
|
||||
|
||||
PATH1="$DIR/../emsdk_env.sh"
|
||||
PATH2="$REL_LINK_DIR/emsdk/emsdk_env.sh"
|
||||
PATH3="$REL_LINK_DIR/emsdk_env.sh"
|
||||
PATH4="$ABS_LINK_DIR/emsdk/emsdk_env.sh"
|
||||
PATH5="$ABS_LINK_DIR/emsdk_env.sh"
|
||||
|
||||
assert_emcc() {
|
||||
current=$1
|
||||
cmd=$2
|
||||
value=$3
|
||||
if [ -z "$value" ] || [ "$value" == "false" ]; then
|
||||
echo "FAILED: $current"
|
||||
echo " unable to get EMSDK in $current using '$cmd'"
|
||||
else
|
||||
echo "SUCCESS: $current testing $cmd"
|
||||
echo " -> EMSDK = $value"
|
||||
fi
|
||||
}
|
||||
|
||||
test_bash() {
|
||||
value=$(bash --rcfile <(echo $1))
|
||||
assert_emcc bash "$1" "$value"
|
||||
}
|
||||
|
||||
test_zsh() {
|
||||
value=$(zsh -d -c "$1")
|
||||
assert_emcc zsh "$1" "$value"
|
||||
}
|
||||
|
||||
test_ksh() {
|
||||
value=$(ksh -c "$1")
|
||||
assert_emcc ksh "$1" "$value"
|
||||
}
|
||||
|
||||
it_tests_direct_path() {
|
||||
TEST_SCRIPT=". ${PATH1}"' >/dev/null 2>&1; if [ -n "$EMSDK" ]; then echo "$EMSDK"; else echo false; fi ; exit'
|
||||
test_bash "$TEST_SCRIPT"
|
||||
test_zsh "$TEST_SCRIPT"
|
||||
test_ksh "$TEST_SCRIPT"
|
||||
TEST_SCRIPT="source ${PATH1}"' >/dev/null 2>&1; if [ -n "$EMSDK" ]; then echo "$EMSDK"; else echo false; fi ; exit'
|
||||
test_bash "$TEST_SCRIPT"
|
||||
test_zsh "$TEST_SCRIPT"
|
||||
test_ksh "$TEST_SCRIPT"
|
||||
}
|
||||
|
||||
it_tests_via_relative_dir_symlink() {
|
||||
TEST_SCRIPT=". ${PATH2}"' >/dev/null 2>&1; if [ -n "$EMSDK" ]; then echo "$EMSDK"; else echo false; fi ; exit'
|
||||
test_bash "$TEST_SCRIPT"
|
||||
test_zsh "$TEST_SCRIPT"
|
||||
test_ksh "$TEST_SCRIPT"
|
||||
TEST_SCRIPT="source ${PATH2}"' >/dev/null 2>&1; if [ -n "$EMSDK" ]; then echo "$EMSDK"; else echo false; fi ; exit'
|
||||
test_bash "$TEST_SCRIPT"
|
||||
test_zsh "$TEST_SCRIPT"
|
||||
test_ksh "$TEST_SCRIPT"
|
||||
}
|
||||
|
||||
it_tests_via_relative_file_symlink() {
|
||||
TEST_SCRIPT=". ${PATH3}"' >/dev/null 2>&1; if [ -n "$EMSDK" ]; then echo "$EMSDK"; else echo false; fi ; exit'
|
||||
test_bash "$TEST_SCRIPT"
|
||||
test_zsh "$TEST_SCRIPT"
|
||||
test_ksh "$TEST_SCRIPT"
|
||||
TEST_SCRIPT="source ${PATH3}"' >/dev/null 2>&1; if [ -n "$EMSDK" ]; then echo "$EMSDK"; else echo false; fi ; exit'
|
||||
test_bash "$TEST_SCRIPT"
|
||||
test_zsh "$TEST_SCRIPT"
|
||||
test_ksh "$TEST_SCRIPT"
|
||||
}
|
||||
|
||||
it_tests_via_absolute_dir_symlink() {
|
||||
TEST_SCRIPT=". ${PATH4}"' >/dev/null 2>&1; if [ -n "$EMSDK" ]; then echo "$EMSDK"; else echo false; fi ; exit'
|
||||
test_bash "$TEST_SCRIPT"
|
||||
test_zsh "$TEST_SCRIPT"
|
||||
test_ksh "$TEST_SCRIPT"
|
||||
TEST_SCRIPT="source ${PATH4}"' >/dev/null 2>&1; if [ -n "$EMSDK" ]; then echo "$EMSDK"; else echo false; fi ; exit'
|
||||
test_bash "$TEST_SCRIPT"
|
||||
test_zsh "$TEST_SCRIPT"
|
||||
test_ksh "$TEST_SCRIPT"
|
||||
}
|
||||
|
||||
it_tests_via_absolute_file_symlink() {
|
||||
TEST_SCRIPT=". ${PATH5}"' >/dev/null 2>&1; if [ -n "$EMSDK" ]; then echo "$EMSDK"; else echo false; fi ; exit'
|
||||
test_bash "$TEST_SCRIPT"
|
||||
test_zsh "$TEST_SCRIPT"
|
||||
test_ksh "$TEST_SCRIPT"
|
||||
TEST_SCRIPT="source ${PATH5}"' >/dev/null 2>&1; if [ -n "$EMSDK" ]; then echo "$EMSDK"; else echo false; fi ; exit'
|
||||
test_bash "$TEST_SCRIPT"
|
||||
test_zsh "$TEST_SCRIPT"
|
||||
test_ksh "$TEST_SCRIPT"
|
||||
}
|
||||
|
||||
run_bash_tests() {
|
||||
it_tests_direct_path
|
||||
it_tests_via_relative_dir_symlink
|
||||
it_tests_via_relative_file_symlink
|
||||
it_tests_via_absolute_dir_symlink
|
||||
it_tests_via_absolute_file_symlink
|
||||
}
|
||||
|
||||
run_bash_tests
|
||||
|
||||
rm -rf $REL_LINK_DIR
|
||||
rm -rf $ABS_LINK_DIR
|
||||
Reference in New Issue
Block a user