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

Commit 8248559

Browse files
committed
Rework tests to exercise mix and elixirc paths
1 parent 9207b3d commit 8248559

File tree

4 files changed

+114
-39
lines changed

4 files changed

+114
-39
lines changed

spec/fixtures/proj/lib/proj.ex

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,16 @@ defmodule Proj do
1818
end
1919

2020
def handle_call({:get, key}, _caller, state) do
21+
prepare_for_call
2122
{:reply, Map.get(state, key), state}
2223
end
2324

2425
def handle_cast({:put, key, val}, state) do
2526
{:noreply, Map.put(state, key, val), state}
2627
end
2728

29+
def prepare_for_call() do
30+
:ok
31+
end
32+
2833
end

spec/fixtures/proj/mix.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ defmodule Proj.Mixfile do
77
elixir: "~> 1.4",
88
build_embedded: Mix.env == :prod,
99
start_permanent: Mix.env == :prod,
10-
deps: deps]
10+
deps: deps()]
1111
end
1212

1313
# Configuration for the OTP application

spec/fixtures/script.exs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
defmodule Script do
2+
defp simple_function do
3+
:ok
4+
end
5+
end

spec/linter-elixirc-spec.js

Lines changed: 103 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,115 @@
11
'use babel';
22

33
import { join } from 'path';
4+
import { remove } from 'fs-extra';
45

56
const validPath = join(__dirname, 'fixtures', 'valid.ex');
6-
const warningPath = join(__dirname, 'fixtures', 'proj', 'mix.exs');
7+
const warningPath = join(__dirname, 'fixtures', 'proj', 'lib', 'proj.ex');
78
const errorMode1Path = join(__dirname, 'fixtures', 'error-mode1.ex');
89
const errorMode2Path = join(__dirname, 'fixtures', 'error-mode2.ex');
10+
const exsFilePath = join(__dirname, 'fixtures', 'script.exs');
11+
12+
const mixBuildDirectory = join(__dirname, 'fixtures', 'proj', '_build');
13+
remove(mixBuildDirectory);
914

