13
13
//===----------------------------------------------------------------------===//
14
14
15
15
import * as vscode from "vscode" ;
16
- import { testAssetPath , testAssetUri } from "../fixtures" ;
16
+ import { testAssetUri } from "../fixtures" ;
17
17
import { waitForNoRunningTasks } from "../utilities/tasks" ;
18
18
import { expect } from "chai" ;
19
19
import {
@@ -22,19 +22,14 @@ import {
22
22
waitUntilDebugSessionTerminates ,
23
23
} from "../utilities/debug" ;
24
24
import { Version } from "../../src/utilities/version" ;
25
- import { activateExtensionForSuite , folderInRootWorkspace } from "./utilities/testutilities" ;
25
+ import {
26
+ activateExtensionForSuite ,
27
+ folderInRootWorkspace ,
28
+ updateSettings ,
29
+ } from "./utilities/testutilities" ;
26
30
import { WorkspaceContext } from "../../src/WorkspaceContext" ;
27
- import { join } from "path" ;
28
31
import { closeAllEditors } from "../utilities/commands" ;
29
-
30
- function normalizePath ( ...segments : string [ ] ) : string {
31
- let path = join ( ...segments ) ;
32
- if ( process . platform === "win32" ) {
33
- path = path . endsWith ( ".exe" ) ? path : path + ".exe" ;
34
- path = path . replace ( / \/ / g, "\\" ) ;
35
- }
36
- return path . toLocaleLowerCase ( ) ; // Windows may use d:\ or D:\
37
- }
32
+ import { Commands } from "../../src/commands" ;
38
33
39
34
suite ( "SwiftSnippet Test Suite @slow" , function ( ) {
40
35
this . timeout ( 180000 ) ;
@@ -44,41 +39,49 @@ suite("SwiftSnippet Test Suite @slow", function () {
44
39
new vscode . SourceBreakpoint ( new vscode . Location ( uri , new vscode . Position ( 2 , 0 ) ) ) ,
45
40
] ;
46
41
let workspaceContext : WorkspaceContext ;
42
+ let resetSettings : ( ( ) => Promise < void > ) | undefined ;
47
43
48
44
activateExtensionForSuite ( {
49
45
async setup ( ctx ) {
50
46
workspaceContext = ctx ;
51
47
52
48
const folder = await folderInRootWorkspace ( "defaultPackage" , workspaceContext ) ;
53
- if ( folder . toolchain . swiftVersion . isLessThan ( new Version ( 5 , 9 , 0 ) ) ) {
49
+ if ( folder . toolchain . swiftVersion . isLessThan ( new Version ( 5 , 10 , 0 ) ) ) {
54
50
this . skip ( ) ;
55
51
}
52
+ resetSettings = await updateSettings ( {
53
+ "swift.debugger.debugAdapter" : "lldb-dap" ,
54
+ } ) ;
56
55
await waitForNoRunningTasks ( ) ;
57
56
58
57
// File needs to be open for command to be enabled
59
- const doc = await vscode . workspace . openTextDocument ( uri . fsPath ) ;
60
- await vscode . window . showTextDocument ( doc ) ;
58
+ await workspaceContext . focusFolder ( folder ) ;
59
+ await vscode . window . showTextDocument ( uri ) ;
61
60
62
61
// Set a breakpoint
63
62
vscode . debug . addBreakpoints ( breakpoints ) ;
64
63
} ,
64
+ async teardown ( ) {
65
+ await closeAllEditors ( ) ;
66
+ vscode . debug . removeBreakpoints ( breakpoints ) ;
67
+ if ( resetSettings ) {
68
+ await resetSettings ( ) ;
69
+ }
70
+ } ,
65
71
requiresDebugger : true ,
66
72
} ) ;
67
73
68
- suiteTeardown ( async ( ) => {
69
- closeAllEditors ( ) ;
70
- vscode . debug . removeBreakpoints ( breakpoints ) ;
71
- } ) ;
72
-
73
74
test ( "Run `Swift: Run Swift Snippet` command for snippet file" , async ( ) => {
74
75
const sessionPromise = waitUntilDebugSessionTerminates ( "Run hello" ) ;
75
76
76
- const succeeded = await vscode . commands . executeCommand ( "swift.runSnippet ") ;
77
+ const succeeded = await vscode . commands . executeCommand ( Commands . RUN_SNIPPET , "hello ") ;
77
78
78
79
expect ( succeeded ) . to . be . true ;
79
80
const session = await sessionPromise ;
80
- expect ( normalizePath ( session . configuration . program ) ) . to . equal (
81
- normalizePath ( testAssetPath ( "defaultPackage" ) , ".build" , "debug" , "hello" )
81
+ expect ( vscode . Uri . file ( session . configuration . program ) . fsPath ) . to . equal (
82
+ testAssetUri (
83
+ "defaultPackage/.build/debug/hello" + ( process . platform === "win32" ? ".exe" : "" )
84
+ ) . fsPath
82
85
) ;
83
86
expect ( session . configuration ) . to . have . property ( "noDebug" , true ) ;
84
87
} ) ;
@@ -91,16 +94,34 @@ suite("SwiftSnippet Test Suite @slow", function () {
91
94
) ;
92
95
const sessionPromise = waitUntilDebugSessionTerminates ( "Run hello" ) ;
93
96
94
- const succeeded = vscode . commands . executeCommand ( "swift.debugSnippet" ) ;
97
+ console . log ( "here 1" ) ;
98
+ const succeededPromise : Thenable < boolean > = vscode . commands . executeCommand (
99
+ Commands . DEBUG_SNIPPET ,
100
+ "hello"
101
+ ) ;
102
+
103
+ console . log ( "here 2" ) ;
95
104
96
105
// Once bp is hit, continue
97
- await bpPromise . then ( ( ) => continueSession ( ) ) ;
106
+ await bpPromise ;
107
+ console . log ( "here 3" ) ;
108
+ let succeeded = false ;
109
+ succeededPromise . then ( s => ( succeeded = s ) ) ;
110
+ while ( ! succeeded ) {
111
+ console . log ( "here continue" ) ;
112
+ await continueSession ( ) ;
113
+ console . log ( "here continued" ) ;
114
+ await new Promise ( r => setTimeout ( r , 500 ) ) ;
115
+ }
116
+ console . log ( "here 4" ) ;
98
117
99
- await expect ( succeeded ) . to . eventually . be . true ;
118
+ expect ( succeeded ) . to . be . true ;
100
119
101
120
const session = await sessionPromise ;
102
- expect ( normalizePath ( session . configuration . program ) ) . to . equal (
103
- normalizePath ( testAssetPath ( "defaultPackage" ) , ".build" , "debug" , "hello" )
121
+ expect ( vscode . Uri . file ( session . configuration . program ) . fsPath ) . to . equal (
122
+ testAssetUri (
123
+ "defaultPackage/.build/debug/hello" + ( process . platform === "win32" ? ".exe" : "" )
124
+ ) . fsPath
104
125
) ;
105
126
expect ( session . configuration ) . to . not . have . property ( "noDebug" ) ;
106
127
} ) ;
0 commit comments