1
1
'use babel' ;
2
2
3
3
import { join } from 'path' ;
4
+ import { remove } from 'fs-extra' ;
4
5
5
6
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 ') ;
7
8
const errorMode1Path = join ( __dirname , 'fixtures' , 'error-mode1.ex' ) ;
8
9
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 ) ;
9
14
10
15
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 ;
12
109
13
110
beforeEach ( ( ) => {
111
+ atom . config . set ( 'linter-elixirc.forceElixirc' , true ) ;
112
+ lint = require ( '../lib/init.js' ) . provideLinter ( ) . lint ;
14
113
atom . workspace . destroyActivePaneItem ( ) ;
15
114
16
115
waitsForPromise ( ( ) =>
@@ -21,49 +120,15 @@ describe('The elixirc provider for Linter', () => {
21
120
) ;
22
121
} ) ;
23
122
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
-
50
123
it ( 'works with warnings' , ( ) => {
51
124
waitsForPromise ( ( ) =>
52
125
atom . workspace . open ( warningPath ) . then ( editor => lint ( editor ) ) . then ( ( messages ) => {
53
126
expect ( messages . length ) . toBe ( 1 ) ;
54
127
expect ( messages [ 0 ] . severity ) . toBe ( 'warning' ) ;
55
128
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' ) ;
57
130
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 ] ] ) ;
67
132
} ) ,
68
133
) ;
69
134
} ) ;
0 commit comments