@@ -5,7 +5,7 @@ import type { LJDiagnostic } from '../types/diagnostics';
55import type { LiquidJavaTestApi } from '../types/test-api' ;
66
77suite ( 'Bundled LiquidJava extension' , ( ) => {
8- test ( 'activates, becomes ready, and verifies the failing fixture' , async ( ) => {
8+ test ( 'activates, becomes ready, and verifies its isolated fixture' , async ( ) => {
99 const installed = vscode . extensions . getExtension < LiquidJavaTestApi > ( 'AlcidesFonseca.liquid-java' ) ;
1010 assert . ok ( installed , 'LiquidJava must be loaded in the Extension Host' ) ;
1111 assert . equal ( installed . packageJSON . main , './dist/extension.js' ) ;
@@ -16,17 +16,25 @@ suite('Bundled LiquidJava extension', () => {
1616 assert . notEqual ( api . getState ( ) . status , 'stopped' ) ;
1717
1818 const workspace = vscode . workspace . workspaceFolders ?. [ 0 ] ;
19- assert . ok ( workspace , 'the failing fixture must have its own workspace' ) ;
20- const uri = vscode . Uri . joinPath ( workspace . uri , 'src/main/java/FailingRefinement.java' ) ;
19+ assert . ok ( workspace , 'the fixture must have its own workspace' ) ;
20+ const passing = path . basename ( workspace . uri . fsPath ) === 'passing' ;
21+ const file = passing ? 'PassingRefinement.java' : 'FailingRefinement.java' ;
22+ const uri = vscode . Uri . joinPath ( workspace . uri , `src/main/java/${ file } ` ) ;
2123 const subscriptions : vscode . Disposable [ ] = [ ] ;
22- const nextFixtureDiagnostics = ( ) => new Promise < LJDiagnostic [ ] > ( ( resolve ) => {
23- const subscription = api . onDiagnostics ( ( diagnostics ) => {
24- if ( diagnostics . some ( d => d . type === 'refinement-error' && path . resolve ( d . file ) === uri . fsPath ) ) {
25- subscription . dispose ( ) ;
26- resolve ( diagnostics ) ;
27- }
24+ const nextFixtureDiagnostics = ( ) => new Promise < LJDiagnostic [ ] > ( ( resolve , reject ) => {
25+ const dispose = ( ) => {
26+ diagnosticsSubscription . dispose ( ) ;
27+ failureSubscription . dispose ( ) ;
28+ } ;
29+ const diagnosticsSubscription = api . onDiagnostics ( ( diagnostics ) => {
30+ dispose ( ) ;
31+ resolve ( diagnostics ) ;
2832 } ) ;
29- subscriptions . push ( subscription ) ;
33+ const failureSubscription = api . onFailure ( ( ) => {
34+ dispose ( ) ;
35+ reject ( new Error ( `LiquidJava verifier crashed while checking ${ file } (status: ${ api . getState ( ) . status } )` ) ) ;
36+ } ) ;
37+ subscriptions . push ( diagnosticsSubscription , failureSubscription ) ;
3038 } ) ;
3139 try {
3240 // settle automatic verification before testing the manual command
@@ -38,12 +46,17 @@ suite('Bundled LiquidJava extension', () => {
3846 const manualDiagnostics = nextFixtureDiagnostics ( ) ;
3947 await vscode . commands . executeCommand ( 'liquidjava.verify' ) ;
4048 const diagnostics = await manualDiagnostics ;
41- const error = diagnostics . find ( d => d . type === 'refinement-error' && path . resolve ( d . file ) === uri . fsPath ) ;
42- assert . ok ( error ) ;
43- assert . equal ( error . category , 'error' ) ;
44- assert . equal ( error . title , 'Refinement Error' ) ;
45- assert . ok ( error . position , 'the diagnostic must identify the invalid assignment' ) ;
46- assert . equal ( api . getState ( ) . status , 'failed' ) ;
49+ if ( passing ) {
50+ assert . deepEqual ( diagnostics , [ ] , 'correct code must emit an explicit empty result' ) ;
51+ assert . equal ( api . getState ( ) . status , 'passed' ) ;
52+ } else {
53+ const error = diagnostics . find ( d => d . type === 'refinement-error' && vscode . Uri . file ( path . resolve ( d . file ) ) . fsPath === uri . fsPath ) ;
54+ assert . ok ( error , `expected a refinement error for ${ file } ; received ${ JSON . stringify ( diagnostics ) } ` ) ;
55+ assert . equal ( error . category , 'error' ) ;
56+ assert . equal ( error . title , 'Refinement Error' ) ;
57+ assert . ok ( error . position , 'the diagnostic must identify the invalid assignment' ) ;
58+ assert . equal ( api . getState ( ) . status , 'failed' ) ;
59+ }
4760 assert . deepEqual ( api . getState ( ) . diagnostics , diagnostics ) ;
4861 } finally {
4962 subscriptions . forEach ( subscription => subscription . dispose ( ) ) ;
0 commit comments