Skip to content

Commit

Permalink
fix(test): namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoshihou514 committed Sep 15, 2023
1 parent f577901 commit ee07b41
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 25 deletions.
5 changes: 4 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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',
},
Expand Down
6 changes: 4 additions & 2 deletions test/linter/clang-tidy_spec.lua
Original file line number Diff line number Diff line change
@@ -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 <stdio.h>]],
[[int main() {]],
[[ int x = 10;]],
Expand All @@ -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',
},
Expand Down
20 changes: 11 additions & 9 deletions test/linter/flake8_spec.lua
Original file line number Diff line number Diff line change
@@ -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):]],
Expand All @@ -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',
},
Expand All @@ -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',
},
Expand All @@ -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',
},
Expand All @@ -53,7 +55,7 @@ describe('flake8', function()
end_lnum = 4,
lnum = 4,
message = 'over-indented [117]',
namespace = 1,
namespace = ns,
severity = 1,
source = 'flake8',
},
Expand All @@ -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',
},
Expand All @@ -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',
},
Expand All @@ -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',
},
Expand All @@ -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',
},
Expand Down
8 changes: 5 additions & 3 deletions test/linter/hadolint_spec.lua
Original file line number Diff line number Diff line change
@@ -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]],
Expand All @@ -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',
},
Expand All @@ -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',
},
Expand Down
1 change: 1 addition & 0 deletions test/linter/helper.lua
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
6 changes: 4 additions & 2 deletions test/linter/luacheck_spec.lua
Original file line number Diff line number Diff line change
@@ -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")]],
Expand All @@ -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',
},
Expand Down
14 changes: 8 additions & 6 deletions test/linter/pylint_spec.lua
Original file line number Diff line number Diff line change
@@ -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]],
Expand All @@ -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',
},
Expand All @@ -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',
},
Expand All @@ -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',
},
Expand All @@ -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',
},
Expand All @@ -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',
},
Expand Down
6 changes: 4 additions & 2 deletions test/linter/selene_spec.lua
Original file line number Diff line number Diff line change
@@ -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")]],
Expand All @@ -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',
},
Expand Down

0 comments on commit ee07b41

Please sign in to comment.