Skip to content
This repository was archived by the owner on Aug 7, 2023. It is now read-only.

Commit 9f2ac4d

Browse files
author
Ted Behling
committed
Specs for useProjectCwd
1 parent 5b30302 commit 9f2ac4d

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/sh
2+
3+
# "project root" in the test suite is spec/fixtures/
4+
#shellcheck source=../clean.sh
5+
. clean.sh
6+
echo "file relative"
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/sh
2+
3+
# "project root" in the test suite is spec/fixtures/
4+
#shellcheck source=clean.sh
5+
. clean.sh
6+
echo "project relative"

spec/linter-shellcheck-spec.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ const { lint } = require('../lib/main.js').provideLinter();
88

99
const cleanPath = path.join(__dirname, 'fixtures', 'clean.sh');
1010
const badPath = path.join(__dirname, 'fixtures', 'bad.sh');
11+
const sourceFileRelativePath = path.join(__dirname, 'fixtures', 'source_directive', 'file_relative.sh');
12+
const sourceProjectRelativePath = path.join(__dirname, 'fixtures', 'source_directive', 'project_relative.sh');
1113

1214
describe('The ShellCheck provider for Linter', () => {
1315
beforeEach(async () => {
@@ -44,4 +46,41 @@ describe('The ShellCheck provider for Linter', () => {
4446
expect(messages[0].filePath).toBe(badPath);
4547
expect(messages[0].range).toEqual([[0, 0], [0, 4]]);
4648
});
49+
50+
describe('implements useProjectCwd and', () => {
51+
beforeEach(async () => {
52+
atom.config.set('linter-shellcheck.userParameters', '-x');
53+
atom.config.set('linter-shellcheck.enableNotice', true);
54+
});
55+
56+
it('uses file-relative source= directives by default', async () => {
57+
atom.config.set('linter-shellcheck.useProjectCwd', false);
58+
const editor = await atom.workspace.open(sourceFileRelativePath);
59+
const messages = await lint(editor);
60+
expect(messages.length).toBe(0);
61+
});
62+
63+
it('errors for file-relative source= path with useProjectCwd = true', async () => {
64+
atom.config.set('linter-shellcheck.useProjectCwd', true);
65+
const editor = await atom.workspace.open(sourceFileRelativePath);
66+
const messages = await lint(editor);
67+
expect(messages.length).toBe(1);
68+
expect(messages[0].html).toMatch(/openBinaryFile: does not exist/);
69+
});
70+
71+
it('uses project-relative source= directives via setting (based at fixtures/)', async () => {
72+
atom.config.set('linter-shellcheck.useProjectCwd', true);
73+
const editor = await atom.workspace.open(sourceProjectRelativePath);
74+
const messages = await lint(editor);
75+
expect(messages.length).toBe(0);
76+
});
77+
78+
it('errors for project-relative source= path with useProjectCwd = false (based at fixtures/)', async () => {
79+
atom.config.set('linter-shellcheck.useProjectCwd', false);
80+
const editor = await atom.workspace.open(sourceProjectRelativePath);
81+
const messages = await lint(editor);
82+
expect(messages.length).toBe(1);
83+
expect(messages[0].html).toMatch(/openBinaryFile: does not exist/);
84+
});
85+
});
4786
});

0 commit comments

Comments
 (0)