-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathFileTest.vala
More file actions
89 lines (78 loc) · 3.83 KB
/
FileTest.vala
File metadata and controls
89 lines (78 loc) · 3.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*
* Copyright (c) 2016-2019 elementary LLC. (https://github.com/elementary/vala-lint)
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*/
class FileTest : GLib.Object {
public struct FileTestMistake {
string title;
int line;
string? message;
}
public static void check_file_for_mistake (File file, Vala.ArrayList<FileTestMistake?> mistake_list) {
var linter = new ValaLint.Linter ();
linter.disable_mistakes = false;
try {
Vala.ArrayList<ValaLint.FormatMistake?> mistakes = linter.run_checks_for_file (file);
if (mistakes.size != mistake_list.size) {
error ("%s has %d but should have %d mistakes.", file.get_path (), mistakes.size, mistake_list.size);
}
for (int i = 0; i < mistakes.size; i++) {
assert (mistakes[i].check.title == mistake_list[i].title);
assert (mistakes[i].begin.line == mistake_list[i].line);
if (mistake_list[i].message != null) {
assert (mistakes[i].mistake == mistake_list[i].message);
}
}
} catch (Error e) {
critical ("Error: %s while linting pass file %s\n", e.message, file.get_path ());
}
}
public static int main (string[] args) {
var m_pass = new Vala.ArrayList<FileTestMistake?> ();
check_file_for_mistake (File.new_for_path ("../test/files/pass.vala"), m_pass);
int line = 0; // So that new tests can be added without changing every number...
var m_warnings = new Vala.ArrayList<FileTestMistake?> ();
m_warnings.add ({ "naming-convention", line += 4 });
m_warnings.add ({ "no-space", line += 2 });
m_warnings.add ({ "note", line += 1, "TODO" });
m_warnings.add ({ "note", line += 1, "TODO: Lorem ipsum" });
m_warnings.add ({ "no-space", line += 2 });
m_warnings.add ({ "no-space", line += 1 });
m_warnings.add ({ "no-space", line += 1 });
m_warnings.add ({ "no-space", line += 1 });
m_warnings.add ({ "double-spaces", line += 3 });
m_warnings.add ({ "double-spaces", line += 1 });
m_warnings.add ({ "double-spaces", line += 0 });
m_warnings.add ({ "double-spaces", line += 0 });
m_warnings.add ({ "double-spaces", line += 1 });
m_warnings.add ({ "trailing-whitespace", line += 1 });
m_warnings.add ({ "no-space", line += 3 });
m_warnings.add ({ "double-semicolon", line += 1 });
m_warnings.add ({ "naming-convention", line += 1 });
m_warnings.add ({ "ellipsis", line += 2 });
m_warnings.add ({ "ellipsis", line += 1 });
m_warnings.add ({ "ellipsis", line += 1 });
m_warnings.add ({ "ellipsis", line += 0 });
m_warnings.add ({ "unnecessary-string-template", line += 2 });
m_warnings.add ({ "unnecessary-string-template", line += 1 });
m_warnings.add ({ "line-length", line += 2 });
m_warnings.add ({ "line-length", line += 1 });
m_warnings.add ({ "trailing-newlines", line += 2 });
check_file_for_mistake (File.new_for_path ("../test/files/warnings.vala"), m_warnings);
return 0;
}
}