mirror of
https://github.com/Strum355/mcshader-lsp.git
synced 2025-08-04 00:49:17 +00:00
Some simple tests. Had to make some methods public but AH WELL
This commit is contained in:
parent
ba26a5eba1
commit
326c5aa42c
6 changed files with 56 additions and 36 deletions
|
@ -4,6 +4,7 @@ pipeline:
|
|||
commands:
|
||||
- npm i
|
||||
- npm run lint
|
||||
- npm run test
|
||||
|
||||
matrix:
|
||||
NODE_VERSION:
|
||||
|
|
|
@ -36,11 +36,20 @@ export default class GLSLProvider implements vscode.CodeActionProvider {
|
|||
private diagnosticCollection: vscode.DiagnosticCollection // where errors/warnings/hints are pushed to be displayed
|
||||
private config: Config
|
||||
|
||||
constructor(subs: vscode.Disposable[]) {
|
||||
public static readonly binaryFound: string = '[MC-GLSL] glslangValidator found!'
|
||||
public static readonly binaryNotFound: string = '[MC-GLSL] glslangValidator not found. Please check that you\'ve given the right path. ' +
|
||||
'Use the config option "mcglsl.glslangValidatorPath" to point to its location'
|
||||
|
||||
constructor(subs: vscode.Disposable[], config?: Config) {
|
||||
this.diagnosticCollection = vscode.languages.createDiagnosticCollection()
|
||||
|
||||
subs.push(this)
|
||||
this.config = this.initConfig()
|
||||
if (config !== null) {
|
||||
this.config = this.initConfig()
|
||||
} else {
|
||||
this.config = config
|
||||
}
|
||||
|
||||
this.checkBinary()
|
||||
|
||||
try {
|
||||
|
@ -86,18 +95,18 @@ export default class GLSLProvider implements vscode.CodeActionProvider {
|
|||
}
|
||||
|
||||
// Check if glslangValidator binary can be found
|
||||
private checkBinary() {
|
||||
public checkBinary(): string {
|
||||
const ret = shell.which(this.config.glslangPath)
|
||||
|
||||
if(ret == null) {
|
||||
vscode.window.showErrorMessage(
|
||||
'[MC-GLSL] glslangValidator not found. Please check that you\'ve given the right path.' +
|
||||
' Use the config option "mcglsl.glslangValidatorPath" to point to its location'
|
||||
)
|
||||
} else {
|
||||
// Do we want this here? ¯\_(ツ)_/¯
|
||||
// vscode.window.showInformationMessage('[MC-GLSL] glslangValidator found!')
|
||||
console.log(GLSLProvider.binaryNotFound)
|
||||
vscode.window.showErrorMessage(GLSLProvider.binaryNotFound)
|
||||
return GLSLProvider.binaryNotFound
|
||||
}
|
||||
|
||||
// Do we want this here? ¯\_(ツ)_/¯
|
||||
// vscode.window.showInformationMessage('[MC-GLSL] glslangValidator found!')
|
||||
return GLSLProvider.binaryFound
|
||||
}
|
||||
|
||||
public dispose() {
|
||||
|
@ -111,7 +120,7 @@ export default class GLSLProvider implements vscode.CodeActionProvider {
|
|||
}
|
||||
|
||||
// Returns true if the string matches any of the regex
|
||||
private matchesFilters(s: string): boolean {
|
||||
public matchesFilters(s: string): boolean {
|
||||
return filters.some((reg: RegExp, i: number, array: RegExp[]) => {
|
||||
return reg.test(s)
|
||||
})
|
||||
|
@ -123,7 +132,7 @@ export default class GLSLProvider implements vscode.CodeActionProvider {
|
|||
const res = cp.spawnSync(this.config.glslangPath, [linkname]).output[1].toString()
|
||||
return res.split(/(?:\n)/g)
|
||||
.filter((s: string) => s !== '')
|
||||
.slice(1, -2) // why did this work as -1 before and now it needs -2???
|
||||
.slice(1, -1) // TODO not this
|
||||
.filter((s: string) => !this.matchesFilters(s))
|
||||
}
|
||||
|
||||
|
@ -174,7 +183,7 @@ export default class GLSLProvider implements vscode.CodeActionProvider {
|
|||
if (this.config.isWin) {
|
||||
shell.ln(document.uri.fsPath, linkname)
|
||||
} else {
|
||||
shell.ln('-s', document.uri.fsPath, linkname)
|
||||
shell.ln('-sf', document.uri.fsPath, linkname)
|
||||
}
|
||||
|
||||
if(shell.error()) {
|
||||
|
|
|
@ -1,22 +0,0 @@
|
|||
//
|
||||
// Note: This example test is leveraging the Mocha test framework.
|
||||
// Please refer to their documentation on https://mochajs.org/ for help.
|
||||
//
|
||||
|
||||
// The module 'assert' provides assertion methods from node
|
||||
import * as assert from 'assert';
|
||||
|
||||
// You can import and use all API from the 'vscode' module
|
||||
// as well as import your extension to test it
|
||||
// import * as vscode from 'vscode';
|
||||
// import * as myExtension from '../extension';
|
||||
|
||||
// Defines a Mocha test suite to group tests of similar kind together
|
||||
suite('Extension Tests', () => {
|
||||
|
||||
// Defines a Mocha unit test
|
||||
test('Something 1', () => {
|
||||
assert.equal(-1, [1, 2, 3].indexOf(5));
|
||||
assert.equal(-1, [1, 2, 3].indexOf(0));
|
||||
});
|
||||
});
|
31
test/extension.test.ts
Normal file
31
test/extension.test.ts
Normal file
|
@ -0,0 +1,31 @@
|
|||
import * as assert from 'assert';
|
||||
import * as vscode from 'vscode'
|
||||
import * as provider from '../src/linter/glslProvider'
|
||||
import * as fs from 'fs'
|
||||
import * as shell from 'shelljs'
|
||||
|
||||
suite('Extension Tests', () => {
|
||||
const inst = new provider.default([], {
|
||||
glslangPath: 'glslangValidator',
|
||||
tmpdir: '',
|
||||
isWin: false
|
||||
})
|
||||
|
||||
/* test('Check for binary', () => {
|
||||
inst.checkBinary()
|
||||
shell.which(inst.)
|
||||
}) */
|
||||
|
||||
test('Check filters', () => {
|
||||
const strings = [
|
||||
'ERROR: 0:61: \'#include\' : required extension not requested: GL_GOOGLE_include_directive',
|
||||
'ERROR: 0:10: \'\' : syntax error',
|
||||
'ERROR: 0:23: \'owo\' compilation terminated',
|
||||
'WARNING: 4:20: \'xd\' no code generated'
|
||||
]
|
||||
|
||||
strings.forEach((s: string) => {
|
||||
assert.equal(true, inst.matchesFilters(s))
|
||||
})
|
||||
})
|
||||
});
|
|
@ -14,6 +14,7 @@
|
|||
},
|
||||
"exclude": [
|
||||
"node_modules",
|
||||
".vscode-test"
|
||||
".vscode-test",
|
||||
"test"
|
||||
]
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue