Skip to content

Commit

Permalink
Add test case for #181
Browse files Browse the repository at this point in the history
Works under Linux...
  • Loading branch information
adangel committed Nov 29, 2024
1 parent 4753d35 commit cdcb2bb
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
7 changes: 7 additions & 0 deletions test/assets/project2 - with & and space/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# project2 - with & and space

The tests uses this folder as `workspaceRootPath` - and the folder name contains spaces and an ampersand.
This might need to be quoted, depending on the operating system.
The ampersand is often used as a conditional operator to execute two commands (AND logic).

This tests issue [#181](https://github.com/ChuckJonas/vscode-apex-pmd/issues/181)
10 changes: 10 additions & 0 deletions test/assets/project2 - with & and space/test.cls
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// test case for https://github.com/ChuckJonas/vscode-apex-pmd/issues/181

// Test apex that should return a single error
public class Test {
public Test() {
while (true) {
Account acc = [SELECT Id FROM Account]; // expected violation from rule: Performance-OperationWithLimitsInLoop
}
}
}
37 changes: 37 additions & 0 deletions test/suite/extension.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,43 @@ suite('Extension Tests', () => {
});
});

test('test workspace root path with spaces and ampersand (#181)', function (done) {
this.timeout(100000);

const workspaceRootPath = path.join(TEST_ASSETS_PATH, 'project2 - with & and space');
const apexClassFile = path.join(workspaceRootPath, 'test.cls');

const collection = vscode.languages.createDiagnosticCollection('apex-pmd-test');

const config = new Config();
config.pmdBinPath = PMD_PATH;
config.rulesets = [RULESET_PATH];
config.priorityErrorThreshold = 3;
config.priorityWarnThreshold = 1;
config.workspaceRootPath = workspaceRootPath;
config.additionalClassPaths = [];
config.commandBufferSize = 64000000;

const pmd = new ApexPmd(outputChannel, config);

const testApexUri = vscode.Uri.file(apexClassFile);
pmd
.run(apexClassFile, collection)
.then(() => {
const errs = collection.get(testApexUri);
assert.strictEqual(errs.length, 1);

const diagnostic = errs[0];
const code = diagnostic.code as {value :string };
assert.strictEqual(code.value, "OperationWithLimitsInLoop");
assert.strictEqual(diagnostic.range.start.line, 6); // vscode lines are 0-based
done();
})
.catch((e) => {
done(e);
});
});

test('test workspace root path with spaces and pmdBinPath with spaces', function (done) {
this.timeout(100000);

Expand Down

0 comments on commit cdcb2bb

Please sign in to comment.