From ee07b4133ff362c52c4f8aaaf6b16c5ba7989252 Mon Sep 17 00:00:00 2001 From: xiaoshihou Date: Fri, 15 Sep 2023 21:22:44 +0800 Subject: [PATCH] fix(test): namespace --- CONTRIBUTING.md | 5 ++++- test/linter/clang-tidy_spec.lua | 6 ++++-- test/linter/flake8_spec.lua | 20 +++++++++++--------- test/linter/hadolint_spec.lua | 8 +++++--- test/linter/helper.lua | 1 + test/linter/luacheck_spec.lua | 6 ++++-- test/linter/pylint_spec.lua | 14 ++++++++------ test/linter/selene_spec.lua | 6 ++++-- 8 files changed, 41 insertions(+), 25 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 4bd829b..ec6c2f2 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -42,6 +42,8 @@ end) describe('selene', function() it('can lint', function() -- pre-test setup + local helper = require('test.linter.helper') + local ns = helper.namespace local ft = require('guard.filetype') ft('lua'):lint('selene') require('guard').setup() @@ -65,7 +67,8 @@ describe('selene', function() end_lnum = 4, lnum = 4, message = '`U` is not defined [undefined_variable]', - namespace = 4, + -- sometimes the namespace is not fixed + namespace = ns, severity = 1, source = 'selene', }, diff --git a/test/linter/clang-tidy_spec.lua b/test/linter/clang-tidy_spec.lua index 19656f7..6e49502 100644 --- a/test/linter/clang-tidy_spec.lua +++ b/test/linter/clang-tidy_spec.lua @@ -1,10 +1,12 @@ describe('clang-tidy', function() it('can lint', function() + local helper = require('test.linter.helper') + local ns = helper.namespace local ft = require('guard.filetype') ft('c'):lint('clang-tidy') require('guard').setup() - local diagnostics = require('test.linter.helper').test_with('c', { + local diagnostics = helper.test_with('c', { [[#include ]], [[int main() {]], [[ int x = 10;]], @@ -22,7 +24,7 @@ describe('clang-tidy', function() end_lnum = 4, lnum = 4, message = 'Division by zero [clang-analyzer-core.DivideZero]', - namespace = 1, + namespace = ns, severity = 2, source = 'clang-tidy', }, diff --git a/test/linter/flake8_spec.lua b/test/linter/flake8_spec.lua index a4cf44c..c62f40c 100644 --- a/test/linter/flake8_spec.lua +++ b/test/linter/flake8_spec.lua @@ -1,10 +1,12 @@ describe('flake8', function() it('can lint', function() + local helper = require('test.linter.helper') + local ns = helper.namespace local ft = require('guard.filetype') ft('python'):lint('flake8') require('guard').setup() - local diagnostics = require('test.linter.helper').test_with('python', { + local diagnostics = helper.test_with('python', { [[import os]], [[]], [[def foo(n):]], @@ -20,7 +22,7 @@ describe('flake8', function() end_lnum = 0, lnum = 0, message = "'os' imported but unused [401]", - namespace = 1, + namespace = ns, severity = 3, source = 'flake8', }, @@ -31,7 +33,7 @@ describe('flake8', function() end_lnum = 2, lnum = 2, message = 'expected 2 blank lines, found 1 [302]', - namespace = 1, + namespace = ns, severity = 1, source = 'flake8', }, @@ -42,7 +44,7 @@ describe('flake8', function() end_lnum = 4, lnum = 4, message = 'indentation is not a multiple of 4 [111]', - namespace = 1, + namespace = ns, severity = 1, source = 'flake8', }, @@ -53,7 +55,7 @@ describe('flake8', function() end_lnum = 4, lnum = 4, message = 'over-indented [117]', - namespace = 1, + namespace = ns, severity = 1, source = 'flake8', }, @@ -64,7 +66,7 @@ describe('flake8', function() end_lnum = 4, lnum = 4, message = 'multiple spaces after keyword [271]', - namespace = 1, + namespace = ns, severity = 1, source = 'flake8', }, @@ -75,7 +77,7 @@ describe('flake8', function() end_lnum = 4, lnum = 4, message = "undefined name 'bar' [821]", - namespace = 1, + namespace = ns, severity = 3, source = 'flake8', }, @@ -86,7 +88,7 @@ describe('flake8', function() end_lnum = 5, lnum = 5, message = 'expected 2 blank lines after class or function definition, found 0 [305]', - namespace = 1, + namespace = ns, severity = 1, source = 'flake8', }, @@ -97,7 +99,7 @@ describe('flake8', function() end_lnum = 5, lnum = 5, message = 'line too long (80 > 79 characters) [501]', - namespace = 1, + namespace = ns, severity = 1, source = 'flake8', }, diff --git a/test/linter/hadolint_spec.lua b/test/linter/hadolint_spec.lua index 8492185..0f54d25 100644 --- a/test/linter/hadolint_spec.lua +++ b/test/linter/hadolint_spec.lua @@ -1,10 +1,12 @@ describe('hadolint', function() it('can lint', function() + local helper = require('test.linter.helper') + local ns = helper.namespace local ft = require('guard.filetype') ft('dockerfile'):lint('hadolint') require('guard').setup() - local diagnostics = require('test.linter.helper').test_with('dockerfile', { + local diagnostics = helper.test_with('dockerfile', { [[FROM alpine:3.18]], [[RUN {{Definitely not valid bash]], [[COPY foo bar]], @@ -19,7 +21,7 @@ describe('hadolint', function() end_lnum = 1, lnum = 1, message = "Missing '}'. Fix any mentioned problems and try again. [SC1072]", - namespace = 4, + namespace = ns, severity = 1, source = 'hadolint', }, @@ -30,7 +32,7 @@ describe('hadolint', function() end_lnum = 2, lnum = 2, message = '`COPY` to a relative destination without `WORKDIR` set. [DL3045]', - namespace = 4, + namespace = ns, severity = 2, source = 'hadolint', }, diff --git a/test/linter/helper.lua b/test/linter/helper.lua index 928cb1a..d3c1570 100644 --- a/test/linter/helper.lua +++ b/test/linter/helper.lua @@ -1,5 +1,6 @@ local M = {} local api = vim.api +M.namespace = api.nvim_get_namespaces().Guard function M.test_with(ft, input) local bufnr = api.nvim_create_buf(true, false) diff --git a/test/linter/luacheck_spec.lua b/test/linter/luacheck_spec.lua index 3af7637..9f18b38 100644 --- a/test/linter/luacheck_spec.lua +++ b/test/linter/luacheck_spec.lua @@ -1,10 +1,12 @@ describe('luacheck', function() it('can lint', function() + local helper = require('test.linter.helper') + local ns = helper.namespace local ft = require('guard.filetype') ft('lua'):lint('luacheck') require('guard').setup() - local diagnostics = require('test.linter.helper').test_with('lua', { + local diagnostics = helper.test_with('lua', { [[local M = {}]], [[function M.foo()]], [[ print("foo")]], @@ -20,7 +22,7 @@ describe('luacheck', function() end_lnum = 4, lnum = 4, message = "accessing undefined variable 'U' [113]", - namespace = 4, + namespace = ns, severity = 2, source = 'luacheck', }, diff --git a/test/linter/pylint_spec.lua b/test/linter/pylint_spec.lua index cc45bb0..7d4fa59 100644 --- a/test/linter/pylint_spec.lua +++ b/test/linter/pylint_spec.lua @@ -1,10 +1,12 @@ describe('pylint', function() it('can lint', function() + local helper = require('test.linter.helper') + local ns = helper.namespace local ft = require('guard.filetype') ft('python'):lint('pylint') require('guard').setup() - local diagnostics = require('test.linter.helper').test_with('python', { + local diagnostics = helper.test_with('python', { [[def foo(n):]], [[ if n in (1, 2, 3):]], [[ return n + 1]], @@ -20,7 +22,7 @@ describe('pylint', function() end_lnum = 0, lnum = 0, message = 'Missing module docstring [missing-module-docstring]', - namespace = 4, + namespace = ns, severity = 3, source = 'pylint', }, @@ -31,7 +33,7 @@ describe('pylint', function() end_lnum = 0, lnum = 0, message = 'Missing function or method docstring [missing-function-docstring]', - namespace = 4, + namespace = ns, severity = 3, source = 'pylint', }, @@ -42,7 +44,7 @@ describe('pylint', function() end_lnum = 0, lnum = 0, message = 'Disallowed name "foo" [disallowed-name]', - namespace = 4, + namespace = ns, severity = 3, source = 'pylint', }, @@ -53,7 +55,7 @@ describe('pylint', function() end_lnum = 0, lnum = 0, message = 'Argument name "n" doesn\'t conform to snake_case naming style [invalid-name]', - namespace = 4, + namespace = ns, severity = 3, source = 'pylint', }, @@ -64,7 +66,7 @@ describe('pylint', function() end_lnum = 0, lnum = 0, message = 'Either all return statements in a function should return an expression, or none of them should. [inconsistent-return-statements]', - namespace = 4, + namespace = ns, severity = 3, source = 'pylint', }, diff --git a/test/linter/selene_spec.lua b/test/linter/selene_spec.lua index eea5243..345bb80 100644 --- a/test/linter/selene_spec.lua +++ b/test/linter/selene_spec.lua @@ -1,10 +1,12 @@ describe('selene', function() it('can lint', function() + local helper = require('test.linter.helper') + local ns = helper.namespace local ft = require('guard.filetype') ft('lua'):lint('selene') require('guard').setup() - local diagnostics = require('test.linter.helper').test_with('lua', { + local diagnostics = helper.test_with('lua', { [[local M = {}]], [[function M.foo()]], [[ print("foo")]], @@ -20,7 +22,7 @@ describe('selene', function() end_lnum = 4, lnum = 4, message = '`U` is not defined [undefined_variable]', - namespace = 4, + namespace = ns, severity = 1, source = 'selene', },