@@ -13,6 +13,9 @@ import {
1313 resolveXlingsExecutable ,
1414} from "../src/llvmTools" ;
1515
16+ // `xlings` on POSIX, `xlings.exe` on Windows — mirrors mcpp's exe_suffix.
17+ const xlingsBinaryName = process . platform === "win32" ? "xlings.exe" : "xlings" ;
18+
1619test ( "extracts version string from ToolIdentity" , ( ) => {
1720 assert . equal (
1821 llvmToolsVersionSpec ( { major : 22 , minor : 1 , patch : 8 , revision : "abc1234" } ) ,
@@ -76,7 +79,7 @@ test("findXlingsExecutable returns a string or undefined", () => {
7679test ( "findXlingsExecutable finds the xlings bundled in $MCPP_HOME/registry/bin" , ( ) => {
7780 const home = mkdtempSync ( path . join ( os . tmpdir ( ) , "mcpp-vscode-mcpp-home-" ) ) ;
7881 const registryBin = path . join ( home , "registry" , "bin" ) ;
79- const xlingsPath = path . join ( registryBin , "xlings" ) ;
82+ const xlingsPath = path . join ( registryBin , xlingsBinaryName ) ;
8083 mkdirSync ( registryBin , { recursive : true } ) ;
8184 writeFileSync ( xlingsPath , "#!/bin/sh\n" ) ;
8285 try {
@@ -92,7 +95,7 @@ test("findXlingsExecutable finds the xlings bundled in $MCPP_HOME/registry/bin",
9295test ( "findXlingsExecutable falls back to $HOME/.mcpp/registry/bin when MCPP_HOME is unset" , ( ) => {
9396 const home = mkdtempSync ( path . join ( os . tmpdir ( ) , "mcpp-vscode-home-" ) ) ;
9497 const registryBin = path . join ( home , ".mcpp" , "registry" , "bin" ) ;
95- const xlingsPath = path . join ( registryBin , "xlings" ) ;
98+ const xlingsPath = path . join ( registryBin , xlingsBinaryName ) ;
9699 mkdirSync ( registryBin , { recursive : true } ) ;
97100 writeFileSync ( xlingsPath , "#!/bin/sh\n" ) ;
98101 try {
@@ -107,7 +110,7 @@ test("findXlingsExecutable falls back to $HOME/.mcpp/registry/bin when MCPP_HOME
107110
108111test ( "findXlingsExecutable honors MCPP_VENDORED_XLINGS" , ( ) => {
109112 const root = mkdtempSync ( path . join ( os . tmpdir ( ) , "mcpp-vscode-vendored-" ) ) ;
110- const vendored = path . join ( root , "opt-mcpp" , "registry" , "bin" , "xlings" ) ;
113+ const vendored = path . join ( root , "opt-mcpp" , "registry" , "bin" , xlingsBinaryName ) ;
111114 mkdirSync ( path . dirname ( vendored ) , { recursive : true } ) ;
112115 writeFileSync ( vendored , "#!/bin/sh\n" ) ;
113116 try {
@@ -122,7 +125,7 @@ test("findXlingsExecutable honors MCPP_VENDORED_XLINGS", () => {
122125
123126test ( "resolveXlingsExecutable reads the xlings binary from `mcpp self env`" , async ( ) => {
124127 const root = mkdtempSync ( path . join ( os . tmpdir ( ) , "mcpp-vscode-selfenv-" ) ) ;
125- const xlingsPath = path . join ( root , "registry" , "bin" , "xlings" ) ;
128+ const xlingsPath = path . join ( root , "registry" , "bin" , xlingsBinaryName ) ;
126129 mkdirSync ( path . dirname ( xlingsPath ) , { recursive : true } ) ;
127130 writeFileSync ( xlingsPath , "#!/bin/sh\n" ) ;
128131 const runner = async ( ) => ( {
@@ -140,20 +143,47 @@ test("resolveXlingsExecutable reads the xlings binary from `mcpp self env`", asy
140143 }
141144} ) ;
142145
143- test ( "resolveXlingsExecutable falls back when the reported path does not exist" , async ( ) => {
146+ test ( "resolveXlingsExecutable passes a timeout to `mcpp self env`" , async ( ) => {
147+ let captured : { timeoutMs ?: number } | undefined ;
148+ const runner = async (
149+ _executable : string ,
150+ _args : string [ ] ,
151+ _cwd ?: string ,
152+ options ?: { timeoutMs ?: number } ,
153+ ) => {
154+ captured = options ;
155+ return { exitCode : 0 , stdout : "" , stderr : "" } ;
156+ } ;
157+ await resolveXlingsExecutable ( "/tools/mcpp" , runner ) ;
158+ assert . equal ( captured ?. timeoutMs , 60_000 ) ;
159+ } ) ;
160+
161+ test ( "resolveXlingsExecutable falls back to path probing when the reported path does not exist" , async ( ) => {
162+ const home = mkdtempSync ( path . join ( os . tmpdir ( ) , "mcpp-vscode-fallback-missing-" ) ) ;
144163 const runner = async ( ) => ( {
145164 exitCode : 0 ,
146165 stdout : "xlings binary = /no/such/xlings\n" ,
147166 stderr : "" ,
148167 } ) ;
149- const result = await resolveXlingsExecutable ( "/tools/mcpp" , runner ) ;
150- // Fallback heuristics find nothing in this environment, so the result is
151- // undefined unless a standalone ~/.xlings or PATH xlings happens to exist.
152- assert . ok ( result === undefined || typeof result === "string" ) ;
168+ try {
169+ assert . equal (
170+ await resolveXlingsExecutable ( "/tools/mcpp" , runner , { home, env : { } } ) ,
171+ undefined ,
172+ ) ;
173+ } finally {
174+ rmSync ( home , { recursive : true , force : true } ) ;
175+ }
153176} ) ;
154177
155- test ( "resolveXlingsExecutable falls back when `mcpp self env` fails" , async ( ) => {
178+ test ( "resolveXlingsExecutable falls back to path probing when `mcpp self env` fails" , async ( ) => {
179+ const home = mkdtempSync ( path . join ( os . tmpdir ( ) , "mcpp-vscode-fallback-fail-" ) ) ;
156180 const runner = async ( ) => ( { exitCode : 1 , stdout : "" , stderr : "boom\n" } ) ;
157- const result = await resolveXlingsExecutable ( "/tools/mcpp" , runner ) ;
158- assert . ok ( result === undefined || typeof result === "string" ) ;
181+ try {
182+ assert . equal (
183+ await resolveXlingsExecutable ( "/tools/mcpp" , runner , { home, env : { } } ) ,
184+ undefined ,
185+ ) ;
186+ } finally {
187+ rmSync ( home , { recursive : true , force : true } ) ;
188+ }
159189} ) ;
0 commit comments