summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorKeith Maxwell <keith.maxwell@gmail.com>2019-05-23 14:12:36 +0100
committerKeith Maxwell <keith.maxwell@gmail.com>2019-05-23 15:49:02 +0100
commit88fa0b9294c6e907e8e2e8bee2ca593dff91b473 (patch)
tree5e094c3c5b45f2137ce821a93a86a3a6653ded01 /test
parent1a9b8a58c7e01f0926e51b39b7b37f932537cc0c (diff)
downloadale-88fa0b9294c6e907e8e2e8bee2ca593dff91b473.zip
Add a terraform linter
This linter uses the check functionality built into terraform. ALE already has a fixer using `terraform fmt` but this doesn't provide error messages. ALE already has a linter using `tflint` but this requires an extra application to be installed. For example this linter will give a warning that ! is an illegal character in the line below: variable "example" !{} This linter runs the buffer through the command below and parses the output: terraform fmt -no-color -check=true - This commit includes a basic implementation, documentation and tests. The only option is to control which executable is run. Tested with: $ terraform -version Terraform v0.11.13
Diffstat (limited to 'test')
-rw-r--r--test/command_callback/test_terraform_terraform_command_callback.vader9
-rwxr-xr-xtest/handler/test_terraform_handler.vader34
2 files changed, 43 insertions, 0 deletions
diff --git a/test/command_callback/test_terraform_terraform_command_callback.vader b/test/command_callback/test_terraform_terraform_command_callback.vader
new file mode 100644
index 00000000..fabd902d
--- /dev/null
+++ b/test/command_callback/test_terraform_terraform_command_callback.vader
@@ -0,0 +1,9 @@
+" Based upon :help ale-development
+Before:
+ call ale#assert#SetUpLinterTest('terraform', 'terraform')
+
+After:
+ call ale#assert#TearDownLinterTest()
+
+Execute(The default command should be correct):
+ AssertLinter 'terraform', ale#Escape('terraform') . ' fmt -no-color --check=true -'
diff --git a/test/handler/test_terraform_handler.vader b/test/handler/test_terraform_handler.vader
new file mode 100755
index 00000000..976ce12a
--- /dev/null
+++ b/test/handler/test_terraform_handler.vader
@@ -0,0 +1,34 @@
+Before:
+ " Load the file which defines the linter.
+ runtime ale_linters/terraform/terraform.vim
+
+After:
+ " Unload all linters again.
+ call ale#linter#Reset()
+
+Execute(The output should be correct):
+ AssertEqual
+ \ [
+ \ {
+ \ 'lnum': 1,
+ \ 'col': 20,
+ \ 'type': 'E',
+ \ 'text': 'illegal char',
+ \ },
+ \ {
+ \ 'lnum': 2,
+ \ 'col': 14,
+ \ 'type': 'E',
+ \ 'text': 'literal not terminated',
+ \ },
+ \ {
+ \ 'lnum': 1,
+ \ 'type': 'E',
+ \ 'text': 'object expected closing RBRACE got: EOF',
+ \ },
+ \ ],
+ \ ale_linters#terraform#terraform#Handle(bufnr(''), [
+ \ 'Error running fmt: In <standard input>: At 1:20: illegal char',
+ \ 'Error running fmt: In <standard input>: At 2:14: literal not terminated',
+ \ 'Error running fmt: In <standard input>: object expected closing RBRACE got: EOF',
+ \ ])