@@ -68,7 +68,6 @@ export function testAtCursor(goConfig: vscode.WorkspaceConfiguration, cmd: TestA
6868 * Runs the test at cursor.
6969 */
7070async function runTestAtCursor ( editor : vscode . TextEditor , testFunctionName : string , testFunctions : vscode . DocumentSymbol [ ] , goConfig : vscode . WorkspaceConfiguration , cmd : TestAtCursorCmd , args : any ) {
71- const { tmpCoverPath, testFlags } = makeCoverData ( goConfig , 'coverOnSingleTest' , args ) ;
7271
7372 const testConfigFns = cmd !== 'benchmark' && extractInstanceTestName ( testFunctionName )
7473 ? [ testFunctionName , ...findAllTestSuiteRuns ( editor . document , testFunctions ) . map ( t => t . name ) ]
@@ -78,17 +77,15 @@ async function runTestAtCursor(editor: vscode.TextEditor, testFunctionName: stri
7877 const testConfig : TestConfig = {
7978 goConfig,
8079 dir : path . dirname ( editor . document . fileName ) ,
81- flags : testFlags ,
80+ flags : getTestFlags ( goConfig , args ) ,
8281 functions : testConfigFns ,
8382 isBenchmark : cmd === 'benchmark' ,
84- isMod
83+ isMod,
84+ applyCodeCoverage : goConfig . get < boolean > ( 'coverOnSingleTest' )
8585 } ;
8686 // Remember this config as the last executed test.
8787 lastTestConfig = testConfig ;
88- await goTest ( testConfig ) ;
89- if ( tmpCoverPath ) {
90- return applyCodeCoverageToAllEditors ( tmpCoverPath , testConfig . dir ) ;
91- }
88+ return goTest ( testConfig ) ;
9289}
9390
9491/**
@@ -132,34 +129,25 @@ async function debugTestAtCursor(editor: vscode.TextEditor, testFunctionName: st
132129 *
133130 * @param goConfig Configuration for the Go extension.
134131 */
135- export function testCurrentPackage ( goConfig : vscode . WorkspaceConfiguration , isBenchmark : boolean , args : any ) {
132+ export async function testCurrentPackage ( goConfig : vscode . WorkspaceConfiguration , isBenchmark : boolean , args : any ) {
136133 const editor = vscode . window . activeTextEditor ;
137134 if ( ! editor ) {
138135 vscode . window . showInformationMessage ( 'No editor is active.' ) ;
139136 return ;
140137 }
141138
142- const { tmpCoverPath, testFlags } = makeCoverData ( goConfig , 'coverOnTestPackage' , args ) ;
143-
139+ const isMod = await isModSupported ( editor . document . uri ) ;
144140 const testConfig : TestConfig = {
145141 goConfig,
146142 dir : path . dirname ( editor . document . fileName ) ,
147- flags : testFlags ,
143+ flags : getTestFlags ( goConfig , args ) ,
148144 isBenchmark,
145+ isMod,
146+ applyCodeCoverage : goConfig . get < boolean > ( 'coverOnTestPackage' )
149147 } ;
150148 // Remember this config as the last executed test.
151149 lastTestConfig = testConfig ;
152-
153- isModSupported ( editor . document . uri ) . then ( isMod => {
154- testConfig . isMod = isMod ;
155- return goTest ( testConfig ) . then ( success => {
156- if ( tmpCoverPath ) {
157- return applyCodeCoverageToAllEditors ( tmpCoverPath , testConfig . dir ) ;
158- }
159- } , err => {
160- console . log ( err ) ;
161- } ) ;
162- } ) ;
150+ return goTest ( testConfig ) ;
163151}
164152
165153/**
@@ -200,7 +188,7 @@ export function testWorkspace(goConfig: vscode.WorkspaceConfiguration, args: any
200188 * @param goConfig Configuration for the Go extension.
201189 * @param isBenchmark Boolean flag indicating if these are benchmark tests or not.
202190 */
203- export function testCurrentFile ( goConfig : vscode . WorkspaceConfiguration , isBenchmark : boolean , args : string [ ] ) : Thenable < boolean > {
191+ export async function testCurrentFile ( goConfig : vscode . WorkspaceConfiguration , isBenchmark : boolean , args : string [ ] ) : Promise < boolean > {
204192 const editor = vscode . window . activeTextEditor ;
205193 if ( ! editor ) {
206194 vscode . window . showInformationMessage ( 'No editor is active.' ) ;
@@ -211,32 +199,23 @@ export function testCurrentFile(goConfig: vscode.WorkspaceConfiguration, isBench
211199 return ;
212200 }
213201
214- const { tmpCoverPath, testFlags } = makeCoverData ( goConfig , 'coverOnSingleTestFile' , args ) ;
215202 const getFunctions = isBenchmark ? getBenchmarkFunctions : getTestFunctions ;
203+ const isMod = await isModSupported ( editor . document . uri ) ;
216204
217205 return editor . document . save ( ) . then ( ( ) => {
218206 return getFunctions ( editor . document , null ) . then ( testFunctions => {
219207 const testConfig : TestConfig = {
220208 goConfig,
221209 dir : path . dirname ( editor . document . fileName ) ,
222- flags : testFlags ,
210+ flags : getTestFlags ( goConfig , args ) ,
223211 functions : testFunctions . map ( sym => sym . name ) ,
224212 isBenchmark,
213+ isMod,
214+ applyCodeCoverage : goConfig . get < boolean > ( 'coverOnSingleTestFile' )
225215 } ;
226216 // Remember this config as the last executed test.
227217 lastTestConfig = testConfig ;
228-
229- return isModSupported ( editor . document . uri ) . then ( isMod => {
230- testConfig . isMod = isMod ;
231- return goTest ( testConfig ) . then ( success => {
232- if ( tmpCoverPath ) {
233- applyCodeCoverageToAllEditors ( tmpCoverPath , testConfig . dir ) ;
234- }
235- return Promise . resolve ( success ) ;
236- } , err => {
237- console . log ( err ) ;
238- } ) ;
239- } ) ;
218+ return goTest ( testConfig ) ;
240219 } ) ;
241220 } ) . then ( null , err => {
242221 console . error ( err ) ;
@@ -256,19 +235,3 @@ export function testPrevious() {
256235 console . error ( err ) ;
257236 } ) ;
258237}
259-
260- /**
261- * Computes the tmp coverage path and needed flags.
262- *
263- * @param goConfig Configuration for the Go extension.
264- */
265- function makeCoverData ( goConfig : vscode . WorkspaceConfiguration , confFlag : string , args : any ) : { tmpCoverPath : string , testFlags : string [ ] } {
266- let tmpCoverPath = '' ;
267- const testFlags = getTestFlags ( goConfig , args ) || [ ] ;
268- if ( goConfig [ confFlag ] === true ) {
269- tmpCoverPath = getTempFilePath ( 'go-code-cover' ) ;
270- testFlags . push ( '-coverprofile=' + tmpCoverPath ) ;
271- }
272-
273- return { tmpCoverPath, testFlags } ;
274- }
0 commit comments