@@ -3,12 +3,13 @@ import assert from "assert";
3
3
import path from "path" ;
4
4
import os from "os" ;
5
5
6
+ import sinon from "sinon" ;
6
7
import { before , after } from "mocha" ;
7
8
import * as vscode from "vscode" ;
8
9
9
10
import { RubyInstaller } from "../../../ruby/rubyInstaller" ;
10
11
import { WorkspaceChannel } from "../../../workspaceChannel" ;
11
- import { LOG_CHANNEL } from "../../../common" ;
12
+ import { asyncExec , LOG_CHANNEL } from "../../../common" ;
12
13
import { RUBY_VERSION } from "../../rubyVersion" ;
13
14
14
15
suite ( "RubyInstaller" , ( ) => {
@@ -100,4 +101,43 @@ suite("RubyInstaller", () => {
100
101
force : true ,
101
102
} ) ;
102
103
} ) ;
104
+
105
+ test ( "Finds Ruby using Powershell" , async ( ) => {
106
+ const [ major , minor , _patch ] = RUBY_VERSION . split ( "." ) . map ( Number ) ;
107
+ fs . symlinkSync (
108
+ path . join (
109
+ "C:" ,
110
+ "hostedtoolcache" ,
111
+ "windows" ,
112
+ "Ruby" ,
113
+ RUBY_VERSION ,
114
+ "x64" ,
115
+ ) ,
116
+ path . join ( "C:" , `Ruby${ major } ${ minor } -${ os . arch ( ) } ` ) ,
117
+ ) ;
118
+
119
+ fs . writeFileSync ( path . join ( workspacePath , ".ruby-version" ) , RUBY_VERSION ) ;
120
+
121
+ const windows = new RubyInstaller ( workspaceFolder , outputChannel ) ;
122
+
123
+ const { stdout } = await asyncExec (
124
+ 'powershell -Command \\"(Get-Command pwsh.exe).Path\\"' ,
125
+ ) ;
126
+ // eslint-disable-next-line no-console
127
+ console . log ( stdout ) ;
128
+ const stub = sinon . stub ( vscode . env , "shell" ) . returns ( stdout . trim ( ) ) ;
129
+
130
+ const { env, version, yjit } = await windows . activate ( ) ;
131
+ stub . restore ( ) ;
132
+
133
+ assert . match ( env . GEM_PATH ! , / r u b y \/ 3 \. 3 \. 0 / ) ;
134
+ assert . match ( env . GEM_PATH ! , / l i b \/ r u b y \/ g e m s \/ 3 \. 3 \. 0 / ) ;
135
+ assert . strictEqual ( version , RUBY_VERSION ) ;
136
+ assert . notStrictEqual ( yjit , undefined ) ;
137
+
138
+ fs . rmSync ( path . join ( "C:" , `Ruby${ major } ${ minor } -${ os . arch ( ) } ` ) , {
139
+ recursive : true ,
140
+ force : true ,
141
+ } ) ;
142
+ } ) ;
103
143
} ) ;
0 commit comments