├── .gitattributes ├── .gitignore ├── .travis.yml ├── CONTRIBUTING.md ├── LICENSE.txt ├── NuGet.config ├── README.md ├── appveyor.yml ├── build.cmd ├── build.sh ├── build ├── _push-dnvm-blob.shade └── _push-dnvm.shade ├── makefile.shade ├── src ├── dnvm.cmd ├── dnvm.ps1 └── dnvm.sh └── test ├── apps ├── README.md └── TestApp │ ├── Program.cs │ ├── TestApp.sln │ ├── TestApp.xproj │ └── project.json ├── ps1 ├── Run-Tests.ps1 ├── _Common.ps1 ├── _Execute-Tests.ps1 └── tests │ ├── Alias.Tests.ps1 │ ├── EntryPoint.Tests.ps1 │ ├── Install.Tests.ps1 │ ├── List.Tests.ps1 │ ├── RunAndExec.Tests.ps1 │ ├── Uninstall.Tests.ps1 │ └── Use.Tests.ps1 └── sh ├── chester ├── common.sh ├── run-tests.sh └── tests ├── alias ├── Alias parameters are case insensitive.sh ├── Alias values can be retrieved.sh ├── Aliases can be listed.sh ├── Aliases can be removed.sh ├── Aliases can be use-d.sh ├── Aliasing creates a new alias file.sh ├── Aliasing replaces existing alias.sh ├── after_all.sh └── before_all.sh ├── install ├── Installed runtime can run hello app.sh ├── Installing a runtime that exists does not report error.sh ├── Installing from nupkg unpacks nupkg as expected.sh ├── Installing global with local already installed does not install.sh ├── Installing latest with no arguments installs Mono CLR.sh ├── Installing puts selected runtime on PATH.sh ├── Installing runtime globally.sh ├── Installing with alias switch creates specified alias.sh ├── Installing with os specified gives correct defaults.sh ├── Installing with persistant switch creates default alias.sh └── after.sh ├── list ├── Listing displays friendly message when no runtimes found.sh ├── Listing displays global and local installed dnx.sh ├── Listing displays orphaned aliases.sh └── before_all.sh ├── run_exec ├── Executes the host or command for the specified alias.sh ├── Executes the host or command for the specified version.sh ├── after_all.sh └── before_all.sh ├── sourcing ├── Self-updating a sourced dnvm can display its non-standard location.sh ├── Sourcing the script adds DNX_HOME bin to path.sh ├── Sourcing the script adds the command.sh └── Sourcing the script twice does not add DNX_HOME bin to path twice.sh ├── uninstall └── Uninstalling removes dnx.sh └── use ├── Use-ing a non-existant alias produces an error.sh ├── Use-ing a non-existant version produces an error.sh ├── Use-ing a version puts the matching runtime on the PATH.sh ├── Use-ing an alias puts the matching runtime on the path.sh ├── Use-ing none clears runtime from the PATH.sh ├── after_all.sh └── before_all.sh /.gitattributes: -------------------------------------------------------------------------------- 1 | *.doc diff=astextplain 2 | *.DOC diff=astextplain 3 | *.docx diff=astextplain 4 | *.DOCX diff=astextplain 5 | *.dot diff=astextplain 6 | *.DOT diff=astextplain 7 | *.pdf diff=astextplain 8 | *.PDF diff=astextplain 9 | *.rtf diff=astextplain 10 | *.RTF diff=astextplain 11 | 12 | *.jpg binary 13 | *.png binary 14 | *.gif binary 15 | 16 | *.cs text=auto diff=csharp 17 | *.vb text=auto 18 | *.resx text=auto 19 | *.c text=auto 20 | *.cpp text=auto 21 | *.cxx text=auto 22 | *.h text=auto 23 | *.hxx text=auto 24 | *.py text=auto 25 | *.ps1 txt=auto 26 | *.rb text=auto 27 | *.java text=auto 28 | *.html text=auto 29 | *.htm text=auto 30 | *.css text=auto 31 | *.scss text=auto 32 | *.sass text=auto 33 | *.less text=auto 34 | *.js text=auto 35 | *.lisp text=auto 36 | *.clj text=auto 37 | *.sql text=auto 38 | *.php text=auto 39 | *.lua text=auto 40 | *.m text=auto 41 | *.asm text=auto 42 | *.erl text=auto 43 | *.fs text=auto 44 | *.fsx text=auto 45 | *.hs text=auto 46 | 47 | *.csproj text=auto 48 | *.vbproj text=auto 49 | *.fsproj text=auto 50 | *.dbproj text=auto 51 | *.sln text=auto eol=crlf 52 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Things related to tests 2 | .pester/ 3 | testwork/ 4 | .urchin* 5 | 6 | # Ignore the folder created when pushing to Home - It should be cleaned up by the task, but sometimes isn't. 7 | .pushdnvm/ 8 | 9 | # Ignore lock files 10 | project.lock.json 11 | 12 | [Oo]bj/ 13 | [Bb]in/ 14 | TestResults/ 15 | .nuget/ 16 | *.sln.ide/ 17 | _ReSharper.*/ 18 | packages/ 19 | artifacts/ 20 | PublishProfiles/ 21 | *.user 22 | *.suo 23 | *.cache 24 | *.docstates 25 | _ReSharper.* 26 | nuget.exe 27 | *net45.csproj 28 | *net451.csproj 29 | *k10.csproj 30 | *.psess 31 | *.vsp 32 | *.pidb 33 | *.userprefs 34 | *DS_Store 35 | *.ncrunchsolution 36 | *.*sdf 37 | *.ipch 38 | *.sln.ide 39 | 40 | # Vim files 41 | *.swp 42 | *.swo 43 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: csharp 2 | sudo: false 3 | mono: 4 | - 4.0.5 5 | addons: 6 | apt: 7 | packages: 8 | - zsh 9 | script: 10 | - ./build.sh verify -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | Contributing 2 | ====== 3 | 4 | Information on contributing to this repo is in the [Contributing Guide](https://github.com/aspnet/Home/blob/dev/CONTRIBUTING.md) in the Home repo. 5 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) .NET Foundation. All rights reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use 4 | these files except in compliance with the License. You may obtain a copy of the 5 | License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software distributed 10 | under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 11 | CONDITIONS OF ANY KIND, either express or implied. See the License for the 12 | specific language governing permissions and limitations under the License. 13 | -------------------------------------------------------------------------------- /NuGet.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | DNVM 2 | ==== 3 | 4 | ## This repository is obsolete and no longer used or maintained. 5 | 6 | 7 | DNX and DNVM have been replaced by the new .NET CLI. See: 8 | 9 | - http://dotnet.github.io/getting-started/ 10 | - http://github.com/dotnet/cli 11 | 12 | As a result, we're not accepting anymore changes to this project. Please file any new issues on http://github.com/dotnet/cli. 13 | -------------------------------------------------------------------------------- /appveyor.yml: -------------------------------------------------------------------------------- 1 | build_script: 2 | - build.cmd verify 3 | clone_depth: 1 4 | test: off 5 | deploy: off 6 | -------------------------------------------------------------------------------- /build.cmd: -------------------------------------------------------------------------------- 1 | @echo off 2 | cd %~dp0 3 | 4 | SETLOCAL 5 | SET NUGET_VERSION=latest 6 | SET CACHED_NUGET=%LocalAppData%\NuGet\nuget.%NUGET_VERSION%.exe 7 | SET BUILDCMD_KOREBUILD_VERSION= 8 | 9 | IF EXIST %CACHED_NUGET% goto copynuget 10 | echo Downloading latest version of NuGet.exe... 11 | IF NOT EXIST %LocalAppData%\NuGet md %LocalAppData%\NuGet 12 | @powershell -NoProfile -ExecutionPolicy unrestricted -Command "$ProgressPreference = 'SilentlyContinue'; Invoke-WebRequest 'https://dist.nuget.org/win-x86-commandline/%NUGET_VERSION%/nuget.exe' -OutFile '%CACHED_NUGET%'" 13 | 14 | :copynuget 15 | IF EXIST .nuget\nuget.exe goto restore 16 | md .nuget 17 | copy %CACHED_NUGET% .nuget\nuget.exe > nul 18 | 19 | :restore 20 | IF EXIST packages\Sake goto run 21 | IF "%BUILDCMD_KOREBUILD_VERSION%"=="" ( 22 | .nuget\nuget.exe install KoreBuild -ExcludeVersion -o packages -nocache -pre 23 | ) ELSE ( 24 | .nuget\nuget.exe install KoreBuild -version %BUILDCMD_KOREBUILD_VERSION% -ExcludeVersion -o packages -nocache -pre 25 | ) 26 | .nuget\NuGet.exe install Sake -ExcludeVersion -Source https://www.nuget.org/api/v2/ -Out packages 27 | 28 | :run 29 | packages\Sake\tools\Sake.exe -I packages\KoreBuild\build -I build -f makefile.shade %* 30 | -------------------------------------------------------------------------------- /build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | if test `uname` = Darwin; then 4 | cachedir=~/Library/Caches/KBuild 5 | else 6 | if [ -z $XDG_DATA_HOME ]; then 7 | cachedir=$HOME/.local/share 8 | else 9 | cachedir=$XDG_DATA_HOME; 10 | fi 11 | fi 12 | mkdir -p $cachedir 13 | nugetVersion=latest 14 | cachePath=$cachedir/nuget.$nugetVersion.exe 15 | 16 | url=https://dist.nuget.org/win-x86-commandline/$nugetVersion/nuget.exe 17 | 18 | if test ! -f $cachePath; then 19 | wget -O $cachePath $url 2>/dev/null || curl -o $cachePath --location $url /dev/null 20 | fi 21 | 22 | if test ! -e .nuget; then 23 | mkdir .nuget 24 | cp $cachePath .nuget/nuget.exe 25 | fi 26 | 27 | if test ! -d packages/Sake; then 28 | mono .nuget/nuget.exe install KoreBuild -ExcludeVersion -o packages -nocache -pre 29 | mono .nuget/nuget.exe install Sake -ExcludeVersion -Source https://www.nuget.org/api/v2/ -Out packages 30 | fi 31 | 32 | mono packages/Sake/tools/Sake.exe -I packages/KoreBuild/build -I build -f makefile.shade "$@" 33 | -------------------------------------------------------------------------------- /build/_push-dnvm-blob.shade: -------------------------------------------------------------------------------- 1 | use assembly="System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" 2 | 3 | use namespace='System' 4 | use namespace='System.IO' 5 | use namespace='System.Net.Http' 6 | 7 | @{ 8 | var queryString = new Uri(container).Query; 9 | var baseAddress = container.Substring(0, container.IndexOf('?')) + "/"; 10 | 11 | var client = new HttpClient() 12 | { 13 | BaseAddress = new Uri(baseAddress) 14 | }; 15 | 16 | foreach (string filePath in files.Split(";".ToCharArray())) 17 | { 18 | var req = new HttpRequestMessage(); 19 | var fileName = Path.GetFileName(filePath); 20 | var stream = File.OpenRead(filePath); 21 | 22 | req.Headers.Add("x-ms-blob-type", "BlockBlob"); 23 | req.Content = new StreamContent(stream); 24 | req.RequestUri = new Uri(client.BaseAddress + fileName + queryString); 25 | req.Method = HttpMethod.Put; 26 | 27 | var result = client.SendAsync(req).Result; 28 | Log.Info("Copying " + fileName + " to " + client.BaseAddress + fileName); 29 | result.EnsureSuccessStatusCode(); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /build/_push-dnvm.shade: -------------------------------------------------------------------------------- 1 | default repo="https://github.com/aspnet/Home" 2 | default branch="dev" 3 | default workdir="${Path.Combine(Directory.GetCurrentDirectory(), ".pushdnvm")}" 4 | default author="ASP.NET Push Bot " 5 | 6 | default sourceRepoUrl="${Environment.GetEnvironmentVariable("REPO_URL")}" 7 | 8 | -// Borrowing commit message style from atom: https://github.com/atom/atom/blob/master/CONTRIBUTING.md#git-commit-messages 9 | default baseMessage=":arrow_up: dnvm" 10 | 11 | 12 | -// Clean up the checkout directory if it's still here from last time 13 | -// Need to use robocopy-delete because of git's permissions 14 | robocopy-delete dir="${workdir}" if="Directory.Exists(workdir)" 15 | 16 | -// Figure out the current commit hash and GitHub info 17 | @{ 18 | var psi = new ProcessStartInfo { 19 | UseShellExecute = false, 20 | RedirectStandardOutput = true, 21 | WorkingDirectory = Directory.GetCurrentDirectory(), 22 | FileName = "git", 23 | Arguments = "rev-parse HEAD" 24 | }; 25 | 26 | var p = Process.Start(psi); 27 | var commit = p.StandardOutput.ReadToEnd().Trim(); 28 | p.WaitForExit(); 29 | if (p.ExitCode != 0) 30 | { 31 | throw new Exception(string.Format("Exit code {0} from git", p.ExitCode)); 32 | } 33 | 34 | var sourceMessage = String.Empty; 35 | if(!String.IsNullOrEmpty(commit)) { 36 | sourceMessage = "Source: dnvm commit " + commit; 37 | if(!String.IsNullOrEmpty(sourceRepoUrl)) { 38 | var ghMatch = Regex.Match(sourceRepoUrl, @"git@github.com:(?[^/]+)/(?[^\.]+)(\.git)?"); 39 | if(!ghMatch.Success) { 40 | ghMatch = Regex.Match(sourceRepoUrl, @"https?://(www\.)?github\.com/(?[^/]+)/(?.+)"); 41 | } 42 | if(ghMatch.Success) { 43 | // It's GitHub! Extract the data to create fancy markdowny links and make one 44 | sourceMessage = "Source: " + ghMatch.Groups["owner"].Value + "/" + ghMatch.Groups["repo"].Value + "@" + commit; 45 | } 46 | } 47 | } 48 | } 49 | 50 | -// Clone the Home repository into the temp directory 51 | git gitCommand='clone ${repo} ${workdir} --branch="${branch}"' 52 | 53 | @{ 54 | // Copy the file across 55 | // Spark tries to be too helpful and converts ' to ", 56 | // so there's no way to get a Char literal, hence the ToCharArray weirdness 57 | foreach(var file in files.Split(";".ToCharArray())) 58 | { 59 | var dest = Path.Combine(workdir, Path.GetFileName(file)); 60 | Log.Info("Copying " + file + " to " + dest); 61 | File.Copy( 62 | sourceFileName: file, 63 | destFileName: dest, 64 | overwrite: true); 65 | } 66 | } 67 | 68 | -// Add everything! (":/" refers to the repo root, "-A" is add all recursively) 69 | git gitCommand='add -A :/' gitFolder='${workdir}' 70 | 71 | @{ 72 | // We don't want a failure to fail the build, just to complete this task 73 | psi = new ProcessStartInfo { 74 | UseShellExecute = false, 75 | WorkingDirectory = workdir, 76 | FileName = "git", 77 | 78 | // Multiple '-m' parameters to commit are added as separate paragraphs, so no need for newline escaping! Nice feature :) 79 | Arguments = "commit -q --author=\"" + author + "\" -m\"" + baseMessage + "\" -m\"" + sourceMessage + "\"" 80 | }; 81 | 82 | p = Process.Start(psi); 83 | p.WaitForExit(); 84 | bool doPush = p.ExitCode == 0; 85 | if(!doPush) { 86 | Log.Info("No changes to dnvm detected, so nothing to push."); 87 | } 88 | } 89 | 90 | git gitCommand='push -q ${repo} ${branch}:${branch}' gitFolder='${workdir}' if='doPush' 91 | 92 | -// Clean up! 93 | robocopy-delete dir="${workdir}" if="Directory.Exists(workdir)" 94 | -------------------------------------------------------------------------------- /makefile.shade: -------------------------------------------------------------------------------- 1 | use import="Files" 2 | use import="BuildEnv" 3 | use import="Environment" 4 | 5 | var PRODUCT_VERSION = '1.0.0' 6 | var AUTHORS='Microsoft Open Technologies, Inc.' 7 | 8 | use-standard-lifecycle 9 | use-teamcity 10 | 11 | default BASE_DIR='${Directory.GetCurrentDirectory()}' 12 | default TARGET_DIR='${Path.Combine(BASE_DIR, "artifacts")}' 13 | default SOURCE_DIR='${Path.Combine(BASE_DIR, "src")}' 14 | default BUILD_DIR='${Path.Combine(BASE_DIR, "build")}' 15 | default TEST_DIR='${Path.Combine(BASE_DIR, "test")}' 16 | default Configuration='${GetEnvironmentVariable("Configuration")}' 17 | 18 | @{ 19 | if (string.IsNullOrEmpty(GetEnvironmentVariable("DNX_BUILD_VERSION"))) 20 | { 21 | SetEnvironmentVariable("DNX_BUILD_VERSION", BuildNumber); 22 | } 23 | if (string.IsNullOrEmpty(GetEnvironmentVariable("K_AUTHOR"))) 24 | { 25 | SetEnvironmentVariable("K_AUTHOR", AUTHORS); 26 | } 27 | if (string.IsNullOrEmpty(Configuration)) 28 | { 29 | Configuration = "Debug"; 30 | SetEnvironmentVariable("Configuration", Configuration); 31 | } 32 | } 33 | 34 | default DEPLOY_DNVM="${Environment.GetEnvironmentVariable("DEPLOY_DNVM")}" 35 | default DNVM_DEPLOY_REPO="${Environment.GetEnvironmentVariable("DNVM_DEPLOY_REPO")}" 36 | default DNVM_DEPLOY_BRANCH="${Environment.GetEnvironmentVariable("DNVM_DEPLOY_BRANCH")}" 37 | default DNVM_DEPLOY_CONTAINER="${Environment.GetEnvironmentVariable("DNVM_DEPLOY_CONTAINER")}" 38 | 39 | #copy-dnvm target='compile' 40 | copy sourceDir='${SOURCE_DIR}' outputDir='${TARGET_DIR}' include='*.*' overwrite='${true}' 41 | 42 | update-file updateFile='${Path.Combine(TARGET_DIR, "dnvm.ps1")}' @{ 43 | updateText = updateText 44 | .Replace("{{BUILD_VERSION}}", Environment.GetEnvironmentVariable("DNX_BUILD_VERSION")) 45 | .Replace("{{AUTHORS}}", AUTHORS); 46 | } 47 | 48 | update-file updateFile='${Path.Combine(TARGET_DIR, "dnvm.sh")}' @{ 49 | updateText = updateText 50 | .Replace("{{BUILD_VERSION}}", Environment.GetEnvironmentVariable("DNX_BUILD_VERSION")) 51 | .Replace("{{AUTHORS}}", AUTHORS); 52 | } 53 | 54 | #run-ps1-tests target='test' if='!IsLinux' 55 | exec program='powershell' commandline='-ExecutionPolicy RemoteSigned -NoProfile -NoLogo -Command & "${Path.Combine(TEST_DIR, "ps1", "Run-Tests.ps1")} ${IsTeamCity?"-TeamCity":""}' 56 | 57 | #run-sh-tests target='test' if='IsLinux' 58 | exec program='/bin/bash' commandline="${Path.Combine(TEST_DIR, "sh", "run-tests.sh")} ${IsTeamCity?"-t ":""}-v" workingdir="${Path.Combine(TEST_DIR, "sh")}" 59 | 60 | #push-dnvm target='deploy' if='DEPLOY_DNVM == "1" && !String.IsNullOrEmpty(DNVM_DEPLOY_REPO) && !String.IsNullOrEmpty(DNVM_DEPLOY_BRANCH)' 61 | push-dnvm repo="${DNVM_DEPLOY_REPO}" branch="${DNVM_DEPLOY_BRANCH}" files="${Path.Combine(TARGET_DIR, "dnvm.cmd")};${Path.Combine(TARGET_DIR, "dnvm.ps1")};${Path.Combine(TARGET_DIR, "dnvm.sh")}" baseMessage=":arrow_up: dnvm.ps1, dnvm.cmd, dnvm.sh" 62 | 63 | #push-dnvm-blob target='deploy' if='DEPLOY_DNVM == "1" && !String.IsNullOrEmpty(DNVM_DEPLOY_CONTAINER)' 64 | push-dnvm-blob container="${DNVM_DEPLOY_CONTAINER}" files="${Path.Combine(TARGET_DIR, "dnvm.cmd")};${Path.Combine(TARGET_DIR, "dnvm.ps1")};${Path.Combine(TARGET_DIR, "dnvm.sh")}" 65 | 66 | functions @{ 67 | private static bool Quiet { get; set; } 68 | 69 | string GetEnvironmentVariable(string key) { return Environment.GetEnvironmentVariable(key); } 70 | void SetEnvironmentVariable(string key, string value) { Environment.SetEnvironmentVariable(key, value); } 71 | } 72 | -------------------------------------------------------------------------------- /src/dnvm.cmd: -------------------------------------------------------------------------------- 1 | @Echo off 2 | 3 | for /f "delims=" %%i in ('PowerShell -NoProfile -NoLogo -ExecutionPolicy unrestricted -Command "[System.IO.Path]::GetTempFileName()"') do set DNVM_CMD_PATH_FILE="%%i.cmd" 4 | 5 | PowerShell -NoProfile -NoLogo -ExecutionPolicy unrestricted -Command "[System.Threading.Thread]::CurrentThread.CurrentCulture = ''; [System.Threading.Thread]::CurrentThread.CurrentUICulture = '';$CmdPathFile='%DNVM_CMD_PATH_FILE%';& '%~dp0dnvm.ps1' %*" 6 | 7 | IF EXIST %DNVM_CMD_PATH_FILE% ( 8 | CALL %DNVM_CMD_PATH_FILE% 9 | DEL %DNVM_CMD_PATH_FILE% 10 | ) 11 | -------------------------------------------------------------------------------- /src/dnvm.sh: -------------------------------------------------------------------------------- 1 | # dnvm.sh 2 | # Source this file from your .bash-profile or script to use 3 | 4 | # "Constants" 5 | _DNVM_BUILDNUMBER="{{BUILD_VERSION}}" 6 | _DNVM_AUTHORS="{{AUTHORS}}" 7 | _DNVM_RUNTIME_PACKAGE_NAME="dnx" 8 | _DNVM_RUNTIME_FRIENDLY_NAME=".NET Execution Environment" 9 | _DNVM_RUNTIME_SHORT_NAME="DNX" 10 | _DNVM_RUNTIME_FOLDER_NAME=".dnx" 11 | _DNVM_COMMAND_NAME="dnvm" 12 | _DNVM_PACKAGE_MANAGER_NAME="dnu" 13 | _DNVM_VERSION_MANAGER_NAME=".NET Version Manager" 14 | _DNVM_DEFAULT_FEED="https://www.nuget.org/api/v2" 15 | _DNVM_DEFAULT_UNSTABLE_FEED="https://www.myget.org/F/aspnetvnext/api/v2" 16 | _DNVM_UPDATE_LOCATION="https://raw.githubusercontent.com/aspnet/Home/dev/dnvm.sh" 17 | 18 | if [ "$NO_COLOR" != "1" ]; then 19 | # ANSI Colors 20 | RCol='\e[0m' # Text Reset 21 | 22 | # Regular Bold Underline High Intensity BoldHigh Intens Background High Intensity Backgrounds 23 | Bla='\e[0;30m'; BBla='\e[1;30m'; UBla='\e[4;30m'; IBla='\e[0;90m'; BIBla='\e[1;90m'; On_Bla='\e[40m'; On_IBla='\e[0;100m'; 24 | Red='\e[0;31m'; BRed='\e[1;31m'; URed='\e[4;31m'; IRed='\e[0;91m'; BIRed='\e[1;91m'; On_Red='\e[41m'; On_IRed='\e[0;101m'; 25 | Gre='\e[0;32m'; BGre='\e[1;32m'; UGre='\e[4;32m'; IGre='\e[0;92m'; BIGre='\e[1;92m'; On_Gre='\e[42m'; On_IGre='\e[0;102m'; 26 | Yel='\e[0;33m'; BYel='\e[1;33m'; UYel='\e[4;33m'; IYel='\e[0;93m'; BIYel='\e[1;93m'; On_Yel='\e[43m'; On_IYel='\e[0;103m'; 27 | Blu='\e[0;34m'; BBlu='\e[1;34m'; UBlu='\e[4;34m'; IBlu='\e[0;94m'; BIBlu='\e[1;94m'; On_Blu='\e[44m'; On_IBlu='\e[0;104m'; 28 | Pur='\e[0;35m'; BPur='\e[1;35m'; UPur='\e[4;35m'; IPur='\e[0;95m'; BIPur='\e[1;95m'; On_Pur='\e[45m'; On_IPur='\e[0;105m'; 29 | Cya='\e[0;36m'; BCya='\e[1;36m'; UCya='\e[4;36m'; ICya='\e[0;96m'; BICya='\e[1;96m'; On_Cya='\e[46m'; On_ICya='\e[0;106m'; 30 | Whi='\e[0;37m'; BWhi='\e[1;37m'; UWhi='\e[4;37m'; IWhi='\e[0;97m'; BIWhi='\e[1;97m'; On_Whi='\e[47m'; On_IWhi='\e[0;107m'; 31 | fi 32 | 33 | 34 | [[ "$_DNVM_BUILDNUMBER" = {{* ]] && _DNVM_BUILDNUMBER="HEAD" 35 | 36 | __dnvm_has() { 37 | type "$1" > /dev/null 2>&1 38 | return $? 39 | } 40 | 41 | __dnvm_to_lower() { 42 | echo "$1" | tr '[:upper:]' '[:lower:]' 43 | } 44 | 45 | if __dnvm_has "unsetopt"; then 46 | unsetopt nomatch 2>/dev/null 47 | fi 48 | 49 | if [ -z "$DNX_USER_HOME" ]; then 50 | eval DNX_USER_HOME="~/$_DNVM_RUNTIME_FOLDER_NAME" 51 | fi 52 | 53 | if [ -z "$DNX_GLOBAL_HOME" ]; then 54 | eval DNX_GLOBAL_HOME="/usr/local/lib/dnx" 55 | fi 56 | 57 | if [ -z "$DNX_HOME" ]; then 58 | # Set to the user home value 59 | eval DNX_HOME="$DNX_USER_HOME:$DNX_GLOBAL_HOME" 60 | elif [[ $DNX_HOME != *"$DNX_GLOBAL_HOME"* ]]; then 61 | eval DNX_HOME="$DNX_HOME:$DNX_GLOBAL_HOME" 62 | fi 63 | 64 | _DNVM_USER_PACKAGES="$DNX_USER_HOME/runtimes" 65 | _DNVM_GLOBAL_PACKAGES="$DNX_GLOBAL_HOME/runtimes" 66 | _DNVM_ALIAS_DIR="$DNX_USER_HOME/alias" 67 | _DNVM_DNVM_DIR="$DNX_USER_HOME/dnvm" 68 | 69 | DNX_ACTIVE_FEED="" 70 | 71 | __dnvm_current_os() 72 | { 73 | local uname=$(uname) 74 | if [[ $uname == "Darwin" ]]; then 75 | echo "darwin" 76 | else 77 | echo "linux" 78 | fi 79 | } 80 | 81 | __dnvm_os_runtime_defaults() 82 | { 83 | local os=$1 84 | 85 | if [[ $os == "win" ]]; then 86 | echo "clr" 87 | elif [[ $os == "linux" ]]; then 88 | echo "mono" 89 | elif [[ $os == "darwin" ]]; then 90 | echo "mono" 91 | else 92 | echo "unknown os" 93 | fi 94 | } 95 | 96 | __dnvm_runtime_bitness_defaults() 97 | { 98 | local runtime=$1 99 | if [[ $runtime == "clr" ]]; then 100 | echo "x86" 101 | elif [[ $runtime == "coreclr" ]]; then 102 | echo "x64" 103 | else 104 | echo "unknown runtime" 105 | fi 106 | } 107 | 108 | __dnvm_query_feed() { 109 | local url=$1 110 | xml="$(curl $url 2>/dev/null)" 111 | echo $xml | grep \<[a-zA-Z]:Version\>* >> /dev/null || return 1 112 | version="$(echo $xml | sed 's/.*<[a-zA-Z]:Version>\([^<]*\).*/\1/')" 113 | downloadUrl="$(echo $xml | sed 's/.*&2; 124 | return 1 125 | fi 126 | 127 | if [[ $platform == "mono" ]]; then 128 | #dnx-mono 129 | local packageId="$_DNVM_RUNTIME_PACKAGE_NAME-$platform" 130 | else 131 | #dnx-coreclr-linux-x64 132 | local packageId="$_DNVM_RUNTIME_PACKAGE_NAME-$platform-$os-$arch" 133 | fi 134 | 135 | local url="$DNX_ACTIVE_FEED/GetUpdates()?packageIds=%27$packageId%27&versions=%270.0%27&includePrerelease=true&includeAllVersions=false" 136 | __dnvm_query_feed $url 137 | return $? 138 | } 139 | 140 | __dnvm_find_package() { 141 | local platform=$1 142 | local arch=$2 143 | local os=$3 144 | local version=$4 145 | 146 | if [[ $platform == "mono" ]]; then 147 | #dnx-mono 148 | local packageId="$_DNVM_RUNTIME_PACKAGE_NAME-$platform" 149 | else 150 | #dnx-coreclr-linux-x64 151 | local packageId="$_DNVM_RUNTIME_PACKAGE_NAME-$platform-$os-$arch" 152 | fi 153 | 154 | local url="$DNX_ACTIVE_FEED/Packages()?\$filter=Id%20eq%27$packageId%27%20and%20Version%20eq%20%27$version%27" 155 | __dnvm_query_feed $url 156 | return $? 157 | } 158 | 159 | __dnvm_strip_path() { 160 | echo "$1" | sed -e "s#$_DNVM_USER_PACKAGES/[^/]*$2[^:]*:##g" -e "s#:$_DNVM_USER_PACKAGES/[^/]*$2[^:]*##g" -e "s#$_DNVM_USER_PACKAGES/[^/]*$2[^:]*##g" | sed -e "s#$_DNVM_GLOBAL_PACKAGES/[^/]*$2[^:]*:##g" -e "s#:$_DNVM_GLOBAL_PACKAGES/[^/]*$2[^:]*##g" -e "s#$_DNVM_GLOBAL_PACKAGES/[^/]*$2[^:]*##g" 161 | } 162 | 163 | __dnvm_prepend_path() { 164 | if [ -z "$1" ]; then 165 | echo "$2" 166 | else 167 | echo "$2:$1" 168 | fi 169 | } 170 | 171 | __dnvm_package_version() { 172 | local runtimeFullName="$1" 173 | echo "$runtimeFullName" | sed "s/[^.]*.\(.*\)/\1/" 174 | } 175 | 176 | __dnvm_package_name() { 177 | local runtimeFullName="$1" 178 | echo "$runtimeFullName" | sed "s/\([^.]*\).*/\1/" 179 | } 180 | 181 | __dnvm_package_runtime() { 182 | local runtimeFullName="$1" 183 | echo "$runtimeFullName" | sed "s/$_DNVM_RUNTIME_PACKAGE_NAME-\([^.-]*\).*/\1/" 184 | } 185 | 186 | __dnvm_package_arch() { 187 | local runtimeFullName="$1" 188 | if [[ "$runtimeFullName" =~ $_DNVM_RUNTIME_PACKAGE_NAME-[^-.]*-[^-.]*-[^-.]*\..* ]]; 189 | then 190 | echo "$runtimeFullName" | sed "s/$_DNVM_RUNTIME_PACKAGE_NAME-[^-.]*-[^-.]*-\([^-.]*\)\..*/\1/" 191 | fi 192 | } 193 | 194 | __dnvm_package_os() { 195 | local runtimeFullName="$1" 196 | if [[ "$runtimeFullName" =~ "mono" ]]; then 197 | echo "linux/osx" 198 | else 199 | echo "$runtimeFullName" | sed "s/$_DNVM_RUNTIME_PACKAGE_NAME-[^-.]*-\([^.-]*\).*/\1/" 200 | fi 201 | } 202 | 203 | __dnvm_update_self() { 204 | local dnvmFileLocation="$_DNVM_DNVM_DIR/dnvm.sh" 205 | if [ ! -e $dnvmFileLocation ]; then 206 | local formattedDnvmFileLocation=`(echo $dnvmFileLocation | sed s=$HOME=~=g)` 207 | local formattedDnvmHome=`(echo $_DNVM_DNVM_DIR | sed s=$HOME=~=g)` 208 | local bashSourceLocation=${BASH_SOURCE} 209 | local scriptLocation=$bashSourceLocation 210 | if [ -z "${bashSourceLocation}" ]; then 211 | local scriptLocation=${(%):-%x} 212 | fi 213 | printf "%b\n" "${Red}$formattedDnvmFileLocation doesn't exist. This command assumes you have installed dnvm in the usual location and are trying to update it. If you want to use update-self then dnvm.sh should be sourced from $formattedDnvmHome. dnvm is currently sourced from $scriptLocation ${RCol}" 214 | return 1 215 | fi 216 | printf "%b\n" "${Cya}Downloading dnvm.sh from $_DNVM_UPDATE_LOCATION ${RCol}" 217 | local httpResult=$(curl -L -D - "$_DNVM_UPDATE_LOCATION" -o "$dnvmFileLocation" -# | grep "^HTTP/1.1" | head -n 1 | sed "s/HTTP.1.1 \([0-9]*\).*/\1/") 218 | 219 | [[ $httpResult == "404" ]] &&printf "%b\n" "${Red}404. Unable to download DNVM from $_DNVM_UPDATE_LOCATION ${RCol}" && return 1 220 | [[ $httpResult != "302" && $httpResult != "200" ]] && echo "${Red}HTTP Error $httpResult fetching DNVM from $_DNVM_UPDATE_LOCATION ${RCol}" && return 1 221 | 222 | source "$dnvmFileLocation" 223 | } 224 | 225 | __dnvm_promptSudo() { 226 | local acceptSudo="$1" 227 | local sudoMsg="$2" 228 | 229 | local answer= 230 | if [ "$acceptSudo" == "0" ]; then 231 | echo $2 232 | read -p "You may be prompted for your password via 'sudo' during this process. Is this Ok? (y/N) " answer 233 | else 234 | answer="y" 235 | fi 236 | if echo $answer | grep -iq "^y" ; then 237 | return 1 238 | else 239 | return 0 240 | fi 241 | } 242 | 243 | __dnvm_download() { 244 | local runtimeFullName="$1" 245 | local downloadUrl="$2" 246 | local runtimeFolder="$3" 247 | local force="$4" 248 | local acceptSudo="$5" 249 | 250 | local pkgName=$(__dnvm_package_name "$runtimeFullName") 251 | local pkgVersion=$(__dnvm_package_version "$runtimeFullName") 252 | local runtimeFile="$runtimeFolder/$runtimeFullName.nupkg" 253 | 254 | if [ -n "$force" ]; then 255 | printf "%b\n" "${Yel}Forcing download by deleting $runtimeFolder directory ${RCol}" 256 | rm -rf "$runtimeFolder" 257 | fi 258 | 259 | if [ -e "$runtimeFolder" ]; then 260 | printf "%b\n" "${Gre}$runtimeFullName already installed. ${RCol}" 261 | return 0 262 | fi 263 | 264 | if ! __dnvm_has "curl"; then 265 | printf "%b\n" "${Red}$_DNVM_COMMAND_NAME needs curl to proceed. ${RCol}" >&2; 266 | return 1 267 | fi 268 | 269 | local useSudo= 270 | mkdir -p "$runtimeFolder" > /dev/null 2>&1 271 | if [ ! -d $runtimeFolder ]; then 272 | if ! __dnvm_promptSudo $acceptSudo "In order to install dnx globally, dnvm will have to temporarily run as root." ; then 273 | useSudo=sudo 274 | sudo mkdir -p "$runtimeFolder" > /dev/null 2>&1 || return 1 275 | else 276 | return 1 277 | fi 278 | fi 279 | echo "Downloading $runtimeFullName from $DNX_ACTIVE_FEED" 280 | echo "Download: $downloadUrl" 281 | 282 | local httpResult=$($useSudo curl -L -D - "$downloadUrl" -o "$runtimeFile" -# | grep "^HTTP/1.1" | head -n 1 | sed "s/HTTP.1.1 \([0-9]*\).*/\1/") 283 | 284 | if [[ $httpResult == "404" ]]; then 285 | printf "%b\n" "${Red}$runtimeFullName was not found in repository $DNX_ACTIVE_FEED ${RCol}" 286 | printf "%b\n" "${Cya}This is most likely caused by the feed not having the version that you typed. Check that you typed the right version and try again. Other possible causes are the feed doesn't have a $_DNVM_RUNTIME_SHORT_NAME of the right name format or some other error caused a 404 on the server.${RCol}" 287 | return 1 288 | fi 289 | [[ $httpResult != "302" && $httpResult != "200" ]] && echo "${Red}HTTP Error $httpResult fetching $runtimeFullName from $DNX_ACTIVE_FEED ${RCol}" && return 1 290 | 291 | __dnvm_unpack $runtimeFile $runtimeFolder $useSudo 292 | return $? 293 | } 294 | 295 | __dnvm_unpack() { 296 | local runtimeFile="$1" 297 | local runtimeFolder="$2" 298 | local useSudo=$3 299 | 300 | echo "Installing to $runtimeFolder" 301 | 302 | if ! __dnvm_has "unzip"; then 303 | echo "$_DNVM_COMMAND_NAME needs unzip to proceed." >&2; 304 | return 1 305 | fi 306 | 307 | $useSudo unzip $runtimeFile -d $runtimeFolder > /dev/null 2>&1 308 | 309 | [ -e "$runtimeFolder/[Content_Types].xml" ] && $useSudo rm "$runtimeFolder/[Content_Types].xml" 310 | 311 | [ -e "$runtimeFolder/_rels/" ] && $useSudo rm -rf "$runtimeFolder/_rels/" 312 | 313 | [ -e "$runtimeFolder/package/" ] && $useSudo rm -rf "$runtimeFolder/_package/" 314 | 315 | [ -e "$runtimeFile" ] && $useSudo rm -f "$runtimeFile" 316 | 317 | #Set dnx to be executable 318 | if [[ -s "$runtimeFolder/bin/dnx" ]]; then 319 | $useSudo chmod 775 "$runtimeFolder/bin/dnx" 320 | fi 321 | 322 | #Set dnu to be executable 323 | if [[ -s "$runtimeFolder/bin/dnu" ]]; then 324 | $useSudo chmod 775 "$runtimeFolder/bin/dnu" 325 | fi 326 | } 327 | 328 | __dnvm_requested_version_or_alias() { 329 | local versionOrAlias="$1" 330 | local runtime="$2" 331 | local arch="$3" 332 | local os="$4" 333 | local runtimeBin=$(__dnvm_locate_runtime_bin_from_full_name "$versionOrAlias") 334 | 335 | # If the name specified is an existing package, just use it as is 336 | if [ -n "$runtimeBin" ]; then 337 | echo "$versionOrAlias" 338 | else 339 | if [ -e "$_DNVM_ALIAS_DIR/$versionOrAlias.alias" ]; then 340 | local runtimeFullName=$(cat "$_DNVM_ALIAS_DIR/$versionOrAlias.alias") 341 | if [[ ! -n "$runtime" && ! -n "$arch" ]]; then 342 | echo "$runtimeFullName" 343 | return 344 | fi 345 | local pkgVersion=$(__dnvm_package_version "$runtimeFullName") 346 | fi 347 | 348 | if [[ ! -n "$pkgVersion" ]]; then 349 | local pkgVersion=$versionOrAlias 350 | fi 351 | local pkgArchitecture="x64" 352 | local pkgSystem=$os 353 | 354 | if [[ -z $runtime || "$runtime" == "mono" ]]; then 355 | echo "$_DNVM_RUNTIME_PACKAGE_NAME-mono.$pkgVersion" 356 | else 357 | if [ "$arch" != "" ]; then 358 | local pkgArchitecture="$arch" 359 | fi 360 | if [ "$os" == "" ]; then 361 | local pkgSystem=$(__dnvm_current_os) 362 | fi 363 | 364 | echo "$_DNVM_RUNTIME_PACKAGE_NAME-$runtime-$pkgSystem-$pkgArchitecture.$pkgVersion" 365 | fi 366 | fi 367 | } 368 | 369 | # This will be more relevant if we support global installs 370 | __dnvm_locate_runtime_bin_from_full_name() { 371 | local runtimeFullName=$1 372 | for v in `echo $DNX_HOME | tr ":" "\n"`; do 373 | if [ -e "$v/runtimes/$runtimeFullName/bin" ]; then 374 | echo "$v/runtimes/$runtimeFullName/bin" && return 375 | fi 376 | done 377 | } 378 | 379 | __echo_art() { 380 | printf "%b" "${Cya}" 381 | echo " ___ _ ___ ____ ___" 382 | echo " / _ \/ |/ / | / / |/ /" 383 | echo " / // / /| |/ / /|_/ / " 384 | echo " /____/_/|_/ |___/_/ /_/ " 385 | printf "%b" "${RCol}" 386 | } 387 | 388 | __dnvm_description() { 389 | __echo_art 390 | echo "" 391 | echo "$_DNVM_VERSION_MANAGER_NAME - Version 1.0.0-$_DNVM_BUILDNUMBER" 392 | [[ "$_DNVM_AUTHORS" != {{* ]] && echo "By $_DNVM_AUTHORS" 393 | echo "" 394 | echo "DNVM can be used to download versions of the $_DNVM_RUNTIME_FRIENDLY_NAME and manage which version you are using." 395 | echo "You can control the URL of the stable and unstable channel by setting the DNX_FEED and DNX_UNSTABLE_FEED variables." 396 | echo "" 397 | printf "%b\n" "${Yel}Current feed settings:${RCol}" 398 | printf "%b\n" "${Cya}Default Stable:${Yel} $_DNVM_DEFAULT_FEED" 399 | printf "%b\n" "${Cya}Default Unstable:${Yel} $_DNVM_DEFAULT_UNSTABLE_FEED" 400 | 401 | local dnxStableOverride="" 402 | [[ -n $DNX_FEED ]] && dnxStableOverride="$DNX_FEED" 403 | 404 | printf "%b\n" "${Cya}Current Stable Override:${Yel} $dnxStableOverride" 405 | 406 | local dnxUnstableOverride="" 407 | [[ -n $DNX_UNSTABLE_FEED ]] && dnxUnstableOverride="$DNX_UNSTABLE_FEED" 408 | 409 | printf "%b\n" "${Cya}Current Unstable Override:${Yel} $dnxUnstableOverride${RCol}" 410 | echo "" 411 | 412 | } 413 | 414 | __dnvm_version() { 415 | echo "1.0.0-$_DNVM_BUILDNUMBER" 416 | } 417 | 418 | __dnvm_help() { 419 | __dnvm_description 420 | printf "%b\n" "${Cya}USAGE:${Yel} $_DNVM_COMMAND_NAME [options] ${RCol}" 421 | echo "" 422 | printf "%b\n" "${Yel}$_DNVM_COMMAND_NAME upgrade [-f|-force] [-u|-unstable] [-g|-global] [-y]${RCol}" 423 | echo " install latest $_DNVM_RUNTIME_SHORT_NAME from feed" 424 | echo " adds $_DNVM_RUNTIME_SHORT_NAME bin to path of current command line" 425 | echo " set installed version as default" 426 | echo " -f|-force force upgrade. Overwrite existing version of $_DNVM_RUNTIME_SHORT_NAME if already installed" 427 | echo " -u|-unstable use unstable feed. Installs the $_DNVM_RUNTIME_SHORT_NAME from the unstable feed" 428 | echo " -r|-runtime runtime flavor to install [mono or coreclr] (default: mono)" 429 | echo " -g|-global Installs the latest $_DNVM_RUNTIME_SHORT_NAME in the configured global $_DNVM_RUNTIME_SHORT_NAME file location (default: /usr/local/lib/dnx current: $DNX_GLOBAL_HOME)" 430 | echo " -y Assume Yes to all queries and do not prompt" 431 | echo "" 432 | printf "%b\n" "${Yel}$_DNVM_COMMAND_NAME install |||latest [-r ] [-OS ] [-alias ] [-a|-arch ] [-p|-persistent] [-f|-force] [-u|-unstable] [-g|-global] [-y]${RCol}" 433 | echo " | install requested $_DNVM_RUNTIME_SHORT_NAME from feed" 434 | echo " install requested $_DNVM_RUNTIME_SHORT_NAME from local package on filesystem" 435 | echo " latest install latest version of $_DNVM_RUNTIME_SHORT_NAME from feed" 436 | echo " -OS the operating system that the runtime targets (default:$(__dnvm_current_os))" 437 | echo " -alias set alias for requested $_DNVM_RUNTIME_SHORT_NAME on install" 438 | echo " -a|-arch architecture to use (x64)" 439 | echo " -p|-persistent set installed version as default" 440 | echo " -f|-force force install. Overwrite existing version of $_DNVM_RUNTIME_SHORT_NAME if already installed" 441 | echo " -u|-unstable use unstable feed. Installs the $_DNVM_RUNTIME_SHORT_NAME from the unstable feed" 442 | echo " -r|-runtime runtime flavor to install [mono or coreclr] (default: mono)" 443 | echo " -g|-global Installs to the configured global $_DNVM_RUNTIME_SHORT_NAME file location (default: /usr/local/lib/dnx current: $DNX_GLOBAL_HOME)" 444 | echo " -y Assume Yes to all queries and do not prompt" 445 | echo "" 446 | echo " adds $_DNVM_RUNTIME_SHORT_NAME bin to path of current command line" 447 | echo "" 448 | printf "%b\n" "${Yel}$_DNVM_COMMAND_NAME uninstall [-r|-runtime ] [-a|-arch ] [-OS ]${RCol}" 449 | echo " the version to uninstall" 450 | echo " -r|-runtime runtime flavor to uninstall [mono or coreclr] (default: mono)" 451 | echo " -a|-arch architecture to use (x64)" 452 | echo " -OS the operating system that the runtime targets (default:$(__dnvm_current_os))" 453 | echo " -y Assume Yes to all queries and do not prompt" 454 | echo "" 455 | printf "%b\n" "${Yel}$_DNVM_COMMAND_NAME use |||none [-p|-persistent] [-r|-runtime ] [-a|-arch ] ${RCol}" 456 | echo " || add $_DNVM_RUNTIME_SHORT_NAME bin to path of current command line " 457 | echo " none remove $_DNVM_RUNTIME_SHORT_NAME bin from path of current command line" 458 | echo " -p|-persistent set selected version as default" 459 | echo " -r|-runtime runtime flavor to use [mono or coreclr] (default: mono)" 460 | echo " -a|-arch architecture to use (x64)" 461 | echo "" 462 | printf "%b\n" "${Yel}$_DNVM_COMMAND_NAME run | ${RCol}" 463 | echo " | the version or alias to run" 464 | echo " arguments to be passed to $_DNVM_RUNTIME_SHORT_NAME" 465 | echo "" 466 | echo " runs the $_DNVM_RUNTIME_SHORT_NAME command from the specified version of the runtime without affecting the current PATH" 467 | echo "" 468 | printf "%b\n" "${Yel}$_DNVM_COMMAND_NAME exec | ${RCol}" 469 | echo " | the version or alias to execute in" 470 | echo " the command to run" 471 | echo " arguments to be passed to the command" 472 | echo "" 473 | echo " runs the specified command in the context of the specified version of the runtime without affecting the current PATH" 474 | echo " example: $_DNVM_COMMAND_NAME exec 1.0.0-beta4 $_DNVM_PACKAGE_MANAGER_NAME build" 475 | echo "" 476 | printf "%b\n" "${Yel}$_DNVM_COMMAND_NAME list [-detailed]${RCol}" 477 | echo " -detailed display more detailed information on each runtime" 478 | echo "" 479 | echo " list $_DNVM_RUNTIME_SHORT_NAME versions installed " 480 | echo "" 481 | printf "%b\n" "${Yel}$_DNVM_COMMAND_NAME alias ${RCol}" 482 | echo " list $_DNVM_RUNTIME_SHORT_NAME aliases which have been defined" 483 | echo "" 484 | printf "%b\n" "${Yel}$_DNVM_COMMAND_NAME alias ${RCol}" 485 | echo " display value of the specified alias" 486 | echo "" 487 | printf "%b\n" "${Yel}$_DNVM_COMMAND_NAME alias || ${RCol}" 488 | echo " the name of the alias to set" 489 | echo " || the $_DNVM_RUNTIME_SHORT_NAME version to set the alias to. Alternatively use the version of the specified alias" 490 | echo "" 491 | printf "%b\n" "${Yel}$_DNVM_COMMAND_NAME alias [-d|-delete] ${RCol}" 492 | echo " remove the specified alias" 493 | echo "" 494 | printf "%b\n" "${Yel}$_DNVM_COMMAND_NAME [help|-h|-help|--help] ${RCol}" 495 | echo " displays this help text." 496 | echo "" 497 | printf "%b\n" "${Yel}$_DNVM_COMMAND_NAME [version|-v|-version|--version] ${RCol}" 498 | echo " print the dnvm version." 499 | echo "" 500 | printf "%b\n" "${Yel}$_DNVM_COMMAND_NAME update-self ${RCol}" 501 | echo " updates dnvm itself." 502 | } 503 | 504 | dnvm() 505 | { 506 | if [ $# -lt 1 ]; then 507 | __dnvm_description 508 | 509 | printf "%b\n" "Use ${Yel}$_DNVM_COMMAND_NAME [help|-h|-help|--help] ${RCol} to display help text." 510 | echo "" 511 | return 512 | fi 513 | 514 | case $1 in 515 | "help"|"-h"|"-help"|"--help" ) 516 | __dnvm_help 517 | ;; 518 | 519 | "version"|"-v"|"-version"|"--version" ) 520 | __dnvm_version 521 | ;; 522 | 523 | "update-self" ) 524 | __dnvm_update_self 525 | ;; 526 | 527 | "upgrade" ) 528 | shift 529 | $_DNVM_COMMAND_NAME install latest -p $@ 530 | ;; 531 | 532 | "install" ) 533 | [ $# -lt 2 ] && __dnvm_help && return 534 | shift 535 | local persistent= 536 | local versionOrAlias= 537 | local alias= 538 | local force= 539 | local unstable= 540 | local os= 541 | local runtime= 542 | local arch= 543 | local global=0 544 | local acceptSudo=0 545 | while [ $# -ne 0 ] 546 | do 547 | if [[ $1 == "-p" || $1 == "-persistent" ]]; then 548 | local persistent="-p" 549 | elif [[ $1 == "-alias" ]]; then 550 | local alias=$2 551 | shift 552 | elif [[ $1 == "-f" || $1 == "-force" ]]; then 553 | local force="-f" 554 | elif [[ $1 == "-u" || $1 == "-unstable" ]]; then 555 | local unstable="-u" 556 | elif [[ $1 == "-r" || $1 == "-runtime" ]]; then 557 | local runtime=$(__dnvm_to_lower "$2") 558 | shift 559 | elif [[ $1 == "-OS" ]]; then 560 | local os=$(__dnvm_to_lower "$2") 561 | shift 562 | elif [[ $1 == "-y" ]]; then 563 | local acceptSudo=1 564 | elif [[ $1 == "-a" || $1 == "-arch" ]]; then 565 | local arch=$(__dnvm_to_lower "$2") 566 | shift 567 | 568 | if [[ $arch != "x86" && $arch != "x64" ]]; then 569 | printf "%b\n" "${Red}Architecture must be x86 or x64.${RCol}" 570 | return 1 571 | fi 572 | elif [[ $1 == "-g" || $1 == "-global" ]]; then 573 | local global=1 574 | elif [[ -n $1 ]]; then 575 | [[ -n $versionOrAlias ]] && echo "Invalid option $1" && __dnvm_help && return 1 576 | local versionOrAlias=$1 577 | fi 578 | shift 579 | done 580 | 581 | if [[ $arch == "x86" && $runtime == "coreclr" && $os != "win" ]]; then 582 | printf "%b\n" "${Red}Core CLR doesn't currently have a 32 bit build. You must use x64.${RCol}" 583 | return 1 584 | fi 585 | 586 | if [ -z $unstable ]; then 587 | DNX_ACTIVE_FEED="$DNX_FEED" 588 | if [ -z "$DNX_ACTIVE_FEED" ]; then 589 | DNX_ACTIVE_FEED="$_DNVM_DEFAULT_FEED" 590 | else 591 | printf "%b\n" "${Yel}Default stable feed ($_DNVM_DEFAULT_FEED) is being overridden by the value of the DNX_FEED variable ($DNX_FEED). ${RCol}" 592 | fi 593 | else 594 | DNX_ACTIVE_FEED="$DNX_UNSTABLE_FEED" 595 | if [ -z "$DNX_ACTIVE_FEED" ]; then 596 | DNX_ACTIVE_FEED="$_DNVM_DEFAULT_UNSTABLE_FEED" 597 | else 598 | printf "%b\n" "${Yel}Default unstable feed ($_DNVM_DEFAULT_UNSTABLE_FEED) is being overridden by the value of the DNX_UNSTABLE_FEED variable ($DNX_UNSTABLE_FEED). ${RCol}" 599 | fi 600 | fi 601 | 602 | if [[ -z $os ]]; then 603 | os=$(__dnvm_current_os) 604 | fi 605 | if [[ $os == "osx" ]]; then 606 | os="darwin" 607 | fi 608 | 609 | if [[ -z $runtime ]]; then 610 | runtime=$(__dnvm_os_runtime_defaults "$os") 611 | fi 612 | 613 | if [[ -z $arch ]]; then 614 | arch=$(__dnvm_runtime_bitness_defaults "$runtime") 615 | fi 616 | 617 | if [[ $runtime == "mono" ]] && ! __dnvm_has "mono"; then 618 | printf "%b\n" "${Yel}It appears you don't have Mono available. Remember to get Mono before trying to run $DNVM_RUNTIME_SHORT_NAME application. ${RCol}" >&2; 619 | fi 620 | 621 | local runtimeDir=$_DNVM_USER_PACKAGES 622 | if [ $global == 1 ]; then 623 | runtimeDir=$_DNVM_GLOBAL_PACKAGES 624 | fi 625 | 626 | if [[ "$versionOrAlias" != *.nupkg ]]; then 627 | if [[ "$versionOrAlias" == "latest" ]]; then 628 | echo "Determining latest version" 629 | read versionOrAlias downloadUrl < <(__dnvm_find_latest "$runtime" "$arch" "$os") 630 | [[ $? == 1 ]] && echo "Error: Could not find latest version from feed $DNX_ACTIVE_FEED" && return 1 631 | printf "%b\n" "Latest version is ${Cya}$versionOrAlias ${RCol}" 632 | else 633 | local runtimeFullName=$(__dnvm_requested_version_or_alias "$versionOrAlias" "$runtime" "$arch" "$os") 634 | local runtimeVersion=$(__dnvm_package_version "$runtimeFullName") 635 | 636 | read versionOrAlias downloadUrl < <(__dnvm_find_package "$runtime" "$arch" "$os" "$runtimeVersion") 637 | [[ $? == 1 ]] && echo "Error: Could not find version $runtimeVersion in feed $DNX_ACTIVE_FEED" && return 1 638 | fi 639 | local runtimeFullName=$(__dnvm_requested_version_or_alias "$versionOrAlias" "$runtime" "$arch" "$os") 640 | local runtimeFolder="$runtimeDir/$runtimeFullName" 641 | 642 | local exist=0 643 | for folder in `echo $DNX_HOME | tr ":" "\n"`; do 644 | if [ -e "$folder/runtimes/$runtimeFullName" ]; then 645 | echo "$runtimeFullName already installed in $folder" 646 | exist=1 647 | fi 648 | done 649 | 650 | if [[ $exist != 1 ]]; then 651 | __dnvm_download "$runtimeFullName" "$downloadUrl" "$runtimeFolder" "$force" "$acceptSudo" 652 | fi 653 | [[ $? == 1 ]] && return 1 654 | if [[ "$os" == $(__dnvm_current_os) ]]; then 655 | $_DNVM_COMMAND_NAME use "$versionOrAlias" "$persistent" "-runtime" "$runtime" "-arch" "$arch" 656 | [[ -n $alias ]] && $_DNVM_COMMAND_NAME alias "$alias" "$versionOrAlias" 657 | fi 658 | else 659 | local runtimeFullName=$(basename $versionOrAlias | sed "s/\(.*\)\.nupkg/\1/") 660 | local runtimeVersion=$(__dnvm_package_version "$runtimeFullName") 661 | local runtimeFolder="$runtimeDir/$runtimeFullName" 662 | local runtimeFile="$runtimeFolder/$runtimeFullName.nupkg" 663 | local runtimeClr=$(__dnvm_package_runtime "$runtimeFullName") 664 | 665 | if [ -n "$force" ]; then 666 | printf "%b\n" "${Yel}Forcing download by deleting $runtimeFolder directory ${RCol}" 667 | rm -rf "$runtimeFolder" 668 | fi 669 | 670 | if [ -e "$runtimeFolder" ]; then 671 | echo "$runtimeFullName already installed" 672 | else 673 | local useSudo= 674 | mkdir -p "$runtimeFolder" > /dev/null 2>&1 675 | if [ ! -d $runtimeFolder ]; then 676 | if ! __dnvm_promptSudo $acceptSudo "In order to install dnx globally, dnvm will have to temporarily run as root." ; then 677 | useSudo=sudo 678 | sudo mkdir -p "$runtimeFolder" > /dev/null 2>&1 || return 1 679 | else 680 | return 1 681 | fi 682 | fi 683 | cp -a "$versionOrAlias" "$runtimeFile" 684 | __dnvm_unpack "$runtimeFile" "$runtimeFolder" $useSudo 685 | [[ $? == 1 ]] && return 1 686 | fi 687 | $_DNVM_COMMAND_NAME use "$runtimeVersion" "$persistent" -r "$runtimeClr" 688 | [[ -n $alias ]] && $_DNVM_COMMAND_NAME alias "$alias" "$runtimeVersion" 689 | fi 690 | ;; 691 | 692 | "uninstall" ) 693 | [[ $# -lt 2 ]] && __dnvm_help && return 694 | shift 695 | 696 | local versionOrAlias= 697 | local runtime= 698 | local architecture= 699 | local os= 700 | local acceptSudo=0 701 | while [ $# -ne 0 ] 702 | do 703 | if [[ $1 == "-r" || $1 == "-runtime" ]]; then 704 | local runtime=$(__dnvm_to_lower "$2") 705 | shift 706 | elif [[ $1 == "-a" || $1 == "-arch" ]]; then 707 | local architecture=$(__dnvm_to_lower "$2") 708 | shift 709 | elif [[ $1 == "-OS" ]]; then 710 | local os=$(__dnvm_to_lower "$2") 711 | shift 712 | elif [[ $1 == "-y" ]]; then 713 | local acceptSudo=1 714 | elif [[ -n $1 ]]; then 715 | local versionOrAlias=$1 716 | fi 717 | 718 | shift 719 | done 720 | 721 | if [[ -z $os ]]; then 722 | os=$(__dnvm_current_os) 723 | elif [[ $os == "osx" ]]; then 724 | os="darwin" 725 | fi 726 | 727 | if [[ -z $runtime ]]; then 728 | runtime=$(__dnvm_os_runtime_defaults "$os") 729 | fi 730 | 731 | if [[ -z $architecture ]]; then 732 | architecture=$(__dnvm_runtime_bitness_defaults "$runtime") 733 | fi 734 | 735 | # dnx-coreclr-linux-x64.1.0.0-beta7-12290 736 | local runtimeFullName=$(__dnvm_requested_version_or_alias "$versionOrAlias" "$runtime" "$architecture" "$os") 737 | 738 | for folder in `echo $DNX_HOME | tr ":" "\n"`; do 739 | if [ -e "$folder/runtimes/$runtimeFullName" ]; then 740 | local runtimeFolder="$folder/runtimes/$runtimeFullName" 741 | fi 742 | done 743 | 744 | if [[ -e $runtimeFolder ]]; then 745 | if [[ $runtimeFolder == *"$DNX_GLOBAL_HOME"* ]] ; then 746 | if ! __dnvm_promptSudo $acceptSudo "In order to uninstall a global dnx, dnvm will have to temporarily run as root." ; then 747 | local useSudo=sudo 748 | fi 749 | fi 750 | $useSudo rm -r $runtimeFolder 751 | echo "Removed $runtimeFolder" 752 | else 753 | echo "$runtimeFolder is not installed" 754 | fi 755 | 756 | if [ -d "$_DNVM_ALIAS_DIR" ]; then 757 | for __dnvm_file in $(find "$_DNVM_ALIAS_DIR" -name *.alias); do 758 | if [ $(cat $__dnvm_file) == "$runtimeFullName" ]; then 759 | rm $__dnvm_file 760 | fi 761 | done 762 | fi 763 | ;; 764 | 765 | "use"|"run"|"exec" ) 766 | [[ $1 == "use" && $# -lt 2 ]] && __dnvm_help && return 767 | 768 | local cmd=$1 769 | local persistent= 770 | local arch= 771 | local runtime= 772 | 773 | local versionOrAlias= 774 | shift 775 | if [ $cmd == "use" ]; then 776 | while [ $# -ne 0 ] 777 | do 778 | if [[ $1 == "-p" || $1 == "-persistent" ]]; then 779 | local persistent="true" 780 | elif [[ $1 == "-a" || $1 == "-arch" ]]; then 781 | local arch=$(__dnvm_to_lower "$2") 782 | shift 783 | elif [[ $1 == "-r" || $1 == "-runtime" ]]; then 784 | local runtime=$(__dnvm_to_lower "$2") 785 | shift 786 | elif [[ $1 == -* ]]; then 787 | echo "Invalid option $1" && __dnvm_help && return 1 788 | elif [[ -n $1 ]]; then 789 | [[ -n $versionOrAlias ]] && echo "Invalid option $1" && __dnvm_help && return 1 790 | local versionOrAlias=$1 791 | fi 792 | shift 793 | done 794 | else 795 | while [ $# -ne 0 ] 796 | do 797 | if [[ $1 == "-a" || $1 == "-arch" ]]; then 798 | local arch=$(__dnvm_to_lower "$2") 799 | shift 800 | elif [[ $1 == "-r" || $1 == "-runtime" ]]; then 801 | local runtime=$(__dnvm_to_lower "$2") 802 | shift 803 | elif [[ -n $1 ]]; then 804 | [[ -n $versionOrAlias ]] && break 805 | local versionOrAlias=$1 806 | fi 807 | shift 808 | done 809 | fi 810 | 811 | if [[ $cmd == "use" && $versionOrAlias == "none" ]]; then 812 | echo "Removing $_DNVM_RUNTIME_SHORT_NAME from process PATH" 813 | # Strip other version from PATH 814 | PATH=$(__dnvm_strip_path "$PATH" "/bin") 815 | 816 | if [[ -n $persistent && -e "$_DNVM_ALIAS_DIR/default.alias" ]]; then 817 | echo "Setting default $_DNVM_RUNTIME_SHORT_NAME to none" 818 | rm "$_DNVM_ALIAS_DIR/default.alias" 819 | fi 820 | return 0 821 | fi 822 | 823 | local runtimeFullName=$(__dnvm_requested_version_or_alias "$versionOrAlias" "$runtime" "$arch" "$(__dnvm_current_os)") 824 | local runtimeBin=$(__dnvm_locate_runtime_bin_from_full_name "$runtimeFullName") 825 | 826 | if [[ -z $runtimeBin ]]; then 827 | echo "Cannot find $runtimeFullName, do you need to run '$_DNVM_COMMAND_NAME install $versionOrAlias'?" 828 | return 1 829 | fi 830 | 831 | case $cmd in 832 | "run") 833 | local hostpath="$runtimeBin/dnx" 834 | if [[ -e $hostpath ]]; then 835 | $hostpath $@ 836 | return $? 837 | else 838 | echo "Cannot find $_DNVM_RUNTIME_SHORT_NAME in $runtimeBin. It may have been corrupted. Use '$_DNVM_COMMAND_NAME install $versionOrAlias -f' to attempt to reinstall it" 839 | fi 840 | ;; 841 | "exec") 842 | ( 843 | PATH=$(__dnvm_strip_path "$PATH" "/bin") 844 | PATH=$(__dnvm_prepend_path "$PATH" "$runtimeBin") 845 | $@ 846 | ) 847 | return $? 848 | ;; 849 | "use") 850 | echo "Adding" $runtimeBin "to process PATH" 851 | 852 | PATH=$(__dnvm_strip_path "$PATH" "/bin") 853 | PATH=$(__dnvm_prepend_path "$PATH" "$runtimeBin") 854 | 855 | if [[ -n $persistent ]]; then 856 | local runtimeVersion=$(__dnvm_package_version "$runtimeFullName") 857 | $_DNVM_COMMAND_NAME alias default "$runtimeVersion" 858 | fi 859 | ;; 860 | esac 861 | ;; 862 | 863 | "alias" ) 864 | [[ $# -gt 9 ]] && __dnvm_help && return 865 | 866 | [[ ! -e "$_DNVM_ALIAS_DIR/" ]] && mkdir -p "$_DNVM_ALIAS_DIR/" > /dev/null 867 | 868 | if [[ $# == 1 ]]; then 869 | echo "" 870 | local format="%-25s %s\n" 871 | printf "$format" "Alias" "Name" 872 | printf "$format" "-----" "----" 873 | if [ -d "$_DNVM_ALIAS_DIR" ]; then 874 | for __dnvm_file in $(find "$_DNVM_ALIAS_DIR" -name *.alias); do 875 | local alias="$(basename $__dnvm_file | sed 's/\.alias//')" 876 | local name="$(cat $__dnvm_file)" 877 | printf "$format" "$alias" "$name" 878 | done 879 | fi 880 | echo "" 881 | return 882 | fi 883 | shift 884 | 885 | if [[ $1 == "-d" || $1 == "-delete" ]]; then 886 | local name=$2 887 | local aliasPath="$_DNVM_ALIAS_DIR/$name.alias" 888 | [[ ! -e "$aliasPath" ]] && echo "Cannot remove alias, '$name' is not a valid alias name" && return 1 889 | echo "Removing alias $name" 890 | rm "$aliasPath" >> /dev/null 2>&1 891 | return 892 | fi 893 | 894 | local name="$1" 895 | 896 | if [[ $# == 1 ]]; then 897 | [[ ! -e "$_DNVM_ALIAS_DIR/$name.alias" ]] && echo "There is no alias called '$name'" && return 1 898 | cat "$_DNVM_ALIAS_DIR/$name.alias" 899 | echo "" 900 | return 901 | fi 902 | 903 | shift 904 | local versionOrAlias="$1" 905 | shift 906 | while [ $# -ne 0 ] 907 | do 908 | if [[ $1 == "-a" || $1 == "-arch" ]]; then 909 | local arch=$(__dnvm_to_lower "$2") 910 | shift 911 | elif [[ $1 == "-r" || $1 == "-runtime" ]]; then 912 | local runtime=$(__dnvm_to_lower "$2") 913 | shift 914 | elif [[ $1 == "-OS" ]]; then 915 | local os=$(__dnvm_to_lower "$2") 916 | shift 917 | fi 918 | shift 919 | done 920 | 921 | local runtimeFullName=$(__dnvm_requested_version_or_alias "$versionOrAlias" "$runtime" "$arch" "$os") 922 | 923 | ([[ ! -d "$_DNVM_USER_PACKAGES/$runtimeFullName" ]] && [[ ! -d "$_DNVM_GLOBAL_PACKAGES/$runtimeFullName" ]]) && echo "$runtimeFullName is not an installed $_DNVM_RUNTIME_SHORT_NAME version" && return 1 924 | 925 | local action="Setting" 926 | [[ -e "$_DNVM_ALIAS_DIR/$name.alias" ]] && action="Updating" 927 | echo "$action alias '$name' to '$runtimeFullName'" 928 | echo "$runtimeFullName" >| "$_DNVM_ALIAS_DIR/$name.alias" 929 | ;; 930 | 931 | "unalias" ) 932 | [[ $# -ne 2 ]] && __dnvm_help && return 933 | 934 | local name=$2 935 | echo "This command has been deprecated. Use '$_DNVM_COMMAND_NAME alias -d' instead" 936 | $_DNVM_COMMAND_NAME alias -d $name 937 | return $? 938 | ;; 939 | 940 | "list" ) 941 | [[ $# -gt 2 ]] && __dnvm_help && return 942 | 943 | [[ ! -d $_DNVM_USER_PACKAGES ]] && echo "$_DNVM_RUNTIME_FRIENDLY_NAME is not installed." && return 1 944 | 945 | local searchGlob="$_DNVM_RUNTIME_PACKAGE_NAME-*" 946 | 947 | local runtimes="" 948 | for location in `echo $DNX_HOME | tr ":" "\n"`; do 949 | location+="/runtimes" 950 | if [ -d "$location" ]; then 951 | local oruntimes="$(find $location -name "$searchGlob" \( -type d -or -type l \) -prune -exec basename {} \;)" 952 | for v in `echo $oruntimes | tr "\n" " "`; do 953 | runtimes+="$v:$location"$'\n' 954 | done 955 | fi 956 | done 957 | 958 | [[ -z $runtimes ]] && echo 'No runtimes installed. You can run `dnvm install latest` or `dnvm upgrade` to install a runtime.' && return 959 | 960 | echo "" 961 | 962 | # Separate empty array declaration from initialization 963 | # to avoid potential ZSH error: local:217: maximum nested function level reached 964 | local arr 965 | arr=() 966 | 967 | # Z shell array-index starts at one. 968 | local i=1 969 | if [ -d "$_DNVM_ALIAS_DIR" ]; then 970 | for __dnvm_file in $(find "$_DNVM_ALIAS_DIR" -name *.alias); do 971 | if [ ! -d "$_DNVM_USER_PACKAGES/$(cat $__dnvm_file)" ] && [ ! -d "$_DNVM_GLOBAL_PACKAGES/$(cat $__dnvm_file)" ]; then 972 | arr[$i]="$(basename $__dnvm_file | sed 's/\.alias//')/missing/$(cat $__dnvm_file)" 973 | runtimes="$runtimes $(cat $__dnvm_file)" 974 | else 975 | arr[$i]="$(basename $__dnvm_file | sed 's/\.alias//')/$(cat $__dnvm_file)" 976 | fi 977 | let i+=1 978 | done 979 | fi 980 | 981 | if [[ $2 == "-detailed" ]]; then 982 | # Calculate widest alias 983 | local widestAlias=5 984 | for f in `echo -e "$runtimes"`; do 985 | f=`echo $f | sed 's/\([:]\).*//'` 986 | local pkgName=$(__dnvm_package_name "$f") 987 | local pkgVersion=$(__dnvm_package_version "$f") 988 | local alias="" 989 | local delim="" 990 | for i in "${arr[@]}"; do 991 | if [[ ${i##*/} == "$pkgName.$pkgVersion" ]]; then 992 | alias+="$delim${i%%/*}" 993 | delim=", " 994 | if [[ "${i%/*}" =~ \/missing$ ]]; then 995 | alias+=" (missing)" 996 | fi 997 | fi 998 | done 999 | if [ "${#alias}" -gt "$widestAlias" ]; then 1000 | widestAlias=${#alias} 1001 | fi 1002 | done 1003 | local formatString="%-6s %-20s %-7s %-12s %-15s %-${widestAlias}s %s\n" 1004 | printf "$formatString" "Active" "Version" "Runtime" "Architecture" "OperatingSystem" "Alias" "Location" 1005 | printf "$formatString" "------" "-------" "-------" "------------" "---------------" "-----" "--------" 1006 | else 1007 | local formatString="%-6s %-20s %-7s %-12s %-15s %s\n" 1008 | printf "$formatString" "Active" "Version" "Runtime" "Architecture" "OperatingSystem" "Alias" 1009 | printf "$formatString" "------" "-------" "-------" "------------" "---------------" "-----" 1010 | fi 1011 | 1012 | for f in `echo -e "$runtimes" | sort -t. -k2 -k3 -k4 -k1`; do 1013 | local location=`echo $f | sed 's/.*\([:]\)//'` 1014 | f=`echo $f | sed 's/\([:]\).*//'` 1015 | local formattedHome=`(echo $location | sed s=$HOME=~=g)` 1016 | local active="" 1017 | [[ $PATH == *"$location/$f/bin"* ]] && local active=" *" 1018 | local pkgRuntime=$(__dnvm_package_runtime "$f") 1019 | local pkgName=$(__dnvm_package_name "$f") 1020 | local pkgVersion=$(__dnvm_package_version "$f") 1021 | local pkgArch=$(__dnvm_package_arch "$f") 1022 | local pkgOs=$(__dnvm_package_os "$f") 1023 | 1024 | local alias="" 1025 | local delim="" 1026 | for i in "${arr[@]}"; do 1027 | if [[ ${i##*/} == "$pkgName.$pkgVersion" ]]; then 1028 | alias+="$delim${i%%/*}" 1029 | delim=", " 1030 | if [[ "${i%/*}" =~ \/missing$ ]]; then 1031 | alias+=" (missing)" 1032 | formattedHome="" 1033 | fi 1034 | fi 1035 | done 1036 | 1037 | if [[ $2 == "-detailed" ]]; then 1038 | printf "$formatString" "$active" "$pkgVersion" "$pkgRuntime" "$pkgArch" "$pkgOs" "$alias" "$formattedHome" 1039 | else 1040 | printf "$formatString" "$active" "$pkgVersion" "$pkgRuntime" "$pkgArch" "$pkgOs" "$alias" 1041 | fi 1042 | done 1043 | 1044 | echo "" 1045 | ;; 1046 | 1047 | *) 1048 | echo "Unknown command $1" 1049 | return 1 1050 | esac 1051 | 1052 | return 0 1053 | } 1054 | 1055 | # Add the home location's bin directory to the path if it doesn't exist 1056 | [[ ":$PATH:" != *":$DNX_USER_HOME/bin:"* ]] && export PATH="$DNX_USER_HOME/bin:$PATH" 1057 | 1058 | [[ ! -d "$_DNVM_USER_PACKAGES" ]] && mkdir -p $_DNVM_USER_PACKAGES 1059 | 1060 | # Generate the command function using the constant defined above. 1061 | $_DNVM_COMMAND_NAME alias default >/dev/null && $_DNVM_COMMAND_NAME use default >/dev/null || true 1062 | -------------------------------------------------------------------------------- /test/apps/README.md: -------------------------------------------------------------------------------- 1 | # Test Apps 2 | Sample DNX apps for testing DNVM installations. 3 | -------------------------------------------------------------------------------- /test/apps/TestApp/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | 4 | namespace TestApp { 5 | public class Program { 6 | public int Main(string[] args) { 7 | Console.WriteLine("Runtime is sane!"); 8 | return 0; 9 | } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /test/apps/TestApp/TestApp.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.22410.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "TestApp", "TestApp.xproj", "{0EF87869-3442-40AA-A0E6-089CD385F7D0}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {0EF87869-3442-40AA-A0E6-089CD385F7D0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {0EF87869-3442-40AA-A0E6-089CD385F7D0}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {0EF87869-3442-40AA-A0E6-089CD385F7D0}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {0EF87869-3442-40AA-A0E6-089CD385F7D0}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /test/apps/TestApp/TestApp.xproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 14.0 5 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) 6 | 7 | 8 | 9 | 0ef87869-3442-40aa-a0e6-089cd385f7d0 10 | ..\..\..\artifacts\obj\$(MSBuildProjectName) 11 | ..\..\..\artifacts\bin\ 12 | 13 | 14 | 2.0 15 | 16 | 17 | -------------------------------------------------------------------------------- /test/apps/TestApp/project.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.0.1-*", 3 | "description": "Quick app to exercise a few .NET things", 4 | "dependencies": {}, 5 | "commands": { 6 | "run": "run" 7 | }, 8 | "frameworks": { 9 | "dnx451": {}, 10 | "netstandardapp1.5": { 11 | "dependencies": { 12 | "System.Runtime": "4.0.21-beta-23225", 13 | "System.Console": "4.0.0-beta-23225", 14 | "System.Collections": "4.0.11-beta-23225", 15 | "System.Diagnostics.Process": "4.0.0-beta-23225", 16 | "System.Linq": "4.0.1-23225" 17 | }, 18 | "imports": [ 19 | "dnxcore50" 20 | ] 21 | } 22 | } 23 | } -------------------------------------------------------------------------------- /test/ps1/Run-Tests.ps1: -------------------------------------------------------------------------------- 1 | #Requires -Version 3 2 | <# 3 | .SYNOPSIS 4 | Runs the tests for dnvm 5 | 6 | .PARAMETER PesterPath 7 | The path to the root of the Pester (https://github.com/pester/Pester) module (optional) 8 | 9 | .PARAMETER PesterRef 10 | A git ref (branch, tag or commit id) to check out in the pester repo (optional) 11 | 12 | .PARAMETER PesterRepo 13 | The repository to clone Pester from (optional) 14 | 15 | .PARAMETER TestsPath 16 | The path to the folder containing Tests to run (optional) 17 | 18 | .PARAMETER TargetPath 19 | The path to the script to test (optional) 20 | 21 | .PARAMETER TestName 22 | The name of a specific test to run (optional) 23 | 24 | .PARAMETER TestWorkingDir 25 | The directory in which to place DNXes downloaded during the tests (optional) 26 | 27 | .PARAMETER TestAppsDir 28 | The directory in which test apps live (optional) 29 | 30 | .PARAMETER Tag 31 | Run only tests with the specified tag (optional) 32 | 33 | .PARAMETER Quiet 34 | Output minimal console messages 35 | 36 | .PARAMETER Debug 37 | Output extra console messages 38 | 39 | .PARAMETER TeamCity 40 | Output TeamCity test outcome markers 41 | #> 42 | param( 43 | [string]$PesterPath = $null, 44 | [string]$PesterRef = "master", 45 | [string]$PesterRepo = "https://github.com/pester/Pester", 46 | [string]$TestsPath = $null, 47 | [string]$TargetPath = $null, 48 | [string]$TestName = $null, 49 | [string]$TestWorkingDir = $null, 50 | [string]$TestAppsDir = $null, 51 | [Alias("Tags")][string]$Tag = $null, 52 | [string]$OutputFile = $null, 53 | [string]$OutputFormat = $null, 54 | [switch]$Quiet, 55 | [switch]$Debug, 56 | [switch]$TeamCity) 57 | 58 | . "$PSScriptRoot\_Common.ps1" 59 | 60 | # Check for necessary commands 61 | if(!(Get-Command git -ErrorAction SilentlyContinue)) { throw "Need git to run tests!" } 62 | 63 | if(!$PesterPath) { $PesterPath = Join-Path $PSScriptRoot ".pester" } 64 | 65 | # Check that Pester is present 66 | Write-Banner "Ensuring Pester is at $PesterRef" 67 | if(!(Test-Path $PesterPath)) { 68 | git clone $PesterRepo $PesterPath 2>&1 | Write-CommandOutput "git" 69 | } 70 | 71 | # Get the right tag checked out 72 | pushd $PesterPath 73 | git checkout $PesterRef 2>&1 | Write-CommandOutput "git" 74 | popd 75 | 76 | Write-Banner "Starting child shell to run" 77 | 78 | # Crappy that we have to duplicate things here... 79 | # Build a string that should basically match the argument string used to call us 80 | $childArgs = @() 81 | $PSBoundParameters.Keys | ForEach-Object { 82 | $key = $_ 83 | $value = $PSBoundParameters[$key] 84 | if($value -is [switch]) { 85 | if($value.IsPresent) { 86 | $childArgs += @("-$key") 87 | } 88 | } else { 89 | $childArgs += @("-$key",$value) 90 | } 91 | } 92 | 93 | # Launch the script that will actually run the tests in a new shell 94 | & powershell -Version 2 -NoProfile -NoLogo -Command "& `"$PSScriptRoot\_Execute-Tests.ps1`" $childArgs -RunningInNewPowershell" 95 | & powershell -NoProfile -NoLogo -Command "& `"$PSScriptRoot\_Execute-Tests.ps1`" $childArgs -RunningInNewPowershell" 96 | exit $LASTEXITCODE 97 | -------------------------------------------------------------------------------- /test/ps1/_Common.ps1: -------------------------------------------------------------------------------- 1 | # Constants 2 | Set-Variable -Option Constant "RuntimePackageName" "dnx" 3 | Set-Variable -Option Constant "RuntimeShortName" "DNX" 4 | Set-Variable -Option Constant "RuntimeFolderName" ".dnx" 5 | Set-Variable -Option Constant "CommandName" "dnvm" 6 | Set-Variable -Option Constant "VersionManagerName" ".NET Version Manager" 7 | Set-Variable -Option Constant "DefaultFeed" "https://www.myget.org/F/aspnetvnext/api/v2" 8 | Set-Variable -Option Constant "CrossGenCommand" "dnx-crossgen" 9 | Set-Variable -Option Constant "HomeEnvVar" "DNX_HOME" 10 | Set-Variable -Option Constant "UserHomeEnvVar" "DNX_USER_HOME" 11 | Set-Variable -Option Constant "FeedEnvVar" "DNX_FEED" 12 | Set-Variable -Option Constant "PackageManagerName" "dnu.cmd" 13 | Set-Variable -Option Constant "RuntimeHostName" "dnx.exe" 14 | 15 | function Write-Banner { 16 | param($Message) 17 | 18 | Write-Host -ForegroundColor Green "===== $Message =====" 19 | } 20 | 21 | filter Write-CommandOutput { 22 | param($Prefix) 23 | 24 | Write-Host -ForegroundColor Magenta -NoNewLine "$($Prefix): " 25 | Write-Host $_ 26 | } 27 | 28 | function Remove-EnvVar($var) { 29 | $path = "Env:\$var" 30 | if(Test-Path $path) { 31 | del $path 32 | } 33 | } 34 | 35 | function GetRuntimesOnPath { 36 | param($runtimeHome) 37 | if(!$runtimeHome) { 38 | $runtimeHome = (cat "env:\$UserHomeEnvVar") 39 | } 40 | 41 | if($env:PATH) { 42 | $paths = $env:PATH.Split(";") 43 | if($paths) { 44 | @($paths | Where { $_.StartsWith("$runtimeHome\runtimes") }) 45 | } 46 | } 47 | } 48 | 49 | function GetActiveRuntimePath { 50 | param($runtimeHome) 51 | GetRuntimesOnPath $runtimeHome | Select -First 1 52 | } 53 | 54 | function GetActiveRuntimeName { 55 | param($runtimeHome) 56 | if(!$runtimeHome) { 57 | $runtimeHome = (cat "env:\$UserHomeEnvVar") 58 | } 59 | $activeRuntime = GetActiveRuntimePath $runtimeHome 60 | if($activeRuntime) { 61 | $activeRuntime.Replace("$runtimeHome\runtimes\", "").Replace("\bin", "") 62 | } 63 | } 64 | 65 | function GetRuntimeName { 66 | param($clr, $arch, $os = "win", $ver = $TestRuntimeVersion) 67 | if($clr -eq "mono") { 68 | "$RuntimePackageName-mono.$($ver.ToLowerInvariant())" 69 | } else { 70 | "$RuntimePackageName-$($clr.ToLowerInvariant())-$($os.ToLowerInvariant())-$($arch.ToLowerInvariant()).$($ver.ToLowerInvariant())" 71 | } 72 | } 73 | 74 | # Borrowed from dnvm itself, but we can't really use that one so unfortunately we have to use copy-pasta :) 75 | # Modified slightly to take in a Proxy value so that it can be defined separately from the Proxy parameter 76 | function Add-Proxy-If-Specified { 77 | param( 78 | [System.Net.WebClient] $wc, 79 | [string] $Proxy 80 | ) 81 | if(!$Proxy) { 82 | $Proxy = $env:http_proxy 83 | } 84 | if ($Proxy) { 85 | $wp = New-Object System.Net.WebProxy($Proxy) 86 | $pb = New-Object UriBuilder($Proxy) 87 | if (!$pb.UserName) { 88 | $wp.Credentials = [System.Net.CredentialCache]::DefaultCredentials 89 | } else { 90 | $wp.Credentials = New-Object System.Net.NetworkCredential($pb.UserName, $pb.Password) 91 | } 92 | $wc.Proxy = $wp 93 | } 94 | } 95 | 96 | function Get-FileHash 97 | { 98 | param ([string] $Path) 99 | 100 | if (-not (Test-Path -LiteralPath $Path -PathType Leaf)) 101 | { 102 | return $null 103 | } 104 | 105 | $item = Get-Item -LiteralPath $Path 106 | if ($item -isnot [System.IO.FileSystemInfo]) 107 | { 108 | return $null 109 | } 110 | 111 | $stream = $null 112 | 113 | try 114 | { 115 | $sha = New-Object System.Security.Cryptography.SHA256CryptoServiceProvider 116 | $stream = $item.OpenRead() 117 | $bytes = $sha.ComputeHash($stream) 118 | return [convert]::ToBase64String($bytes) 119 | } 120 | finally 121 | { 122 | if ($null -ne $stream) { $stream.Close() } 123 | if ($null -ne $sha) { $sha.Clear() } 124 | } 125 | } 126 | -------------------------------------------------------------------------------- /test/ps1/_Execute-Tests.ps1: -------------------------------------------------------------------------------- 1 | #Requires -Version 2 2 | param( 3 | [string]$PesterPath = $null, 4 | [string]$PesterRef = "anurse/teamcity", 5 | [string]$PesterRepo = "https://github.com/anurse/Pester", 6 | [string]$TestsPath = $null, 7 | [string]$TargetPath = $null, 8 | [string]$TestName = $null, 9 | [string]$TestWorkingDir = $null, 10 | [string]$TestAppsDir = $null, 11 | [Alias("Tags")][string]$Tag = $null, 12 | [string]$OutputFile = $null, 13 | [string]$OutputFormat = $null, 14 | [switch]$Strict, 15 | [switch]$Quiet, 16 | [switch]$Debug, 17 | [switch]$TeamCity, 18 | 19 | # Cheap and relatively effective way to scare users away from running this script themselves 20 | [switch]$RunningInNewPowershell) 21 | 22 | if(!$RunningInNewPowershell) { 23 | throw "Don't use this script to run the tests! Use Run-Tests.ps1, it sets up a new powershell instance in which to run the tests!" 24 | } 25 | 26 | $scriptDir = $PSScriptRoot 27 | if (!$scriptDir) { 28 | if ($MyInvocation.MyCommand.Path) { 29 | $scriptDir = Split-Path $MyInvocation.MyCommand.Path -Parent 30 | } 31 | } 32 | 33 | Write-Host "Script Dir: $scriptDir" 34 | 35 | . "$scriptDir\_Common.ps1" 36 | 37 | # Set defaults 38 | if(!$PesterPath) { $PesterPath = Join-Path $scriptDir ".pester" } 39 | if(!$TestsPath) { $TestsPath = Join-Path $scriptDir "tests" } 40 | if(!$TargetPath) { $TargetPath = Convert-Path (Join-Path $scriptDir "../../src/dnvm.ps1") } 41 | if(!$TestWorkingDir) { $TestWorkingDir = Join-Path $scriptDir "testwork" } 42 | if(!$TestWorkingGlobalDir) { $TestWorkingGlobalDir = Join-Path $scriptDir "testworkGlobal" } 43 | if(!$TestAppsDir) { $TestAppsDir = Convert-Path (Join-Path $scriptDir "../apps") } 44 | 45 | 46 | # Configure the Runtimes we're going to use in testing. The actual runtime doesn't matter since we're only testing 47 | # that dnvm can find it, download it and unpack it successfully. We do run an app in the runtime to do that sanity 48 | # test, but all we care about in these tests is that the app executes. 49 | #$env:DNX_FEED = "https://www.myget.org/F/aspnetrelease/api/v2" 50 | #NOTE: This should be set back to release once we have non windows DNX on that feed. 51 | $env:DNX_FEED = "https://nuget.org/api/v2/" 52 | $TestRuntimeVersion = "1.0.0-beta7" 53 | $specificNupkgUrl = "$($env:DNX_FEED)/package/dnx-coreclr-win-x64/$TestRuntimeVersion" 54 | $specificNupkgHash = "AvYCzI6R94VSFfzrLF79T9bPQXHjWLB73BwSNJkxOYA=" 55 | $specificNupkgName = "dnx-coreclr-win-x64.$TestRuntimeVersion.nupkg" 56 | $specificNuPkgFxName = "Asp.Net,Version=v5.0" 57 | 58 | # Set up context 59 | $CommandPath = $TargetPath 60 | 61 | # Create test working directory 62 | if(Test-Path "$TestWorkingDir\$RuntimeFolderName") { 63 | Write-Banner "Wiping old test working area" 64 | del -rec -for "$TestWorkingDir\$RuntimeFolderName" 65 | } 66 | if(Test-Path "$TestWorkingGlobalDir\$RuntimeFolderName") { 67 | Write-Banner "Wiping old global test working area" 68 | del -rec -for "$TestWorkingGlobalDir\$RuntimeFolderName" 69 | } 70 | 71 | if(!(Test-Path $TestWorkingDir)) { 72 | mkdir $TestWorkingDir | Out-Null 73 | } 74 | if(!(Test-Path $TestWorkingGlobalDir)) { 75 | mkdir $TestWorkingGlobalDir | Out-Null 76 | } 77 | 78 | # Import the module and set up test environment 79 | Import-Module "$PesterPath\Pester.psm1" 80 | 81 | # Turn on Debug logging if requested 82 | if($Debug) { 83 | $DebugPreference = "Continue" 84 | $VerbosePreference = "Continue" 85 | } 86 | 87 | # Unset KRE_HOME for the test 88 | $oldKreHome = $env:DNX_HOME 89 | Remove-EnvVar DNX_HOME 90 | 91 | # Unset KRE_TRACE for the test 92 | Remove-EnvVar DNX_TRACE 93 | 94 | # Unset PATH for the test 95 | Remove-EnvVar PATH 96 | 97 | # Set up the user/global install directories to be inside the test work area 98 | $UserPath = "$TestWorkingDir\$RuntimeFolderName" 99 | $GlobalPath = "$TestWorkingGlobalDir\$RuntimeFolderName" 100 | $env:DNX_HOME="$($UserPath);$($GlobalPath)" 101 | $env:DNX_USER_HOME=$UserPath 102 | $env:DNX_GLOBAL_HOME=$GlobalPath 103 | mkdir $UserPath | Out-Null 104 | 105 | # Helper function to run dnvm and capture stuff. 106 | function __dnvmtest_run { 107 | $oldWP = $WarningPreference 108 | $WarningPreference = "SilentlyContinue" 109 | 110 | 111 | $Global:__dnvmtest_out = $null 112 | $Global:__dnvmtest_exit = $null 113 | $__TestWriteTo = "__dnvmtest_out" 114 | try { 115 | & $CommandPath @args 116 | $Global:__dnvmtest_exit = $LASTEXITCODE 117 | } catch { 118 | $Global:__dnvmtest_err = $_ 119 | } 120 | 121 | $WarningPreference = $oldWP 122 | } 123 | 124 | # Fetch a nupkg to use for the 'dnvm install ' scenario 125 | Write-Banner "Fetching test prerequisites" 126 | 127 | $downloadDir = Join-Path $TestWorkingDir "downloads" 128 | if(!(Test-Path $downloadDir)) { mkdir $downloadDir | Out-Null } 129 | $specificNupkgPath = Join-Path $downloadDir $specificNupkgName 130 | 131 | # If the test package exists 132 | if(Test-Path $specificNupkgPath) { 133 | # Test it against the expected hash 134 | if((Get-FileHash $specificNupkgPath) -ne $specificNupkgHash) { 135 | # Failed to match, kill it with fire! 136 | Write-Host "Test prerequisites are corrupt, redownloading." 137 | rm -for $specificNupkgPath 138 | } 139 | } 140 | 141 | # Check if the the test package exists again (since we might have deleted it above) 142 | if(!(Test-Path $specificNupkgPath)) { 143 | # It doesn't, redownload it 144 | $wc = New-Object System.Net.WebClient 145 | $wc.DownloadFile($specificNupkgUrl, $specificNupkgPath) 146 | 147 | # Test it against the expected hash 148 | $actualHash = (Get-FileHash $specificNupkgPath) 149 | if($actualHash -ne $specificNupkgHash) { 150 | # Failed to match, we downloaded a corrupt package?? 151 | throw "Test prerequisite $specificNupkgUrl failed to download. The hash '$actualHash' does not match the expected value." 152 | } 153 | } 154 | 155 | # Run the tests! 156 | # Powershell complains if we pass null in for -OutputFile :( 157 | Write-Banner "Running Pester Tests in $TestsPath" 158 | if($OutputFile) { 159 | $result = Invoke-Pester ` 160 | -Path $TestsPath ` 161 | -TestName $TestName ` 162 | -Tag $Tag ` 163 | -Strict:$Strict ` 164 | -Quiet:$Quiet ` 165 | -OutputFile $OutputFile ` 166 | -OutputFormat $OutputFormat ` 167 | -PassThru 168 | } else { 169 | $result = Invoke-Pester ` 170 | -Path $TestsPath ` 171 | -TestName $TestName ` 172 | -Tag $Tag ` 173 | -Strict:$Strict ` 174 | -Quiet:$Quiet ` 175 | -PassThru 176 | } 177 | 178 | function TeamCityEscape($str) { 179 | if($str) { 180 | $str.Replace("|", "||").Replace("'", "|'").Replace("`n", "|n").Replace("`r", "|r").Replace("[", "|[").Replace("]", "|]") 181 | } 182 | } 183 | 184 | # Generate TeamCity Output 185 | if($TeamCity) { 186 | Write-Host "##teamcity[testSuiteStarted name='$CommandName.ps1 on PSv$($Host.Version.Major)']" 187 | $result.TestResult | Group-Object Describe | ForEach-Object { 188 | $describe = TeamCityEscape $_.Name 189 | Write-Host "##teamcity[testSuiteStarted name='$describe']" 190 | $_.Group | Group-Object Context | ForEach-Object { 191 | $context = TeamCityEscape $_.Name 192 | Write-Host "##teamcity[testSuiteStarted name='$context']" 193 | $_.Group | ForEach-Object { 194 | $name = "It $(TeamCityEscape $_.Name)" 195 | $message = TeamCityEscape $_.FailureMessage 196 | Write-Host "##teamcity[testStarted name='$name']" 197 | switch ($_.Result) { 198 | Skipped 199 | { 200 | Write-Host "##teamcity[testIgnored name='$name' message='$message']" 201 | } 202 | Pending 203 | { 204 | Write-Host "##teamcity[testIgnored name='$name' message='$message']" 205 | } 206 | Failed 207 | { 208 | Write-Host "##teamcity[testFailed name='$name' message='$message' details='$(TeamCityEscape $_.StackTrace)']" 209 | } 210 | } 211 | Write-Host "##teamcity[testFinished name='$name']" 212 | } 213 | Write-Host "##teamcity[testSuiteFinished name='$context']" 214 | } 215 | Write-Host "##teamcity[testSuiteFinished name='$describe']" 216 | } 217 | Write-Host "##teamcity[testSuiteFinished name='$CommandName.ps1']" 218 | } 219 | 220 | # Set the exit code! 221 | $host.SetShouldExit($result.FailedCount) 222 | -------------------------------------------------------------------------------- /test/ps1/tests/Alias.Tests.ps1: -------------------------------------------------------------------------------- 1 | # Ensure a Runtime has been installed (if the other tests ran first, we're good) 2 | __dnvmtest_run install $TestRuntimeVersion -arch "x86" -r "CLR" 3 | 4 | $notRealRuntimeVersion = "0.0.1-notarealruntime" 5 | 6 | $runtimeName = GetRuntimeName "CLR" "x86" 7 | $notRealRuntimeName = GetRuntimeName "CLR" "x86" $notRealRuntimeVersion 8 | 9 | $testAlias = "alias_test_" + [Guid]::NewGuid().ToString("N") 10 | $testDefaultAlias = "alias_testDefault_" + [Guid]::NewGuid().ToString("N") 11 | $notRealAlias = "alias_notReal_" + [Guid]::NewGuid().ToString("N") 12 | $bogusAlias = "alias_bogus_" + [Guid]::NewGuid().ToString("N") 13 | 14 | Describe "alias" -Tag "alias" { 15 | Context "When defining an alias for a Runtime that exists" { 16 | __dnvmtest_run alias $testAlias $TestRuntimeVersion -x86 -r CLR | Out-Null 17 | 18 | It "writes the alias file" { 19 | "$UserPath\alias\$testAlias.txt" | Should Exist 20 | cat "$UserPath\alias\$testAlias.txt" | Should Be $runtimeName 21 | } 22 | } 23 | 24 | Context "When defining an alias for a Runtime with no arch or clr parameters" { 25 | __dnvmtest_run alias $testDefaultAlias $TestRuntimeVersion | Out-Null 26 | 27 | It "writes the x86/CLR variant to the alias file" { 28 | "$UserPath\alias\$testDefaultAlias.txt" | Should Exist 29 | cat "$UserPath\alias\$testDefaultAlias.txt" | Should Be $runtimeName 30 | } 31 | } 32 | 33 | Context "When defining an alias for a Runtime that does not exist" { 34 | __dnvmtest_run alias $notRealAlias $notRealRuntimeVersion -x86 -r CLR | Out-Null 35 | 36 | It "writes the alias file" { 37 | "$UserPath\alias\$notRealAlias.txt" | Should Exist 38 | } 39 | } 40 | 41 | Context "When displaying an alias" { 42 | __dnvmtest_run alias $testAlias | Out-Null 43 | It "outputs the value of the alias" { 44 | $__dnvmtest_out.Trim() | Should Be "Alias '$testAlias' is set to '$runtimeName'" 45 | } 46 | } 47 | 48 | Context "When aliasing a full package name" { 49 | __dnvmtest_run alias "alias_fullname_test" $runtimeName | Out-Null 50 | 51 | It "correctly writes the alias" { 52 | "$UserPath\alias\alias_fullname_test.txt" | Should Exist 53 | cat "$UserPath\alias\alias_fullname_test.txt" | Should Be $runtimeName 54 | } 55 | } 56 | 57 | Context "When given an non-existant alias" { 58 | __dnvmtest_run alias $bogusAlias | Out-Null 59 | 60 | It "outputs an error" { 61 | $__dnvmtest_out.Trim() | Should Be "Alias does not exist: '$bogusAlias'" 62 | } 63 | 64 | It "returns a non-zero exit code" { 65 | $__dnvmtest_exit | Should Not Be 0 66 | } 67 | } 68 | 69 | Context "When displaying all aliases" { 70 | $allAliases = __dnvmtest_run alias | Out-String 71 | 72 | It "lists all aliases in the alias files" { 73 | dir "$UserPath\alias\*.txt" | ForEach-Object { 74 | $alias = [Regex]::Escape([IO.Path]::GetFileNameWithoutExtension($_.Name)) 75 | 76 | # On some consoles, the value of the alias gets cut off, so don't require it in the assertion. 77 | # Instead, we just test the short prefix 78 | $allAliases | Should Match ".*alias_.*" 79 | } 80 | } 81 | } 82 | 83 | Context "When removing an alias that does not exist" { 84 | __dnvmtest_run alias -d $bogusAlias | Out-Null 85 | 86 | It "outputs an error" { 87 | $__dnvmtest_out.Trim() | Should Be "Cannot remove alias '$bogusAlias'. It does not exist." 88 | } 89 | 90 | It "returns a non-zero exit code" { 91 | $__dnvmtest_exit | Should Not Be 0 92 | } 93 | } 94 | 95 | Context "When removing an alias that does exist" { 96 | __dnvmtest_run alias -d $testAlias | Out-Null 97 | 98 | It "removes the alias file" { 99 | "$UserPath\alias\$testAlias.txt" | Should Not Exist 100 | } 101 | } 102 | 103 | Context "When aliasing global dnx" { 104 | $runtimeName = GetRuntimeName "CLR" "x86" 105 | if(Test-Path $UserPath\runtimes\$runtimeName) { del -rec -for $UserPath\runtimes\$runtimeName } 106 | __dnvmtest_run install $TestRuntimeVersion -arch x86 -r "CLR" -g | Out-Null 107 | __dnvmtest_run alias globalAlias $TestRuntimeVersion | Out-Null 108 | 109 | It "keeps alias local" { 110 | "$UserPath\alias\globalAlias.txt" | Should Exist 111 | } 112 | 113 | It "references global installed dnx" { 114 | __dnvmtest_run use globalAlias | Out-Null 115 | $__dnvmtest_out.Trim() | Should Be "Adding $GlobalPath\runtimes\$runtimeName\bin to process PATH" 116 | } 117 | 118 | if(Test-Path $GlobalPath\runtimes\$runtimeName) { del -rec -for $GlobalPath\runtimes\$runtimeName } 119 | } 120 | } 121 | -------------------------------------------------------------------------------- /test/ps1/tests/EntryPoint.Tests.ps1: -------------------------------------------------------------------------------- 1 | Describe "entrypoint" -Tag "entrypoint" { 2 | __dnvmtest_run install $TestRuntimeVersion | Out-Null 3 | 4 | Context "When an invalid command is specified" { 5 | It "returns exit code and displays help" { 6 | __dnvmtest_run sdfjklsdfljkasdfjklasdfjkl | Out-Null 7 | $__dnvmtest_exit | Should Be 1002 8 | $__dnvmtest_out | Should Match "usage:" 9 | } 10 | } 11 | Context "When no arguments are provided" { 12 | It "returns exit code and displays help" { 13 | __dnvmtest_run | Out-Null 14 | $__dnvmtest_exit | Should Be 1003 15 | $__dnvmtest_out | Should Match "usage:" 16 | } 17 | } 18 | 19 | del -rec -for $UserPath\runtimes\ 20 | } 21 | -------------------------------------------------------------------------------- /test/ps1/tests/Install.Tests.ps1: -------------------------------------------------------------------------------- 1 | function DefineInstallTests($clr, $arch, $os) { 2 | $runtimeHome = $UserPath 3 | $alias = "install_test_$arch_$clr" 4 | 5 | if($clr -eq "CoreCLR") { 6 | $fxName = "Asp.NetCore,Version=v5.0" 7 | } else { 8 | $fxName = "Asp.Net,Version=v5.0" 9 | } 10 | 11 | $runtimeName = GetRuntimeName $clr $arch -OS:$os 12 | $runtimeRoot = "$runtimeHome\runtimes\$runtimeName" 13 | 14 | Context "When installing $clr on $arch for $os" { 15 | It "downloads and unpacks a runtime" { 16 | # Never crossgen in the automated tests since it takes a loooong time :(. 17 | if($clr -eq "mono") { 18 | __dnvmtest_run install $TestRuntimeVersion -arch $arch -r $clr -os $os -nonative | Out-Null 19 | } else { 20 | __dnvmtest_run install $TestRuntimeVersion -arch $arch -r $clr -alias $alias -os $os -nonative | Out-Null 21 | } 22 | $__dnvmtest_exit | Should Be 0 23 | } 24 | 25 | It "installs the runtime into the user directory" { 26 | $runtimeRoot | Should Exist 27 | } 28 | 29 | #We want to verify that non windows runtimes install, but they will not be able to restore or run an app. 30 | if($os -eq "win") { 31 | It "can restore packages for the TestApp sample" { 32 | pushd "$TestAppsDir\TestApp" 33 | try { 34 | & "$runtimeRoot\bin\$PackageManagerName" restore 35 | } finally { 36 | popd 37 | } 38 | } 39 | 40 | It "can run the TestApp sample" { 41 | pushd "$TestAppsDir\TestApp" 42 | try { 43 | "$runtimeRoot\bin\$RuntimeHostName" | Should Exist 44 | 45 | $output = & "$runtimeRoot\bin\$RuntimeHostName" run 46 | $LASTEXITCODE | Should Be 0 47 | $fullOutput = [String]::Join("`r`n", $output) 48 | $output | ForEach-Object { Write-Verbose $_ } 49 | 50 | $fullOutput | Should Match "Runtime is sane!" 51 | } finally { 52 | popd 53 | } 54 | } 55 | 56 | It "assigned the requested alias" { 57 | "$UserPath\alias\$alias.txt" | Should Exist 58 | "$UserPath\alias\$alias.txt" | Should ContainExactly $runtimeName 59 | } 60 | 61 | It "uses the new Runtime" { 62 | GetActiveRuntimeName $runtimeHome | Should Be "$runtimeName" 63 | } 64 | } 65 | } 66 | } 67 | 68 | Describe "install" -Tag "install" { 69 | DefineInstallTests "CLR" "x86" "win" 70 | DefineInstallTests "CLR" "x64" "win" 71 | DefineInstallTests "CoreCLR" "x86" "win" 72 | DefineInstallTests "CoreCLR" "x64" "win" 73 | DefineInstallTests "CoreCLR" "x64" "linux" 74 | DefineInstallTests "CoreCLR" "x64" "darwin" 75 | DefineInstallTests "Mono" "x86" "linux" 76 | 77 | Context "When installing a non-existant Runtime version" { 78 | __dnvmtest_run install "0.0.1-thisisnotarealruntime" | Out-Null 79 | 80 | It "returns a non-zero exit code" { 81 | $__dnvmtest_exit | Should Not Be 0 82 | } 83 | } 84 | 85 | Context "When no architecture is specified" { 86 | __dnvmtest_run install $TestRuntimeVersion -r CLR | Out-Null 87 | $runtimeName = GetRuntimeName -clr CLR -arch x86 88 | 89 | It "uses x86" { 90 | ($__dnvmtest_out.Trim() -like "*'$runtimeName' is already installed in $UserPath\runtimes\$runtimeName.`r`nAdding $UserPath\runtimes\$runtimeName\bin to process PATH*") | Should Be $true 91 | } 92 | } 93 | 94 | Context "When no clr is specified" { 95 | __dnvmtest_run install $TestRuntimeVersion -arch x86 | Out-Null 96 | $runtimeName = GetRuntimeName -clr CLR -arch x86 97 | 98 | It "uses Desktop CLR" { 99 | ($__dnvmtest_out.Trim() -like "*'$runtimeName' is already installed in $UserPath\runtimes\$runtimeName.`r`nAdding $UserPath\runtimes\$runtimeName\bin to process PATH*") | Should Be $true 100 | } 101 | } 102 | 103 | Context "When neither architecture nor clr is specified" { 104 | __dnvmtest_run install $TestRuntimeVersion | Out-Null 105 | $runtimeName = GetRuntimeName -clr CLR -arch x86 106 | 107 | It "uses x86/Desktop" { 108 | ($__dnvmtest_out.Trim() -like "*'$runtimeName' is already installed in $UserPath\runtimes\$runtimeName.`r`nAdding $UserPath\runtimes\$runtimeName\bin to process PATH*") | Should Be $true 109 | } 110 | } 111 | 112 | Context "When installing an alias" { 113 | __dnvmtest_run install $TestRuntimeVersion -Alias "test_install_alias" | Out-Null 114 | $runtimeName = GetRuntimeName "CoreCLR" "x86" 115 | $runtimePath = "$UserPath\runtimes\$runtimeName" 116 | if(Test-Path $runtimePath) { del -rec -for $runtimePath } 117 | $runtimePath | Should Not Exist 118 | 119 | It "downloads the same version but with the specified runtime" { 120 | __dnvmtest_run install "test_install_alias" -r coreclr -nonative | Out-Null 121 | $runtimePath | Should Exist 122 | } 123 | } 124 | 125 | Context "When installing latest" { 126 | $previous = @(dir "$UserPath\runtimes" | select -ExpandProperty Name) 127 | It "downloads a runtime" { 128 | __dnvmtest_run install latest -arch x86 -r CLR | Out-Null 129 | } 130 | # TODO: Check that it actually installed the latest? 131 | } 132 | 133 | Context "When installing latest linux package" { 134 | $previous = @(dir "$UserPath\runtimes" | select -ExpandProperty Name) 135 | It "downloads a runtime" { 136 | __dnvmtest_run install latest -arch x86 -r mono -OS Linux | Out-Null 137 | } 138 | 139 | It "returns a zero exit code" { 140 | $__dnvmtest_exit | Should Be 0 141 | } 142 | } 143 | 144 | Context "When installing latest darwin package" { 145 | $previous = @(dir "$UserPath\runtimes" | select -ExpandProperty Name) 146 | It "downloads a runtime" { 147 | __dnvmtest_run install latest -arch x86 -r mono -OS Darwin | Out-Null 148 | } 149 | 150 | It "returns a zero exit code" { 151 | $__dnvmtest_exit | Should Be 0 152 | } 153 | } 154 | 155 | Context "When installing latest darwin coreclr" { 156 | $previous = @(dir "$UserPath\runtimes" | select -ExpandProperty Name) 157 | It "downloads a runtime" { 158 | __dnvmtest_run install latest -arch x64 -r CoreCLR -OS Darwin | Out-Null 159 | } 160 | 161 | It "returns a zero exit code" { 162 | $__dnvmtest_exit | Should Be 0 163 | } 164 | } 165 | 166 | Context "When installing an already-installed runtime" { 167 | # Clear active runtime 168 | __dnvmtest_run use none | Out-Null 169 | 170 | $runtimeName = GetRuntimeName "CLR" "x86" 171 | $runtimePath = "$UserPath\runtimes\$runtimeName" 172 | It "ensures the runtime is installed" { 173 | __dnvmtest_run install $TestRuntimeVersion -arch x86 -r "CLR" | Out-Null 174 | ($__dnvmtest_out.Trim() -like "*'$runtimeName' is already installed in $UserPath\runtimes\$runtimeName.`r`nAdding $UserPath\runtimes\$runtimeName\bin to process PATH*") | Should Be $true 175 | $runtimePath | Should Exist 176 | } 177 | } 178 | 179 | Context "When installing a specific package" { 180 | $name = [IO.Path]::GetFileNameWithoutExtension($specificNupkgName) 181 | $runtimeRoot = "$UserPath\runtimes\$name" 182 | 183 | It "unpacks the runtime" { 184 | __dnvmtest_run install $specificNupkgPath | Out-Null 185 | } 186 | 187 | It "installs the runtime into the user directory" { 188 | $runtimeRoot | Should Exist 189 | } 190 | } 191 | 192 | Context "When installing global" { 193 | $runtimeName = GetRuntimeName "CLR" "x86" 194 | if(Test-Path $UserPath\runtimes\$runtimeName) { del -rec -for $UserPath\runtimes\$runtimeName } 195 | if(Test-Path $GlobalPath\runtimes\$runtimeName) { del -rec -for $GlobalPath\runtimes\$runtimeName } 196 | 197 | It "installs runtime to global install location" { 198 | __dnvmtest_run install $TestRuntimeVersion -arch x86 -r "CLR" -g | Out-Null 199 | 200 | ($__dnvmtest_out.Trim() -like "*Installing to $GlobalPath\runtimes\$runtimeName`r`nAdding $GlobalPath\runtimes\$runtimeName\bin to process PATH*") | Should Be $true 201 | "$GlobalPath\runtimes\$runtimeName" | Should Exist 202 | } 203 | 204 | del -rec -for $GlobalPath\runtimes\$runtimeName 205 | } 206 | } 207 | -------------------------------------------------------------------------------- /test/ps1/tests/List.Tests.ps1: -------------------------------------------------------------------------------- 1 | # Ensure a Runtime has been installed (if the other tests ran first, we're good) 2 | __dnvmtest_run install $TestRuntimeVersion -arch "x86" -r "CLR" 3 | 4 | $foobarRuntime = "foo" 5 | $foobarOS = "bar" 6 | $foobarVersion = "1.0.0-beta7" 7 | $foobarAlias = "foobar" 8 | $foobarAliasRuntime = "$foobarRuntime-$foobarOS.$foobarVersion" 9 | 10 | # Clean aliases (if exist) and create a orphaned alias and a default alias 11 | if(Test-Path $UserPath\alias) { 12 | Get-ChildItem $UserPath\alias | ForEach-Object { Remove-Item $_.FullName } 13 | } 14 | else 15 | { 16 | New-Item -ItemType directory -Path $UserPath\alias 17 | } 18 | New-Item -Force -Path $($UserPath + "\alias\" + $foobarAlias + ".txt") -Value $foobarAliasRuntime -ItemType File 19 | New-Item -Force -Path $($UserPath + "\alias\default.txt") -Value $("dnx-clr-win-x86." + $TestRuntimeVersion) -ItemType File 20 | 21 | Describe "list" -Tag "list" { 22 | Context "When list contains an orphaned alias" { 23 | $runtimes = (__dnvmtest_run list -PassThru) 24 | 25 | $orphan = $runtimes | Where { $_.Alias -like "*$foobarAlias*" } 26 | $default = $runtimes | Where { $_.Alias -like "*default*" } 27 | 28 | It "shows orphaned alias correctly" { 29 | $orphan | Should Not BeNullOrEmpty 30 | $orphan.Alias | Should Match "\(missing\)$" 31 | $orphan.Location | Should BeNullOrEmpty 32 | } 33 | 34 | It "shows non orphaned alias correctly" { 35 | $default | Should Not BeNullOrEmpty 36 | $default.Alias | Should Not Match "\(missing\)" 37 | $default.Location | Should Not BeNullOrEmpty 38 | } 39 | } 40 | 41 | Context "When list contains a global dnx" { 42 | $runtimeName = GetRuntimeName "CLR" "x86" 43 | if(Test-Path $UserPath\runtimes\$runtimeName) { del -rec -for $UserPath\runtimes\$runtimeName } 44 | if(Test-Path $GlobalPath\runtimes\$runtimeName) { del -rec -for $GlobalPath\runtimes\$runtimeName } 45 | __dnvmtest_run install $TestRuntimeVersion -arch x86 -r "CLR" -g | Out-Null 46 | 47 | $runtimes = (__dnvmtest_run list -PassThru -Detailed) 48 | It "shows location correctly" { 49 | $runtimes | Where { $_.Location -like "$GlobalPath\runtimes" } | Should Not BeNullOrEmpty 50 | } 51 | 52 | if(Test-Path $GlobalPath\runtimes\$runtimeName) { del -rec -for $GlobalPath\runtimes\$runtimeName } 53 | } 54 | } -------------------------------------------------------------------------------- /test/ps1/tests/RunAndExec.Tests.ps1: -------------------------------------------------------------------------------- 1 | Describe "run" -Tag "run" { 2 | __dnvmtest_run install $TestRuntimeVersion -r CLR | Out-Null 3 | 4 | Context "When a version is provided" { 5 | It "executes dnx with provides args" { 6 | __dnvmtest_run use none | Out-Null 7 | { Get-Command dnx -ErrorAction Stop } | Should Throw 8 | (__dnvmtest_run run $TestRuntimeVersion | Select-String -SimpleMatch "Microsoft .NET Execution environment CLR-x86-$TestRuntimeVersion") | Should Be $true 9 | $__dnvmtest_exit | Should Be 2 10 | } 11 | } 12 | 13 | Context "When an alias is provided" { 14 | It "executes dnx with provides args" { 15 | __dnvmtest_run alias "test_alias_run" $TestRuntimeVersion | Out-Null 16 | __dnvmtest_run use none | Out-Null 17 | { Get-Command dnx -ErrorAction Stop } | Should Throw 18 | (__dnvmtest_run run "test_alias_run" | Select-String -SimpleMatch "Microsoft .NET Execution environment CLR-x86-$TestRuntimeVersion") | Should Be $true 19 | $__dnvmtest_exit | Should Be 2 20 | } 21 | } 22 | } 23 | 24 | Describe "exec" -Tag "exec" { 25 | __dnvmtest_run install $TestRuntimeVersion -r CLR | Out-Null 26 | $runtimeName = GetRuntimeName "CLR" "x86" 27 | $runtimePath = "$UserPath\runtimes\$runtimeName" 28 | 29 | Context "When a version is provided" { 30 | It "executes the command with the expected dnx in path" { 31 | __dnvmtest_run use none | Out-Null 32 | { Get-Command dnx -ErrorAction Stop } | Should Throw 33 | (__dnvmtest_run exec $TestRuntimeVersion Get-Command dnx).Definition | Should Be "$runtimePath\bin\dnx.exe" 34 | } 35 | } 36 | 37 | Context "When an alias is provided" { 38 | It "executes the command with the expected dnx in path" { 39 | __dnvmtest_run alias "test_alias_exec" $TestRuntimeVersion 40 | __dnvmtest_run use none | Out-Null 41 | { Get-Command dnx -ErrorAction Stop } | Should Throw 42 | (__dnvmtest_run exec test_alias_exec Get-Command dnx).Definition | Should Be "$runtimePath\bin\dnx.exe" 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /test/ps1/tests/Uninstall.Tests.ps1: -------------------------------------------------------------------------------- 1 | function DefineUninstallTests($clr, $arch, $os) { 2 | $runtimeHome = $UserPath 3 | $alias = "uninstall_test_$arch_$clr" 4 | 5 | if($clr -eq "CoreCLR") { 6 | $fxName = "Asp.NetCore,Version=v5.0" 7 | } else { 8 | $fxName = "Asp.Net,Version=v5.0" 9 | } 10 | 11 | $runtimeName = GetRuntimeName $clr $arch -OS:$os 12 | $runtimeRoot = "$runtimeHome\runtimes\$runtimeName" 13 | 14 | Context "When uninstalling $clr on $arch for $os" { 15 | It "removes the runtime folder" { 16 | # Never crossgen in the automated tests since it takes a loooong time :(. 17 | if($clr -eq "mono") { 18 | __dnvmtest_run install $TestRuntimeVersion -arch $arch -r $clr -os $os -nonative | Out-Null 19 | } else { 20 | __dnvmtest_run install $TestRuntimeVersion -arch $arch -r $clr -alias $alias -os $os -nonative | Out-Null 21 | } 22 | 23 | $runtimeRoot | Should Exist 24 | __dnvmtest_run uninstall $TestRuntimeVersion -arch $arch -r $clr -os $os | Out-Null 25 | $runtimeRoot | Should Not Exist 26 | 27 | $__dnvmtest_exit | Should Be 0 28 | } 29 | } 30 | } 31 | 32 | Describe "uninstall" -Tag "uninstall" { 33 | DefineUninstallTests "CLR" "x86" "win" 34 | DefineUninstallTests "CLR" "x64" "win" 35 | DefineUninstallTests "CoreCLR" "x86" "win" 36 | DefineUninstallTests "CoreCLR" "x64" "win" 37 | DefineUninstallTests "CoreCLR" "x64" "linux" 38 | DefineUninstallTests "CoreCLR" "x64" "darwin" 39 | DefineUninstallTests "Mono" "x86" "linux" 40 | 41 | Context "When uninstalling a runtime that isn't installed" { 42 | # Clear active runtime 43 | __dnvmtest_run use none | Out-Null 44 | 45 | $runtimeName = GetRuntimeName "CLR" "x86" 46 | $runtimePath = "$UserPath\runtimes\$runtimeName" 47 | __dnvmtest_run uninstall $TestRuntimeVersion -arch x86 -r "CLR" | Out-Null 48 | 49 | It "says runtime is not installed" { 50 | __dnvmtest_run uninstall $TestRuntimeVersion -arch x86 -r "CLR" | Out-Null 51 | ($__dnvmtest_out.Trim() -like "*'$runtimeName' is not installed*") | Should Be $true 52 | $runtimePath | Should Not Exist 53 | } 54 | } 55 | 56 | Context "When uninstalling" { 57 | $runtimeName = GetRuntimeName "CLR" "x86" 58 | if(Test-Path $UserPath\runtimes\$runtimeName) { del -rec -for $UserPath\runtimes\$runtimeName } 59 | if(Test-Path $GlobalPath\runtimes\$runtimeName) { del -rec -for $GlobalPath\runtimes\$runtimeName } 60 | 61 | __dnvmtest_run install $TestRuntimeVersion -arch x86 -r "CLR" -g | Out-Null 62 | It "it can uninstall a global runtime" { 63 | 64 | __dnvmtest_run uninstall $TestRuntimeVersion -arch x86 -r "CLR" 65 | ($__dnvmtest_out.Trim() -like "*Removed '$GlobalPath\runtimes\$runtimeName'*") | Should Be $true 66 | "$GlobalPath\runtimes\$runtimeName" | Should Not Exist 67 | } 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /test/ps1/tests/Use.Tests.ps1: -------------------------------------------------------------------------------- 1 | # Ensure some KREs have been installed (if the other tests ran first, we're good) 2 | __dnvmtest_run install $TestRuntimeVersion -arch "x86" -r "CLR" 3 | __dnvmtest_run install $TestRuntimeVersion -arch "x64" -r "CoreCLR" 4 | 5 | $notRealRuntimeVersion = "0.0.1-notarealruntime" 6 | 7 | $runtimeName = GetRuntimeName "CLR" "x86" 8 | $notRealRuntimeName = GetRuntimeName "CLR" "x86" $notRealRuntimeVersion 9 | 10 | $testAlias = "use_test_" + [Guid]::NewGuid().ToString("N") 11 | $notRealAlias = "use_notReal_" + [Guid]::NewGuid().ToString("N") 12 | $bogusAlias = "use_bogus_" + [Guid]::NewGuid().ToString("N") 13 | 14 | __dnvmtest_run alias $testAlias $TestRuntimeVersion -arch "x86" -r "CLR" | Out-Null 15 | __dnvmtest_run use none | Out-Null 16 | 17 | Describe "use" -Tag "use" { 18 | Context "When use-ing without a clr or architecture" { 19 | __dnvmtest_run use $TestRuntimeVersion | Out-Null 20 | $runtimeName = GetRuntimeName -clr CLR -arch x86 21 | 22 | It "uses x86/CLR variant" { 23 | GetActiveRuntimeName | Should Be $runtimeName 24 | } 25 | 26 | __dnvmtest_run use none | Out-Null 27 | } 28 | 29 | Context "When use-ing a runtime" { 30 | __dnvmtest_run use $TestRuntimeVersion | Out-Null 31 | $runtimeName = GetRuntimeName -clr CLR -arch x86 32 | 33 | It "puts $PackageManagerName on the PATH" { 34 | $cmd = Get-Command $PackageManagerName -ErrorAction SilentlyContinue 35 | $cmd | Should Not BeNullOrEmpty 36 | $cmd.Definition | Should Be (Convert-Path "$UserPath\runtimes\$runtimeName\bin\$PackageManagerName") 37 | } 38 | 39 | It "puts $RuntimeHostName on the PATH" { 40 | $cmd = Get-Command $RuntimeHostName -ErrorAction SilentlyContinue 41 | $cmd | Should Not BeNullOrEmpty 42 | $cmd.Definition | Should Be (Convert-Path "$UserPath\runtimes\$runtimeName\bin\$RuntimeHostName") 43 | } 44 | 45 | __dnvmtest_run use none | Out-Null 46 | } 47 | 48 | Context "When use-ing an alias" { 49 | __dnvmtest_run use $testAlias | Out-Null 50 | 51 | It "puts $PackageManagerName on the PATH" { 52 | $cmd = Get-Command $PackageManagerName -ErrorAction SilentlyContinue 53 | $cmd | Should Not BeNullOrEmpty 54 | $cmd.Definition | Should Be (Convert-Path "$UserPath\runtimes\$runtimeName\bin\$PackageManagerName") 55 | } 56 | 57 | It "puts $RuntimeHostName on the PATH" { 58 | $cmd = Get-Command $RuntimeHostName -ErrorAction SilentlyContinue 59 | $cmd | Should Not BeNullOrEmpty 60 | $cmd.Definition | Should Be (Convert-Path "$UserPath\runtimes\$runtimeName\bin\$RuntimeHostName") 61 | } 62 | } 63 | 64 | Context "When use-ing an ailas, overriding -arch and -r" { 65 | __dnvmtest_run use $testAlias -arch "x64" -r "CoreCLR" | Out-Null 66 | $runtimeName = GetRuntimeName -clr CoreCLR -arch x64 67 | 68 | It "uses x64/CoreCLR variant" { 69 | GetActiveRuntimeName | Should Be $runtimeName 70 | } 71 | 72 | __dnvmtest_run use none | Out-Null 73 | } 74 | 75 | Context "When use-ing 'none'" { 76 | __dnvmtest_run use $TestRuntimeVersion | Out-Null 77 | 78 | __dnvmtest_run use none | Out-Null 79 | 80 | It "removes the Runtime from the PATH" { 81 | GetRuntimesOnPath | Should BeNullOrEmpty 82 | } 83 | 84 | It "removes $PackageManagerName from the PATH" { 85 | (Get-Command $PackageManagerName -ErrorAction SilentlyContinue) | Should BeNullOrEmpty 86 | } 87 | 88 | It "removes $RuntimeHostName from the PATH" { 89 | (Get-Command $RuntimeHostName -ErrorAction SilentlyContinue) | Should BeNullOrEmpty 90 | } 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /test/sh/chester: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | VERSION="0.1.0" 3 | 4 | # A bunch of helper functions and variables! 5 | 6 | if [ "$NO_COLOR" != "1" ]; then 7 | # ANSI Colors 8 | RCol='\e[0m' # Text Reset 9 | 10 | # Regular Bold Underline High Intensity BoldHigh Intens Background High Intensity Backgrounds 11 | Bla='\e[0;30m'; BBla='\e[1;30m'; UBla='\e[4;30m'; IBla='\e[0;90m'; BIBla='\e[1;90m'; On_Bla='\e[40m'; On_IBla='\e[0;100m'; 12 | Red='\e[0;31m'; BRed='\e[1;31m'; URed='\e[4;31m'; IRed='\e[0;91m'; BIRed='\e[1;91m'; On_Red='\e[41m'; On_IRed='\e[0;101m'; 13 | Gre='\e[0;32m'; BGre='\e[1;32m'; UGre='\e[4;32m'; IGre='\e[0;92m'; BIGre='\e[1;92m'; On_Gre='\e[42m'; On_IGre='\e[0;102m'; 14 | Yel='\e[0;33m'; BYel='\e[1;33m'; UYel='\e[4;33m'; IYel='\e[0;93m'; BIYel='\e[1;93m'; On_Yel='\e[43m'; On_IYel='\e[0;103m'; 15 | Blu='\e[0;34m'; BBlu='\e[1;34m'; UBlu='\e[4;34m'; IBlu='\e[0;94m'; BIBlu='\e[1;94m'; On_Blu='\e[44m'; On_IBlu='\e[0;104m'; 16 | Pur='\e[0;35m'; BPur='\e[1;35m'; UPur='\e[4;35m'; IPur='\e[0;95m'; BIPur='\e[1;95m'; On_Pur='\e[45m'; On_IPur='\e[0;105m'; 17 | Cya='\e[0;36m'; BCya='\e[1;36m'; UCya='\e[4;36m'; ICya='\e[0;96m'; BICya='\e[1;96m'; On_Cya='\e[46m'; On_ICya='\e[0;106m'; 18 | Whi='\e[0;37m'; BWhi='\e[1;37m'; UWhi='\e[4;37m'; IWhi='\e[0;97m'; BIWhi='\e[1;97m'; On_Whi='\e[47m'; On_IWhi='\e[0;107m'; 19 | fi 20 | 21 | INDENT=0 22 | INDENT_STRING=" " 23 | indent() { 24 | INDENT=$((INDENT+1)) 25 | } 26 | unindent() { 27 | INDENT=$((INDENT-1)) 28 | } 29 | 30 | log_lines() { 31 | local level="$1" 32 | shift 33 | echo "$@" | while IFS= read -r line; do 34 | log "$level" "$line" 35 | done 36 | } 37 | 38 | log() { 39 | local level="$1" 40 | shift 41 | local message="$@" 42 | 43 | local color="" 44 | case "$level" in 45 | warn) color="${BIYel}";; 46 | error) color="${BIRed}";; 47 | info) color="${BIGre}";; 48 | trace) color="${BBla}";; 49 | esac 50 | 51 | local indentation="" 52 | if [ "$INDENT" -ne "0" ]; then 53 | for i in $(seq 0 $INDENT); do 54 | local indentation="$indentation$INDENT_STRING" 55 | done 56 | fi 57 | 58 | local format="${color}%-5s${RCol}: $indentation%s\n" 59 | if [ $level == "trace" ]; then 60 | format="${color}%-5s${RCol}: $indentation${color}%s${RCol}\n" 61 | fi 62 | 63 | if [ $level == "error" ]; then 64 | printf "$format" "$level" "$message" 1>&2 65 | else 66 | printf "$format" "$level" "$message" 67 | fi 68 | } 69 | 70 | # Echo to stderr 71 | error() { 72 | log error $@ 73 | } 74 | 75 | info() { 76 | log info $@ 77 | } 78 | 79 | warn() { 80 | log warn $@ 81 | } 82 | 83 | die() { 84 | error $@ 85 | exit 1 86 | } 87 | 88 | tc_escape() { 89 | echo "$1" | sed "s/|/||/g" | sed "s/'/|'/g" 90 | } 91 | 92 | teamcity() { 93 | [ "$TEAMCITY" == "1" ] && echo "##teamcity[$1]" 94 | } 95 | 96 | verbose() { 97 | [ "$VERBOSE" == "1" ] && log trace $@ 98 | } 99 | 100 | path_of() { 101 | local CMD=$1 102 | type $CMD | sed "s/$CMD is //g" 103 | } 104 | 105 | has() { 106 | type "$1" > /dev/null 2>&1 107 | return $? 108 | } 109 | 110 | requires() { 111 | if ! has $1; then 112 | die "Missing required command: $1" 113 | fi 114 | } 115 | 116 | usage() { 117 | echo -en "${Pur}help ${RCol}: ${BWhi}Chester${RCol} v$VERSION - Testing tool for shell scripts 118 | ${Pur}help ${RCol}: ${Cya}Usage${RCol}: ${BWhi}$0${RCol} [${Yel}${RCol}][${Yel}${RCol}...] 119 | ${Pur}help ${RCol}: 120 | ${Pur}help ${RCol}: Recurses through files and directories found in the ${Yel}${RCol} list and runs executable files as tests. 121 | ${Pur}help ${RCol}: 122 | ${Pur}help ${RCol}: Chester is short for Shell Tester. Just roll with it. 123 | ${Pur}help ${RCol}: 124 | ${Pur}help ${RCol}: ${Cya}Options:${RCol} 125 | " 126 | 127 | FORMAT="${Pur}help ${RCol}: ${Yel}%-20b${RCol} %b\n" 128 | printf "$FORMAT" "-h" "Print this help message" 129 | printf "$FORMAT" "-t" "Report status using TeamCity-style status messages" 130 | printf "$FORMAT" "-v" "Report status using TeamCity-style status messages" 131 | printf "$FORMAT" "-s " "Run the tests in ${Yel}${RCol}, defaults to '/bin/sh'" 132 | printf "$FORMAT" "-n " "When writing TeamCity status message, use as the outer-most test suite name" 133 | } 134 | 135 | # Main entry point (after argument parsing) 136 | run_chester() { 137 | local testpaths="$1" 138 | 139 | # Recurse through each argument item 140 | for testpath in $testpaths; do 141 | run_test $testpath 142 | done 143 | } 144 | 145 | run_test() { 146 | local testpath="$1" 147 | 148 | # What kind of thing is testpath? 149 | if [ -f "$testpath" ]; then 150 | run_test_file "$testpath" 151 | elif [ -d "$testpath" ]; then 152 | run_test_dir "$testpath" 153 | else 154 | warn "Unknown test path: $testpath" 155 | fi 156 | } 157 | 158 | join_array() { 159 | local IFS="$1"; shift; echo "$*"; 160 | } 161 | 162 | run_test_file() { 163 | local testfile="$1" 164 | 165 | local test_name=$(echo "$testfile" | sed s/\.sh//g) 166 | local full_test_name="$(join_array "/" ${DIR_STACK[*]})/$test_name" 167 | local tc_test_name=$(tc_escape "$test_name") 168 | 169 | if [ ! -f "$testfile" ] || [ ! -x "$testfile" ]; then 170 | warn "? $test_name" 171 | teamcity "testIgnored name='$tc_test_name' message='file is not executable'" 172 | return 173 | fi 174 | 175 | teamcity "testStarted name='$tc_test_name' captureStandardOutput='true'" 176 | 177 | for dir in "${DIR_STACK[@]}"; do 178 | run_infra_script "$dir/before.sh" 179 | done 180 | 181 | out=$("$TEST_SHELL" "$testfile" 2>&1) 182 | exit_code="$?" 183 | if [ "$exit_code" -eq "0" ]; then 184 | SUCCEEDED+=("$full_test_name") 185 | 186 | info "✓ $test_name" 187 | if [ "$VERBOSE" == "1" ]; then 188 | indent 189 | log_lines "trace" "$out" 190 | unindent 191 | fi 192 | else 193 | FAILED+=("$full_test_name") 194 | 195 | error "✗ $test_name" 196 | indent 197 | log_lines error "$out" 198 | unindent 199 | 200 | teamcity "testFailed name='$tc_test_name'" 201 | fi 202 | 203 | for dir in "${DIR_STACK[@]}"; do 204 | run_infra_script "$dir/after.sh" 205 | done 206 | 207 | teamcity "testFinished name='$tc_test_name'" 208 | } 209 | 210 | is_test() { 211 | local testpath="$1" 212 | 213 | if [ "$testpath" == "before.sh" ] || [ "$testpath" == "before_all.sh" ] || [ "$testpath" == "after.sh" ] || [ "$testpath" == "after_all.sh" ]; then 214 | return 1 215 | fi 216 | } 217 | 218 | run_infra_script() { 219 | if [ -f "$1" ] && [ -x "$1" ]; then 220 | out=$("$1" 2>&1) 221 | if [ $? -ne "0" ]; then 222 | error "failed to run $(pwd)/$1" 223 | 224 | indent 225 | log_lines error "$out" 226 | unindent 227 | 228 | exit 1 229 | fi 230 | fi 231 | } 232 | 233 | declare -a DIR_STACK 234 | DIR_STACK_POINTER=0 235 | run_test_dir() { 236 | local testdir="$1" 237 | 238 | teamcity "testSuiteStarted name='$testdir'" 239 | 240 | info "$testdir/" 241 | 242 | # Push this dir onto the dir stack 243 | DIR_STACK[DIR_STACK_POINTER]="$1" 244 | DIR_STACK_POINTER=$((DIR_STACK_POINTER+1)) 245 | 246 | # Enter dir 247 | pushd "$testdir" >/dev/null 2>&1 248 | indent 249 | 250 | # Run before_all for the dir 251 | run_infra_script "./before_all.sh" 252 | 253 | for testpath in *; do 254 | if is_test $testpath; then 255 | run_test "$testpath" 256 | fi 257 | done 258 | 259 | # Run after_all for the dir 260 | run_infra_script "./after_all.sh" 261 | 262 | unindent 263 | popd >/dev/null 2>&1 264 | 265 | teamcity "testSuiteFinished name='$testdir'" 266 | 267 | # Pop this value off the dir stack 268 | DIR_STACK_POINTER=$((DIR_STACK_POINTER-1)) 269 | unset DIR_STACK[DIR_STACK_POINTER] 270 | } 271 | 272 | # Parse arguments 273 | while getopts tvs:hpn: opt; do 274 | case $opt in 275 | h) usage; exit 0;; 276 | t) TEAMCITY=1;; 277 | v) VERBOSE=1;; 278 | s) TEST_SHELL="$OPTARG";; 279 | p) REPORT=1;; 280 | n) SUITE_NAME="$OPTARG";; 281 | [?]) usage;; 282 | esac 283 | done 284 | 285 | # Shift out named arguments that were parsed by getopts 286 | shift $((OPTIND-1)) 287 | 288 | FAILED=() 289 | SUCCEEDED=() 290 | DIRS="$@" 291 | if [ -z "$DIRS" ]; then 292 | error "No test directories specified" 293 | usage 294 | exit 1 295 | fi 296 | 297 | [ -z "$TEAMCITY" ] && TEAMCITY=0 298 | [ -z "$VERBOSE" ] && VERBOSE=0 299 | [ -z "$REPORT" ] && REPORT=0 300 | [ -z "$TEST_SHELL" ] && TEST_SHELL="/bin/sh" 301 | 302 | [ ! -z "$SUITE_NAME" ] && teamcity "testSuiteStarted name='$SUITE_NAME'" 303 | run_chester "$DIRS" 304 | [ ! -z "$SUITE_NAME" ] && teamcity "testSuiteFinished name='$SUITE_NAME'" 305 | 306 | if [ "$REPORT" -eq "1" ]; then 307 | info "=== Test Results ===" 308 | fmt="%b : %s\n"; 309 | for ((i = 0; i < ${#SUCCEEDED[@]}; i++)); do 310 | testname="${SUCCEEDED[$i]}" 311 | printf "$fmt" "${BGre}pass${RCol}" "$testname" 312 | done 313 | for ((i = 0; i < ${#FAILED[@]}; i++)); do 314 | testname="${FAILED[$i]}" 315 | printf "$fmt" "${BRed}fail${RCol}" "$testname" 316 | done 317 | fi 318 | 319 | exit "${#FAILED[@]}" -------------------------------------------------------------------------------- /test/sh/common.sh: -------------------------------------------------------------------------------- 1 | # A bunch of helper functions and variables! 2 | 3 | # "Constants" 4 | _DNVM_BUILDNUMBER="{{BUILD_VERSION}}" 5 | _DNVM_RUNTIME_PACKAGE_NAME="dnx" 6 | _DNVM_RUNTIME_FRIENDLY_NAME=".NET Execution Environment" 7 | _DNVM_RUNTIME_SHORT_NAME="DNX" 8 | _DNVM_RUNTIME_FOLDER_NAME=".dnx" 9 | _DNVM_COMMAND_NAME="dnvm" 10 | _DNVM_VERSION_MANAGER_NAME=".NET Version Manager" 11 | _DNVM_DEFAULT_FEED="https://www.myget.org/F/aspnetvnext/api/v2" 12 | _DNVM_HOME_VAR_NAME="DNX_HOME" 13 | 14 | _DNVM_PACKAGE_MANAGER_NAME="dnu" 15 | _DNVM_RUNTIME_HOST_NAME="dnx" 16 | 17 | if [ "$NO_COLOR" != "1" ]; then 18 | # ANSI Colors 19 | RCol='\e[0m' # Text Reset 20 | 21 | # Regular Bold Underline High Intensity BoldHigh Intens Background High Intensity Backgrounds 22 | Bla='\e[0;30m'; BBla='\e[1;30m'; UBla='\e[4;30m'; IBla='\e[0;90m'; BIBla='\e[1;90m'; On_Bla='\e[40m'; On_IBla='\e[0;100m'; 23 | Red='\e[0;31m'; BRed='\e[1;31m'; URed='\e[4;31m'; IRed='\e[0;91m'; BIRed='\e[1;91m'; On_Red='\e[41m'; On_IRed='\e[0;101m'; 24 | Gre='\e[0;32m'; BGre='\e[1;32m'; UGre='\e[4;32m'; IGre='\e[0;92m'; BIGre='\e[1;92m'; On_Gre='\e[42m'; On_IGre='\e[0;102m'; 25 | Yel='\e[0;33m'; BYel='\e[1;33m'; UYel='\e[4;33m'; IYel='\e[0;93m'; BIYel='\e[1;93m'; On_Yel='\e[43m'; On_IYel='\e[0;103m'; 26 | Blu='\e[0;34m'; BBlu='\e[1;34m'; UBlu='\e[4;34m'; IBlu='\e[0;94m'; BIBlu='\e[1;94m'; On_Blu='\e[44m'; On_IBlu='\e[0;104m'; 27 | Pur='\e[0;35m'; BPur='\e[1;35m'; UPur='\e[4;35m'; IPur='\e[0;95m'; BIPur='\e[1;95m'; On_Pur='\e[45m'; On_IPur='\e[0;105m'; 28 | Cya='\e[0;36m'; BCya='\e[1;36m'; UCya='\e[4;36m'; ICya='\e[0;96m'; BICya='\e[1;96m'; On_Cya='\e[46m'; On_ICya='\e[0;106m'; 29 | Whi='\e[0;37m'; BWhi='\e[1;37m'; UWhi='\e[4;37m'; IWhi='\e[0;97m'; BIWhi='\e[1;97m'; On_Whi='\e[47m'; On_IWhi='\e[0;107m'; 30 | fi 31 | 32 | INDENT=0 33 | INDENT_STRING=" " 34 | indent() { 35 | INDENT=$((INDENT+1)) 36 | } 37 | unindent() { 38 | INDENT=$((INDENT-1)) 39 | } 40 | 41 | log_lines() { 42 | local level="$1" 43 | shift 44 | echo "$@" | while IFS= read -r line; do 45 | log "$level" "$line" 46 | done 47 | } 48 | 49 | log() { 50 | local level="$1" 51 | shift 52 | local message="$@" 53 | 54 | local color="" 55 | case "$level" in 56 | warn) color="${BIYel}";; 57 | error) color="${BIRed}";; 58 | info) color="${BIGre}";; 59 | trace) color="${BBla}";; 60 | esac 61 | 62 | local indentation="" 63 | if [ "$INDENT" -ne "0" ]; then 64 | for i in $(seq 0 $INDENT); do 65 | local indentation="$indentation$INDENT_STRING" 66 | done 67 | fi 68 | 69 | local format="${color}%-5s${RCol}: $indentation%s\n" 70 | if [ $level == "trace" ]; then 71 | format="${color}%-5s${RCol}: $indentation${color}%s${RCol}\n" 72 | fi 73 | 74 | if [ $level == "error" ]; then 75 | printf "$format" "$level" "$message" 1>&2 76 | else 77 | printf "$format" "$level" "$message" 78 | fi 79 | } 80 | 81 | # Echo to stderr 82 | error() { 83 | log error $@ 84 | } 85 | 86 | info() { 87 | log info $@ 88 | } 89 | 90 | warn() { 91 | log warn $@ 92 | } 93 | 94 | die() { 95 | error $@ 96 | exit 1 97 | } 98 | 99 | teamcity() { 100 | [ "$TEAMCITY" == "1" ] && echo "##teamcity[$1]" 101 | } 102 | 103 | verbose() { 104 | [ "$VERBOSE" == "1" ] && log trace $@ 105 | } 106 | 107 | path_of() { 108 | local CMD=$1 109 | type $CMD | sed "s/$CMD is //g" 110 | } 111 | 112 | has() { 113 | type "$1" > /dev/null 2>&1 114 | return $? 115 | } 116 | 117 | requires() { 118 | if ! has $1; then 119 | die "Missing required command: $1" 120 | fi 121 | } 122 | -------------------------------------------------------------------------------- /test/sh/run-tests.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Determine my directory 4 | SCRIPT_DIR=$(dirname $0) 5 | pushd $SCRIPT_DIR > /dev/null 6 | SCRIPT_DIR=$(pwd) 7 | popd > /dev/null 8 | 9 | # Determine root 10 | pushd $SCRIPT_DIR/../.. > /dev/null 11 | REPO_ROOT=$(pwd) 12 | popd > /dev/null 13 | 14 | # Load helper functions 15 | export COMMON_HELPERS="$SCRIPT_DIR/common.sh" 16 | source $COMMON_HELPERS 17 | 18 | # Default variable values 19 | [ -z "$TEST_WORK_DIR" ] && export TEST_WORK_DIR="$(pwd)/testwork" 20 | [ -z "$TEST_SHELLS" ] && export TEST_SHELLS="bash zsh" 21 | [ -z "$TEST_DIR" ] && export TEST_DIR="$SCRIPT_DIR/tests" 22 | [ -z "$CHESTER" ] && export CHESTER="$SCRIPT_DIR/chester" 23 | [ -z "$DNX_FEED" ] && export DNX_FEED="https://www.nuget.org/api/v2" # doesn't really matter what the feed is, just that it is a feed 24 | [ -z "$TEST_APPS_DIR" ] && export TEST_APPS_DIR="$REPO_ROOT/test/apps" 25 | 26 | export DNX_FEED 27 | 28 | # This is a DNX to use for testing various commands. It doesn't matter what version it is 29 | [ -z "$_TEST_VERSION" ] && export _TEST_VERSION="1.0.0-beta7" 30 | [ -z "$_NUPKG_HASH" ] && export _NUPKG_HASH='234e543292254e18fe57c6f77c54b281d9d600b7' 31 | [ -z "$_NUPKG_URL" ] && export _NUPKG_URL="$DNX_FEED/package/$_DNVM_RUNTIME_PACKAGE_NAME-mono/$_TEST_VERSION" 32 | [ -z "$_NUPKG_NAME" ] && export _NUPKG_NAME="$_DNVM_RUNTIME_PACKAGE_NAME-mono.$_TEST_VERSION" 33 | [ -z "$_NUPKG_FILE" ] && export _NUPKG_FILE="$TEST_WORK_DIR/${_NUPKG_NAME}.nupkg" 34 | 35 | requires curl 36 | requires awk 37 | 38 | for shell in $TEST_SHELLS; do 39 | requires $shell 40 | done 41 | 42 | # Set up a test environment 43 | info "Using Working Directory path: $TEST_WORK_DIR" 44 | 45 | if [ ! -e "$TEST_WORK_DIR" ]; then 46 | info "Creating working directory." 47 | mkdir -p "$TEST_WORK_DIR" 48 | fi 49 | 50 | if [ -f "$_NUPKG_FILE" ]; then 51 | # Remove the file if it doesn't match the expected hash 52 | if [ $(shasum $_NUPKG_FILE | awk '{ print $1 }') = "$_NUPKG_HASH" ]; then 53 | info "Test package already exists and matches expected hash" 54 | else 55 | warn "Test package does not match expected hash, removing and redownloading." 56 | rm "$_NUPKG_FILE" 57 | fi 58 | fi 59 | 60 | if [ ! -f "$_NUPKG_FILE" ]; then 61 | # Fetch the nupkg we use for testing 62 | info "Fetching test dependencies..." 63 | 64 | curl -L -o $_NUPKG_FILE $_NUPKG_URL >/dev/null 2>&1 65 | ACTUAL_HASH=$(shasum $_NUPKG_FILE | awk '{ print $1 }') 66 | [ -e $_NUPKG_FILE ] || die "failed to fetch test nupkg" 67 | [ "$ACTUAL_HASH" = "$_NUPKG_HASH" ] || die "downloaded nupkg hash '$ACTUAL_HASH' for '$_NUPKG_URL' does not match expected value" 68 | fi 69 | 70 | # Set up useful variables for the test 71 | pushd "$SCRIPT_DIR/../../src" > /dev/null 72 | export _DNVM_PATH=$(pwd)/$_DNVM_COMMAND_NAME.sh 73 | popd > /dev/null 74 | 75 | if [ ! -e $_DNVM_PATH ]; then 76 | die "Couldn't find $_DNVM_COMMAND_NAME at $_DNVM_PATH" 77 | elif [ ! -f $_DNVM_PATH ]; then 78 | die "$_DNVM_COMMAND_NAME at $_DNVM_PATH is not a file?!" 79 | fi 80 | 81 | info "Using $_DNVM_COMMAND_NAME at $_DNVM_PATH" 82 | 83 | # Run the test runner in each test shell 84 | FAILED=() 85 | SUCCEEDED=() 86 | for shell in $TEST_SHELLS; do 87 | info "Testing $_DNVM_COMMAND_NAME.sh in $shell" 88 | 89 | if [ -e "$TEST_WORK_DIR/$shell" ]; then 90 | if [ ! -d "$TEST_WORK_DIR/$shell" ]; then 91 | die "Working directory path exists and is not a directory!" 92 | else 93 | warn "Working directory path exists. Cleaning..." 94 | rm -Rf "$TEST_WORK_DIR/$shell" 95 | fi 96 | fi 97 | mkdir "$TEST_WORK_DIR/$shell" 98 | mkdir "$TEST_WORK_DIR/$shell/runtimes" 99 | mkdir "$TEST_WORK_DIR/${shell}_global" 100 | mkdir "$TEST_WORK_DIR/${shell}_global/runtimes" 101 | 102 | export DNX_USER_HOME="$TEST_WORK_DIR/$shell" 103 | [ -d $DNX_USER_HOME ] || mkdir $DNX_USER_HOME 104 | 105 | export DNX_GLOBAL_HOME="$TEST_WORK_DIR/${shell}_global" 106 | [ -d $DNX_GLOBAL_HOME ] || mkdir $DNX_GLOBAL_HOME 107 | 108 | pushd "$SCRIPT_DIR/tests" >/dev/null 2>&1 109 | $CHESTER $@ -s $shell -n $shell "*" 110 | err_code="$?" 111 | popd >/dev/null 2>&1 112 | 113 | unset DNVM_USER_HOME 114 | 115 | if [ "$err_code" -eq 0 ]; then 116 | SUCCEEDED+=("$shell") 117 | info "Tests completed in $shell" 118 | else 119 | FAILED+=("$shell") 120 | error "Tests failed in $shell" 121 | fi 122 | done 123 | 124 | exit "${#FAILED[@]}" 125 | -------------------------------------------------------------------------------- /test/sh/tests/alias/Alias parameters are case insensitive.sh: -------------------------------------------------------------------------------- 1 | source $COMMON_HELPERS 2 | source $_DNVM_PATH 3 | 4 | DUMMY_RUNTIME="coreclr" 5 | DUMMY_OS="linux" 6 | DUMMY_ARCH="x64" 7 | DUMMY_VERSION="1.0.0-beta7" 8 | DUMMY_PACKAGE="$_DNVM_RUNTIME_PACKAGE_NAME-$DUMMY_RUNTIME-$DUMMY_OS-$DUMMY_ARCH.$DUMMY_VERSION" 9 | 10 | # Create dummy dir for testing if not exists 11 | if [ ! -d "$DNX_USER_HOME/runtimes/$DUMMY_PACKAGE/bin" ]; then 12 | mkdir -p "$DNX_USER_HOME/runtimes/$DUMMY_PACKAGE/bin" > /dev/null 13 | CREATED="true" 14 | fi 15 | 16 | # Make the alias 17 | $_DNVM_COMMAND_NAME alias not_case_sensitive "$DUMMY_VERSION" -r CoreCLR -OS Linux -a X64 || die 'could not create alias' 18 | 19 | # Read them 20 | LIST=$($_DNVM_COMMAND_NAME alias) 21 | 22 | # Check the output 23 | ESCAPED_DUMMY_PACKAGE=$(echo $DUMMY_PACKAGE | sed 's,\.,\\.,g') 24 | 25 | echo $LIST | grep -E "not_case_sensitive\s+$ESCAPED_DUMMY_PACKAGE" || die 'list did not include expected alias' 26 | 27 | # Cleanup of dummy package 28 | [[ "$CREATED" == "true" ]] && rm -rf "$DNX_USER_HOME/runtimes/$DUMMY_PACKAGE" -------------------------------------------------------------------------------- /test/sh/tests/alias/Alias values can be retrieved.sh: -------------------------------------------------------------------------------- 1 | source $COMMON_HELPERS 2 | source $_DNVM_PATH 3 | 4 | # Alias the installed runtime 5 | $_DNVM_COMMAND_NAME alias test_alias_get "$_TEST_VERSION" 6 | 7 | # Try to read it 8 | [ $($_DNVM_COMMAND_NAME alias test_alias_get) = "$_NUPKG_NAME" ] || die "alias value was not the expected value" 9 | -------------------------------------------------------------------------------- /test/sh/tests/alias/Aliases can be listed.sh: -------------------------------------------------------------------------------- 1 | source $COMMON_HELPERS 2 | source $_DNVM_PATH 3 | 4 | # Make some aliases 5 | $_DNVM_COMMAND_NAME alias test_alias_list_0 "$_TEST_VERSION" 6 | $_DNVM_COMMAND_NAME alias test_alias_list_1 "$_TEST_VERSION" 7 | $_DNVM_COMMAND_NAME alias test_alias_list_2 "$_TEST_VERSION" 8 | $_DNVM_COMMAND_NAME alias test_alias_list_3 "$_TEST_VERSION" 9 | 10 | # Read them 11 | LIST=$($_DNVM_COMMAND_NAME alias) 12 | 13 | # Check the output 14 | ESCAPED_VER=$(echo $_TEST_VERSION | sed 's,\.,\\.,g') 15 | 16 | echo $LIST | grep -E "test_alias_list_0\s+$_DNVM_RUNTIME_PACKAGE_NAME-mono\.$ESCAPED_VER" || die 'list did not include expected aliases' 17 | echo $LIST | grep -E "test_alias_list_1\s+$_DNVM_RUNTIME_PACKAGE_NAME-mono\.$ESCAPED_VER" || die 'list did not include expected aliases' 18 | echo $LIST | grep -E "test_alias_list_2\s+$_DNVM_RUNTIME_PACKAGE_NAME-mono\.$ESCAPED_VER" || die 'list did not include expected aliases' 19 | echo $LIST | grep -E "test_alias_list_3\s+$_DNVM_RUNTIME_PACKAGE_NAME-mono\.$ESCAPED_VER" || die 'list did not include expected aliases' 20 | -------------------------------------------------------------------------------- /test/sh/tests/alias/Aliases can be removed.sh: -------------------------------------------------------------------------------- 1 | source $COMMON_HELPERS 2 | source $_DNVM_PATH 3 | 4 | # Alias the installed runtime 5 | $_DNVM_COMMAND_NAME alias test_alias_unalias "$_TEST_VERSION" 6 | 7 | # Unalias it 8 | $_DNVM_COMMAND_NAME alias -d test_alias_unalias 9 | 10 | # Check the alias file 11 | [ ! -e "$DNX_USER_HOME/alias/test_alias_unalias.alias" ] || die "test alias was not removed" 12 | -------------------------------------------------------------------------------- /test/sh/tests/alias/Aliases can be use-d.sh: -------------------------------------------------------------------------------- 1 | source $COMMON_HELPERS 2 | source $_DNVM_PATH 3 | 4 | # Alias the installed runtime 5 | $_DNVM_COMMAND_NAME alias test_alias_use "$_TEST_VERSION" 6 | 7 | # Remove runtime from the path 8 | $_DNVM_COMMAND_NAME use none 9 | 10 | # 'use' the alias 11 | $_DNVM_COMMAND_NAME use test_alias_use 12 | 13 | # Check that the path now has that Runtime on it 14 | EXPECTED_ROOT="$DNX_USER_HOME/runtimes/$_DNVM_RUNTIME_PACKAGE_NAME-mono.$_TEST_VERSION/bin" 15 | [ "$(path_of $_DNVM_RUNTIME_HOST_NAME)" = "$EXPECTED_ROOT/$_DNVM_RUNTIME_HOST_NAME" ] || die "'$_DNVM_RUNTIME_HOST_NAME' was not available at the expected path!" 16 | [ "$(path_of $_DNVM_PACKAGE_MANAGER_NAME)" = "$EXPECTED_ROOT/$_DNVM_PACKAGE_MANAGER_NAME" ] || die "'$_DNVM_PACKAGE_MANAGER_NAME' was not available at the expected path!" 17 | 18 | # Clean up the path 19 | $_DNVM_COMMAND_NAME use none 20 | -------------------------------------------------------------------------------- /test/sh/tests/alias/Aliasing creates a new alias file.sh: -------------------------------------------------------------------------------- 1 | source $COMMON_HELPERS 2 | source $_DNVM_PATH 3 | 4 | # Alias the installed runtime 5 | $_DNVM_COMMAND_NAME alias test_alias_create "$_TEST_VERSION" 6 | 7 | # Check the alias file 8 | [ -f "$DNX_USER_HOME/alias/test_alias_create.alias" ] || die "test alias was not created" 9 | [ $(cat "$DNX_USER_HOME/alias/test_alias_create.alias") = "$_DNVM_RUNTIME_PACKAGE_NAME-mono.$_TEST_VERSION" ] || die "test alias was not set to expected value" 10 | -------------------------------------------------------------------------------- /test/sh/tests/alias/Aliasing replaces existing alias.sh: -------------------------------------------------------------------------------- 1 | source $COMMON_HELPERS 2 | source $_DNVM_PATH 3 | 4 | # Check which shell currently executing 5 | if [ -n "$ZSH_VERSION" ]; then 6 | # assume Zsh 7 | setopt noclobber 8 | elif [ -n "$BASH_VERSION" ]; then 9 | # assume Bash 10 | set -o noclobber 11 | fi 12 | 13 | echo "woozlewuzzle" > "$DNX_USER_HOME/alias/test_alias_rename.alias" 14 | 15 | # Alias the installed runtime 16 | $_DNVM_COMMAND_NAME alias test_alias_rename "$_TEST_VERSION" 17 | 18 | # Check the alias file 19 | [ -f "$DNX_USER_HOME/alias/test_alias_rename.alias" ] || die "test alias was removed" 20 | [ $(cat "$DNX_USER_HOME/alias/test_alias_rename.alias") = "$_DNVM_RUNTIME_PACKAGE_NAME-mono.$_TEST_VERSION" ] || die "test alias was not set to expected value" 21 | -------------------------------------------------------------------------------- /test/sh/tests/alias/after_all.sh: -------------------------------------------------------------------------------- 1 | # Clean up 2 | rm -Rf "$DNX_USER_HOME/alias" 3 | rm -Rf "$DNX_USER_HOME/runtimes" 4 | rm -Rf "$DNX_USER_HOME/temp" 5 | -------------------------------------------------------------------------------- /test/sh/tests/alias/before_all.sh: -------------------------------------------------------------------------------- 1 | source $COMMON_HELPERS 2 | source $_DNVM_PATH 3 | 4 | # Get a runtime to use during these tests 5 | $_DNVM_COMMAND_NAME install "$_TEST_VERSION" 6 | -------------------------------------------------------------------------------- /test/sh/tests/install/Installed runtime can run hello app.sh: -------------------------------------------------------------------------------- 1 | # Simple smoke test for the runtime fetched by $_DNVM_COMMAND_NAME. To help ensure that it is unpacked correctly and such 2 | 3 | source $COMMON_HELPERS 4 | source $_DNVM_PATH 5 | 6 | # Get a runtime to use during these tests 7 | $_DNVM_COMMAND_NAME install latest 8 | 9 | # Test the runtime 10 | has $_DNVM_RUNTIME_HOST_NAME || die "didn't install the runtime :(" 11 | has $_DNVM_PACKAGE_MANAGER_NAME || die "installed runtime didn't have a package manager?" 12 | 13 | pushd "$TEST_APPS_DIR/TestApp" 14 | $_DNVM_PACKAGE_MANAGER_NAME restore || die "failed to restore packages" 15 | OUTPUT=$($_DNVM_RUNTIME_HOST_NAME run || die "failed to run hello application") 16 | echo $OUTPUT | grep 'Runtime is sane!' || die "unexpected output from sample app: $OUTPUT" 17 | popd 18 | -------------------------------------------------------------------------------- /test/sh/tests/install/Installing a runtime that exists does not report error.sh: -------------------------------------------------------------------------------- 1 | source $COMMON_HELPERS 2 | source $_DNVM_PATH 3 | 4 | # Install a runtime 5 | $_DNVM_COMMAND_NAME install "$_TEST_VERSION" || die "failed initial install of runtime" 6 | 7 | # Install it again and ensure it reports the message we expect 8 | OUTPUT=$($_DNVM_COMMAND_NAME install "$_TEST_VERSION" || die "failed second attempt at installing runtime") 9 | echo $OUTPUT | grep "$_DNVM_RUNTIME_PACKAGE_NAME-mono.$_TEST_VERSION already installed" || die "expected message was not reported" 10 | -------------------------------------------------------------------------------- /test/sh/tests/install/Installing from nupkg unpacks nupkg as expected.sh: -------------------------------------------------------------------------------- 1 | source $COMMON_HELPERS 2 | source $_DNVM_PATH 3 | 4 | # Install the nupkg 5 | $_DNVM_COMMAND_NAME install $_NUPKG_FILE 6 | 7 | [ -d "$DNX_USER_HOME/runtimes/$_NUPKG_NAME" ] || die "unable to find installed runtime" 8 | 9 | pushd "$DNX_USER_HOME/runtimes/$_NUPKG_NAME" 2>/dev/null 1>/dev/null 10 | [ -f bin/$_DNVM_RUNTIME_HOST_NAME ] || die "$_DNVM_COMMAND_NAME did not include '$_DNVM_RUNTIME_HOST_NAME' command!" 11 | [ -f bin/$_DNVM_PACKAGE_MANAGER_NAME ] || die "$_DNVM_COMMAND_NAME did not include '$_DNVM_PACKAGE_MANAGER_NAME' command!" 12 | popd 2>/dev/null 1>/dev/null 13 | -------------------------------------------------------------------------------- /test/sh/tests/install/Installing global with local already installed does not install.sh: -------------------------------------------------------------------------------- 1 | source $COMMON_HELPERS 2 | source $_DNVM_PATH 3 | 4 | mv $DNX_USER_HOME/runtimes $DNX_USER_HOME/runtimes_backup 5 | mv $DNX_GLOBAL_HOME/runtimes $DNX_GLOBAL_HOME/runtimes_backup 6 | 7 | $_DNVM_COMMAND_NAME install $_TEST_VERSION 8 | 9 | OUTPUT=$($_DNVM_COMMAND_NAME install $_TEST_VERSION -g) 10 | echo $OUTPUT | grep -E "\salready installed in $DNX_USER_HOME" || die "expected message was not reported" 11 | 12 | rm -Rf $DNX_USER_HOME/runtimes 13 | mv $DNX_USER_HOME/runtimes_backup $DNX_USER_HOME/runtimes 14 | mv $DNX_GLOBAL_HOME/runtimes_backup $DNX_GLOBAL_HOME/runtimes 15 | -------------------------------------------------------------------------------- /test/sh/tests/install/Installing latest with no arguments installs Mono CLR.sh: -------------------------------------------------------------------------------- 1 | source $COMMON_HELPERS 2 | source $_DNVM_PATH 3 | 4 | $_DNVM_COMMAND_NAME install $_TEST_VERSION 5 | 6 | # Resolve the name of the runtime directory 7 | RUNTIME_PATH="$DNX_USER_HOME/runtimes/$_DNVM_RUNTIME_PACKAGE_NAME-mono.$_TEST_VERSION" 8 | 9 | [ -f "$RUNTIME_PATH/bin/$_DNVM_RUNTIME_HOST_NAME" ] || die "$_DNVM_COMMAND_NAME did not include '$_DNVM_RUNTIME_HOST_NAME' command!" 10 | [ -f "$RUNTIME_PATH/bin/$_DNVM_PACKAGE_MANAGER_NAME" ] || die "$_DNVM_COMMAND_NAME did not include '$_DNVM_PACKAGE_MANAGER_NAME' command!" 11 | 12 | [ ! -f "$DNX_USER_HOME/alias/default.alias" ] || die "default alias was created despite not setting --persistant" 13 | -------------------------------------------------------------------------------- /test/sh/tests/install/Installing puts selected runtime on PATH.sh: -------------------------------------------------------------------------------- 1 | source $COMMON_HELPERS 2 | source $_DNVM_PATH 3 | 4 | $_DNVM_COMMAND_NAME install "$_TEST_VERSION" 5 | 6 | EXPECTED_ROOT="$DNX_USER_HOME/runtimes/$_DNVM_RUNTIME_PACKAGE_NAME-mono.$_TEST_VERSION/bin" 7 | 8 | [ $(path_of $_DNVM_RUNTIME_HOST_NAME) = "$EXPECTED_ROOT/$_DNVM_RUNTIME_HOST_NAME" ] || die "'$_DNVM_RUNTIME_HOST_NAME' was not available at the expected path!" 9 | [ $(path_of $_DNVM_PACKAGE_MANAGER_NAME) = "$EXPECTED_ROOT/$_DNVM_PACKAGE_MANAGER_NAME" ] || die "'$_DNVM_PACKAGE_MANAGER_NAME' was not available at the expected path!" 10 | -------------------------------------------------------------------------------- /test/sh/tests/install/Installing runtime globally.sh: -------------------------------------------------------------------------------- 1 | source $COMMON_HELPERS 2 | source $_DNVM_PATH 3 | 4 | mv $DNX_USER_HOME/runtimes $DNX_USER_HOME/runtimes_backup 5 | mv $DNX_GLOBAL_HOME/runtimes $DNX_GLOBAL_HOME/runtimes_backup 6 | 7 | OUTPUT=$($_DNVM_COMMAND_NAME install $_TEST_VERSION -g -y) 8 | echo $OUTPUT | grep -E "Installing to $DNX_GLOBAL_HOME/runtimes/dnx-mono.$_TEST_VERSION" || die "expected message was not reported" 9 | 10 | rm -rf $DNX_GLOBAL_HOME/runtimes 11 | mv $DNX_GLOBAL_HOME/runtimes_backup $DNX_GLOBAL_HOME/runtimes 12 | mv $DNX_USER_HOME/runtimes_backup $DNX_USER_HOME/runtimes 13 | -------------------------------------------------------------------------------- /test/sh/tests/install/Installing with alias switch creates specified alias.sh: -------------------------------------------------------------------------------- 1 | source $COMMON_HELPERS 2 | source $_DNVM_PATH 3 | 4 | $_DNVM_COMMAND_NAME install "$_TEST_VERSION" -alias test 5 | 6 | [ -f "$DNX_USER_HOME/alias/test.alias" ] || die "test alias was not created" 7 | [ $(cat "$DNX_USER_HOME/alias/test.alias") = "$_DNVM_RUNTIME_PACKAGE_NAME-mono.$_TEST_VERSION" ] || die "test alias was not set to expected value" 8 | -------------------------------------------------------------------------------- /test/sh/tests/install/Installing with os specified gives correct defaults.sh: -------------------------------------------------------------------------------- 1 | source $COMMON_HELPERS 2 | source $_DNVM_PATH 3 | 4 | $_DNVM_COMMAND_NAME install $_TEST_VERSION -OS win 5 | 6 | # Resolve the name of the runtime directory 7 | RUNTIME_PATH="$DNX_USER_HOME/runtimes/$_DNVM_RUNTIME_PACKAGE_NAME-clr-win-x86.$_TEST_VERSION" 8 | 9 | [ -f "$RUNTIME_PATH/bin/$_DNVM_RUNTIME_HOST_NAME.exe" ] || die "$_DNVM_COMMAND_NAME did not include '$_DNVM_RUNTIME_HOST_NAME.exe' command!" 10 | [ -f "$RUNTIME_PATH/bin/$_DNVM_PACKAGE_MANAGER_NAME.cmd" ] || die "$_DNVM_COMMAND_NAME did not include '$_DNVM_PACKAGE_MANAGER_NAME.cmd' command!" 11 | 12 | $_DNVM_COMMAND_NAME install $_TEST_VERSION -OS darwin 13 | 14 | # Resolve the name of the runtime directory 15 | RUNTIME_PATH="$DNX_USER_HOME/runtimes/$_DNVM_RUNTIME_PACKAGE_NAME-mono.$_TEST_VERSION" 16 | 17 | [ -f "$RUNTIME_PATH/bin/$_DNVM_RUNTIME_HOST_NAME" ] || die "$_DNVM_COMMAND_NAME did not include '$_DNVM_RUNTIME_HOST_NAME' command!" 18 | [ -f "$RUNTIME_PATH/bin/$_DNVM_PACKAGE_MANAGER_NAME" ] || die "$_DNVM_COMMAND_NAME did not include '$_DNVM_PACKAGE_MANAGER_NAME' command!" 19 | 20 | $_DNVM_COMMAND_NAME install $_TEST_VERSION -OS linux 21 | 22 | # Resolve the name of the runtime directory 23 | RUNTIME_PATH="$DNX_USER_HOME/runtimes/$_DNVM_RUNTIME_PACKAGE_NAME-mono.$_TEST_VERSION" 24 | 25 | [ -f "$RUNTIME_PATH/bin/$_DNVM_RUNTIME_HOST_NAME" ] || die "$_DNVM_COMMAND_NAME did not include '$_DNVM_RUNTIME_HOST_NAME' command!" 26 | [ -f "$RUNTIME_PATH/bin/$_DNVM_PACKAGE_MANAGER_NAME" ] || die "$_DNVM_COMMAND_NAME did not include '$_DNVM_PACKAGE_MANAGER_NAME' command!" 27 | 28 | rm -Rf $DNX_USER_HOME/runtimes 29 | -------------------------------------------------------------------------------- /test/sh/tests/install/Installing with persistant switch creates default alias.sh: -------------------------------------------------------------------------------- 1 | source $COMMON_HELPERS 2 | source $_DNVM_PATH 3 | 4 | $_DNVM_COMMAND_NAME install "$_TEST_VERSION" -p 5 | 6 | [ -f "$DNX_USER_HOME/alias/default.alias" ] || die "default alias was not created" 7 | [ $(cat "$DNX_USER_HOME/alias/default.alias") = "$_DNVM_RUNTIME_PACKAGE_NAME-mono.$_TEST_VERSION" ] || die "default alias was not set to expected value" 8 | -------------------------------------------------------------------------------- /test/sh/tests/install/after.sh: -------------------------------------------------------------------------------- 1 | # Clean up 2 | rm -Rf "$DNX_USER_HOME/alias" 3 | rm -Rf "$DNX_USER_HOME/runtimes" 4 | rm -Rf "$DNX_USER_HOME/temp" 5 | -------------------------------------------------------------------------------- /test/sh/tests/list/Listing displays friendly message when no runtimes found.sh: -------------------------------------------------------------------------------- 1 | source $COMMON_HELPERS 2 | source $_DNVM_PATH 3 | 4 | # Clean all runtimes (temporarily) 5 | mv $DNX_USER_HOME/runtimes $DNX_USER_HOME/runtimes_backup 6 | mv $DNX_GLOBAL_HOME/runtimes $DNX_GLOBAL_HOME/runtimes_backup 7 | mkdir -p $DNX_USER_HOME/runtimes 8 | mkdir -p $DNX_GLOBAL_HOME/runtimes 9 | 10 | # List runtimes 11 | OUTPUT=$($_DNVM_COMMAND_NAME list || die "failed at listing runtimes") 12 | echo $OUTPUT | grep "^No runtimes installed" || die "expected message was not reported" 13 | 14 | # Restore runtimes 15 | rm -Rf $DNX_USER_HOME/runtimes 16 | rm -Rf $DNX_GLOBAL_HOME/runtimes 17 | mv $DNX_USER_HOME/runtimes_backup $DNX_USER_HOME/runtimes 18 | mv $DNX_GLOBAL_HOME/runtimes_backup $DNX_GLOBAL_HOME/runtimes 19 | -------------------------------------------------------------------------------- /test/sh/tests/list/Listing displays global and local installed dnx.sh: -------------------------------------------------------------------------------- 1 | source $COMMON_HELPERS 2 | source $_DNVM_PATH 3 | 4 | # Clean all runtime (temporarily) 5 | mv $DNX_USER_HOME/runtimes $DNX_USER_HOME/runtimes_backup 6 | mv $DNX_GLOBAL_HOME/runtimes $DNX_GLOBAL_HOME/runtimes_backup 7 | mv $DNX_USER_HOME/alias $DNX_USER_HOME/alias_backup 8 | 9 | # Install runtimes 10 | $_DNVM_COMMAND_NAME install "$_TEST_VERSION" 11 | $_DNVM_COMMAND_NAME install "$_TEST_VERSION" -r coreclr -g 12 | echo $($_DNVM_COMMAND_NAME list -detailed) 13 | # List runtimes 14 | OUTPUT=$($_DNVM_COMMAND_NAME list -detailed || die "failed at listing runtimes") 15 | OS="$(__dnvm_current_os)" 16 | 17 | echo $OUTPUT | grep -E "\s+$_TEST_VERSION\s+mono\s+linux/osx\s+$(echo $DNX_USER_HOME | sed s=$HOME=~=g)/runtimes" || die "expected message was not reported" 18 | echo $OUTPUT | grep -E "\s+$_TEST_VERSION\s+coreclr\s+x64\s+$OS\s+$(echo $DNX_GLOBAL_HOME | sed s=$HOME=~=g)/runtimes" || die "expected message was not reported" 19 | 20 | rm -rf $DNX_GLOBAL_HOME/runtimes 21 | rm -rf $DNX_USER_HOME/runtimes 22 | mv $DNX_USER_HOME/runtimes_backup $DNX_USER_HOME/runtimes 23 | mv $DNX_GLOBAL_HOME/runtimes_backup $DNX_GLOBAL_HOME/runtimes 24 | mv $DNX_USER_HOME/alias_backup $DNX_USER_HOME/alias 25 | -------------------------------------------------------------------------------- /test/sh/tests/list/Listing displays orphaned aliases.sh: -------------------------------------------------------------------------------- 1 | source $COMMON_HELPERS 2 | source $_DNVM_PATH 3 | 4 | # Clean all aliases 5 | rm -Rf $DNX_USER_HOME/alias/*.alias 6 | 7 | # Set default alias to any runtime 8 | echo $(ls $DNX_USER_HOME/runtimes | head -n1) > $DNX_USER_HOME/alias/default.alias 9 | 10 | # Create orphaned alias 11 | echo dnx-foo-bar.1.0.0-beta7 > $DNX_USER_HOME/alias/foobar.alias 12 | 13 | # List runtimes 14 | OUTPUT=$($_DNVM_COMMAND_NAME list -detailed || die "failed at listing runtimes") 15 | echo $OUTPUT | grep -E "\s+1\.0\.0-beta7\s+foo\s+bar\s+foobar\s\(missing\)" || die "expected message was not reported" 16 | echo $OUTPUT | grep -E "default\s+.*?\/runtimes" || die "expected message was not reported" 17 | -------------------------------------------------------------------------------- /test/sh/tests/list/before_all.sh: -------------------------------------------------------------------------------- 1 | source $COMMON_HELPERS 2 | source $_DNVM_PATH 3 | 4 | # Get a runtime to use during these tests 5 | $_DNVM_COMMAND_NAME install "$_TEST_VERSION" 6 | -------------------------------------------------------------------------------- /test/sh/tests/run_exec/Executes the host or command for the specified alias.sh: -------------------------------------------------------------------------------- 1 | source $COMMON_HELPERS 2 | source $_DNVM_PATH 3 | 4 | $_DNVM_COMMAND_NAME alias test_alias_runexec $_TEST_VERSION 5 | $_DNVM_COMMAND_NAME use none 6 | 7 | pushd "$TEST_APPS_DIR/TestApp" 8 | $_DNVM_COMMAND_NAME exec test_alias_runexec $_DNVM_PACKAGE_MANAGER_NAME restore || die "failed to restore packages" 9 | OUTPUT=$($_DNVM_COMMAND_NAME run test_alias_runexec run || die "failed to run hello application") 10 | echo $OUTPUT | grep 'Runtime is sane!' || die "unexpected output from sample app: $OUTPUT" 11 | popd 12 | -------------------------------------------------------------------------------- /test/sh/tests/run_exec/Executes the host or command for the specified version.sh: -------------------------------------------------------------------------------- 1 | source $COMMON_HELPERS 2 | source $_DNVM_PATH 3 | 4 | $_DNVM_COMMAND_NAME use none 5 | 6 | pushd "$TEST_APPS_DIR/TestApp" 7 | $_DNVM_COMMAND_NAME exec $_TEST_VERSION $_DNVM_PACKAGE_MANAGER_NAME restore || die "failed to restore packages" 8 | OUTPUT=$($_DNVM_COMMAND_NAME run $_TEST_VERSION run || die "failed to run hello application") 9 | echo $OUTPUT | grep 'Runtime is sane!' || die "unexpected output from sample app: $OUTPUT" 10 | popd 11 | -------------------------------------------------------------------------------- /test/sh/tests/run_exec/after_all.sh: -------------------------------------------------------------------------------- 1 | # Clean up 2 | rm -Rf "$DNX_USER_HOME/alias" 3 | rm -Rf "$DNX_USER_HOME/runtimes" 4 | rm -Rf "$DNX_USER_HOME/temp" 5 | -------------------------------------------------------------------------------- /test/sh/tests/run_exec/before_all.sh: -------------------------------------------------------------------------------- 1 | source $COMMON_HELPERS 2 | source $_DNVM_PATH 3 | 4 | # Get a runtime to use during these tests 5 | $_DNVM_COMMAND_NAME install "$_TEST_VERSION" 6 | $_DNVM_COMMAND_NAME alias default "$_TEST_VERSION" 7 | -------------------------------------------------------------------------------- /test/sh/tests/sourcing/Self-updating a sourced dnvm can display its non-standard location.sh: -------------------------------------------------------------------------------- 1 | source $COMMON_HELPERS 2 | mkdir nonstandard_path 3 | cp $_DNVM_PATH nonstandard_path/ 4 | source nonstandard_path/dnvm.sh 5 | dnvm update-self > update-self-output-nonstandard.txt 6 | rm -rf nonstandard_path 7 | source $_DNVM_PATH 8 | -------------------------------------------------------------------------------- /test/sh/tests/sourcing/Sourcing the script adds DNX_HOME bin to path.sh: -------------------------------------------------------------------------------- 1 | source $COMMON_HELPERS 2 | 3 | source $_DNVM_PATH || die "$_DNVM_COMMAND_NAME sourcing failed" 4 | 5 | MATCHES=$(echo $PATH | grep -c "$DNX_USER_HOME/bin") 6 | [[ $MATCHES -eq 1 ]] || die "sourcing $_DNVM_COMMAND_NAME did not put expected value on PATH: $DNX_USER_HOME/bin" 7 | -------------------------------------------------------------------------------- /test/sh/tests/sourcing/Sourcing the script adds the command.sh: -------------------------------------------------------------------------------- 1 | source $COMMON_HELPERS 2 | 3 | source $_DNVM_PATH || die "$_DNVM_COMMAND_NAME sourcing failed" 4 | has $_DNVM_COMMAND_NAME || die "$_DNVM_COMMAND_NAME command not found!" 5 | -------------------------------------------------------------------------------- /test/sh/tests/sourcing/Sourcing the script twice does not add DNX_HOME bin to path twice.sh: -------------------------------------------------------------------------------- 1 | source $COMMON_HELPERS 2 | 3 | source $_DNVM_PATH || die "$_DNVM_COMMAND_NAME sourcing failed" 4 | source $_DNVM_PATH || die "$_DNVM_COMMAND_NAME sourcing failed" 5 | 6 | MATCHES=$(echo $PATH | tr ":" "\n" | grep -c "$DNX_USER_HOME/bin") 7 | [[ $MATCHES -eq 1 ]] || die "sourcing $_DNVM_COMMAND_NAME twice did put '$DNX_USER_HOME/bin' on PATH $MATCHES times" 8 | -------------------------------------------------------------------------------- /test/sh/tests/uninstall/Uninstalling removes dnx.sh: -------------------------------------------------------------------------------- 1 | source $COMMON_HELPERS 2 | source $_DNVM_PATH 3 | 4 | $_DNVM_COMMAND_NAME install $_TEST_VERSION 5 | 6 | [ -d $DNX_USER_HOME/runtimes/dnx-mono.$_TEST_VERSION ] || die "Nothing to uninstall" 7 | OUTPUT=$($_DNVM_COMMAND_NAME uninstall $_TEST_VERSION) 8 | [ -d $DNX_USER_HOME/runtimes/dnx-mono.$_TEST_VERSION ] && die "Uninstall didn't remove runtime" 9 | echo $OUTPUT | grep "Removed $DNX_USER_HOME/runtimes/dnx-mono.$_TEST_VERSION" || die "expected message was not reported" 10 | -------------------------------------------------------------------------------- /test/sh/tests/use/Use-ing a non-existant alias produces an error.sh: -------------------------------------------------------------------------------- 1 | source $COMMON_HELPERS 2 | source $_DNVM_PATH 3 | 4 | if $_DNVM_COMMAND_NAME use bogus_alias; then 5 | die "$_DNVM_COMMAND_NAME didn't fail to use bogus alias" 6 | fi 7 | -------------------------------------------------------------------------------- /test/sh/tests/use/Use-ing a non-existant version produces an error.sh: -------------------------------------------------------------------------------- 1 | source $COMMON_HELPERS 2 | source $_DNVM_PATH 3 | 4 | if $_DNVM_COMMAND_NAME use 0.1.0-not-real; then 5 | die "$_DNVM_COMMAND_NAME didn't fail to use bogus runtime version" 6 | fi 7 | -------------------------------------------------------------------------------- /test/sh/tests/use/Use-ing a version puts the matching runtime on the PATH.sh: -------------------------------------------------------------------------------- 1 | source $COMMON_HELPERS 2 | source $_DNVM_PATH 3 | 4 | # Clear the path 5 | $_DNVM_COMMAND_NAME use none 6 | 7 | # Use the installed runtime 8 | $_DNVM_COMMAND_NAME use "$_TEST_VERSION" 9 | 10 | # Check paths 11 | EXPECTED_ROOT="$DNX_USER_HOME/runtimes/$_DNVM_RUNTIME_PACKAGE_NAME-mono.$_TEST_VERSION/bin" 12 | 13 | [ "$(path_of $_DNVM_RUNTIME_HOST_NAME)" = "$EXPECTED_ROOT/$_DNVM_RUNTIME_HOST_NAME" ] || die "'$_DNVM_RUNTIME_HOST_NAME' was not available at the specified path!" 14 | [ "$(path_of $_DNVM_PACKAGE_MANAGER_NAME)" = "$EXPECTED_ROOT/$_DNVM_PACKAGE_MANAGER_NAME" ] || die "'$_DNVM_PACKAGE_MANAGER_NAME' was not available at the specified path!" 15 | -------------------------------------------------------------------------------- /test/sh/tests/use/Use-ing an alias puts the matching runtime on the path.sh: -------------------------------------------------------------------------------- 1 | source $COMMON_HELPERS 2 | source $_DNVM_PATH 3 | 4 | # Clear the path 5 | $_DNVM_COMMAND_NAME use none 6 | 7 | # Use the installed runtime 8 | $_DNVM_COMMAND_NAME use default 9 | 10 | # Check paths 11 | EXPECTED_ROOT="$DNX_USER_HOME/runtimes/$_DNVM_RUNTIME_PACKAGE_NAME-mono.$_TEST_VERSION/bin" 12 | 13 | [ "$(path_of $_DNVM_RUNTIME_HOST_NAME)" = "$EXPECTED_ROOT/$_DNVM_RUNTIME_HOST_NAME" ] || die "'$_DNVM_RUNTIME_HOST_NAME' was not available at the specified path!" 14 | [ "$(path_of $_DNVM_PACKAGE_MANAGER_NAME)" = "$EXPECTED_ROOT/$_DNVM_PACKAGE_MANAGER_NAME" ] || die "'$_DNVM_PACKAGE_MANAGER_NAME' was not available at the specified path!" 15 | -------------------------------------------------------------------------------- /test/sh/tests/use/Use-ing none clears runtime from the PATH.sh: -------------------------------------------------------------------------------- 1 | source $COMMON_HELPERS 2 | source $_DNVM_PATH 3 | 4 | # Use a runtime 5 | $_DNVM_COMMAND_NAME use "$_TEST_VERSION" 6 | 7 | # Use none 8 | $_DNVM_COMMAND_NAME use none 9 | 10 | # Check paths 11 | EXPECTED_ROOT="$DNX_USER_HOME/runtimes/$_DNVM_RUNTIME_PACKAGE_NAME-mono.$_TEST_VERSION/bin" 12 | 13 | [ "$(path_of $_DNVM_RUNTIME_HOST_NAME)" != "$EXPECTED_ROOT/$_DNVM_RUNTIME_HOST_NAME" ] || die "'$_DNVM_RUNTIME_HOST_NAME' was still available at the expected path!" 14 | [ "$(path_of $_DNVM_PACKAGE_MANAGER_NAME)" != "$EXPECTED_ROOT/$_DNVM_PACKAGE_MANAGER_NAME" ] || die "'$_DNVM_PACKAGE_MANAGER_NAME' was still available at the expected path!" 15 | -------------------------------------------------------------------------------- /test/sh/tests/use/after_all.sh: -------------------------------------------------------------------------------- 1 | # Clean up 2 | rm -Rf "$DNX_USER_HOME/alias" 3 | rm -Rf "$DNX_USER_HOME/runtimes" 4 | rm -Rf "$DNX_USER_HOME/temp" 5 | -------------------------------------------------------------------------------- /test/sh/tests/use/before_all.sh: -------------------------------------------------------------------------------- 1 | source $COMMON_HELPERS 2 | source $_DNVM_PATH 3 | 4 | # Get a runtime to use during these tests 5 | $_DNVM_COMMAND_NAME install "$_TEST_VERSION" 6 | $_DNVM_COMMAND_NAME alias default "$_TEST_VERSION" 7 | --------------------------------------------------------------------------------