1015
describe('The elixirc provider for Linter', () => {
11-
const lint = require('../lib/init.js').provideLinter().lint;
16+
describe('when using the standard configuration', () => {
17+
let lint;
18+
19+
beforeEach(() => {
20+
atom.config.set('linter-elixirc.forceElixirc', false);
21+
lint = require('../lib/init.js').provideLinter().lint;
22+
atom.workspace.destroyActivePaneItem();
23+
24+
waitsForPromise(() =>
25+
Promise.all([
26+
atom.packages.activatePackage('linter-elixirc'),
27+
atom.packages.activatePackage('language-elixir'),
28+
]),
29+
);
30+
});
31+
32+
it('works with mode 1 errors', () => {
33+
waitsForPromise(() =>
34+
atom.workspace.open(errorMode1Path).then(editor => lint(editor)).then((messages) => {
35+
expect(messages.length).toBe(1);
36+
expect(messages[0].severity).toBe('error');
37+
expect(messages[0].html).not.toBeDefined();
38+
expect(messages[0].excerpt).toBe('(ArgumentError) Dangerous is not available');
39+
expect(messages[0].location.file).toBe(errorMode1Path);
40+
expect(messages[0].location.position).toEqual([[1, 0], [1, 32]]);
41+
}),
42+
);
43+
});
44+
45+
it('works with mode 1 errors for elixirc', () => {
46+
waitsForPromise(() =>
47+
atom.workspace.open(errorMode1Path).then(editor => lint(editor)).then((messages) => {
48+
expect(messages.length).toBe(1);
49+
expect(messages[0].severity).toBe('error');
50+
expect(messages[0].html).not.toBeDefined();
51+
expect(messages[0].excerpt).toBe('(ArgumentError) Dangerous is not available');
52+
expect(messages[0].location.file).toBe(errorMode1Path);
53+
expect(messages[0].location.position).toEqual([[1, 0], [1, 32]]);
54+
}),
55+
);
56+
});
57+
58+
it('works with mode 2 errors', () => {
59+
waitsForPromise(() =>
60+
atom.workspace.open(errorMode2Path).then(editor => lint(editor)).then((messages) => {
61+
expect(messages.length).toBe(1);
62+
expect(messages[0].severity).toBe('error');
63+
expect(messages[0].html).not.toBeDefined();
64+
expect(messages[0].excerpt).toBe('(CompileError) module Usefulness is not loaded and could not be found');
65+
expect(messages[0].location.file).toBe(errorMode2Path);
66+
expect(messages[0].location.position).toEqual([[3, 2], [3, 20]]);
67+
}),
68+
);
69+
});
70+
71+
it('works with warnings', () => {
72+
waitsForPromise(() =>
73+
atom.workspace.open(warningPath).then(editor => lint(editor)).then((messages) => {
74+
expect(messages.length).toBe(1);
75+
expect(messages[0].severity).toBe('warning');
76+
expect(messages[0].html).not.toBeDefined();
77+
expect(messages[0].excerpt).toBe('variable "prepare_for_call" does not exist and is being expanded to "prepare_for_call()", please use parentheses to remove the ambiguity or change the variable name');
78+
expect(messages[0].location.file).toBe(warningPath);
79+
expect(messages[0].location.position).toEqual([[20, 4], [20, 20]]);
80+
}),
81+
);
82+
});
83+
84+
it('works with .exs files', () => {
85+
waitsForPromise(() =>
86+
atom.workspace.open(exsFilePath).then(editor => lint(editor)).then((messages) => {
87+
expect(messages.length).toBe(1);
88+
expect(messages[0].severity).toBe('warning');
89+
expect(messages[0].html).not.toBeDefined();
90+
expect(messages[0].excerpt).toBe('function simple_function/0 is unused');
91+
expect(messages[0].location.file).toBe(exsFilePath);
92+
expect(messages[0].location.position).toEqual([[1, 2], [1, 25]]);
93+
}),
94+
);
95+
});
96+
97+
it('finds nothing wrong with a valid file', () => {
98+
waitsForPromise(() =>
99+
atom.workspace.open(validPath).then(editor => lint(editor)).then((messages) => {
100+
expect(messages.length).toBe(0);
101+
}),
102+
);
103+
});
104+
});
105+
});
106+
107+
describe('when using the setting forceElixirc', () => {
108+
let lint;
12109

13110
beforeEach(() => {
111+
atom.config.set('linter-elixirc.forceElixirc', true);
112+
lint = require('../lib/init.js').provideLinter().lint;
14113
atom.workspace.destroyActivePaneItem();
15114

16115
waitsForPromise(() =>
@@ -21,49 +120,15 @@ describe('The elixirc provider for Linter', () => {
21120
);
22121
});
23122

24-
it('works with mode 1 errors', () => {
25-
waitsForPromise(() =>
26-
atom.workspace.open(errorMode1Path).then(editor => lint(editor)).then((messages) => {
27-
expect(messages.length).toBe(1);
28-
expect(messages[0].severity).toBe('error');
29-
expect(messages[0].html).not.toBeDefined();
30-
expect(messages[0].excerpt).toBe('(ArgumentError) Dangerous is not available');
31-
expect(messages[0].location.file).toBe(errorMode1Path);
32-
expect(messages[0].location.position).toEqual([[1, 0], [1, 32]]);
33-
}),
34-
);
35-
});
36-
37-
it('works with mode 2 errors', () => {
38-
waitsForPromise(() =>
39-
atom.workspace.open(errorMode2Path).then(editor => lint(editor)).then((messages) => {
40-
expect(messages.length).toBe(1);
41-
expect(messages[0].severity).toBe('error');
42-
expect(messages[0].html).not.toBeDefined();
43-
expect(messages[0].excerpt).toBe('(CompileError) module Usefulness is not loaded and could not be found');
44-
expect(messages[0].location.file).toBe(errorMode2Path);
45-
expect(messages[0].location.position).toEqual([[3, 2], [3, 20]]);
46-
}),
47-
);
48-
});
49-
50123
it('works with warnings', () => {
51124
waitsForPromise(() =>
52125
atom.workspace.open(warningPath).then(editor => lint(editor)).then((messages) => {
53126
expect(messages.length).toBe(1);
54127
expect(messages[0].severity).toBe('warning');
55128
expect(messages[0].html).not.toBeDefined();
56-
expect(messages[0].excerpt).toBe('variable "deps" does not exist and is being expanded to "deps()", please use parentheses to remove the ambiguity or change the variable name');
129+
expect(messages[0].excerpt).toBe('variable "prepare_for_call" does not exist and is being expanded to "prepare_for_call()", please use parentheses to remove the ambiguity or change the variable name');
57130
expect(messages[0].location.file).toBe(warningPath);
58-
expect(messages[0].location.position).toEqual([[9, 5], [9, 16]]);
59-
}),
60-
);
61-
});
62-
63-
it('finds nothing wrong with a valid file', () => {
64-
waitsForPromise(() =>
65-
atom.workspace.open(validPath).then(editor => lint(editor)).then((messages) => {
66-
expect(messages.length).toBe(0);
131+
expect(messages[0].location.position).toEqual([[20, 4], [20, 20]]);
67132
}),
68133
);
69134
});

0 commit comments

Comments
 (0)