Simplfy semver handling and share the semver version cache across everything

This commit is contained in:
w0rp
2017-11-09 23:42:54 +00:00
parent c1fa88e78c
commit d425b8a18a
12 changed files with 133 additions and 188 deletions

View File

@@ -17,6 +17,7 @@ After:
call ale#test#RestoreDirectory()
call ale#linter#Reset()
call ale#semver#ResetVersionCache()
Execute(An empty string should be returned for the cargo executable when there's no Cargo.toml file):
AssertEqual

View File

@@ -23,7 +23,7 @@ After:
call ale#test#RestoreDirectory()
call ale#linter#Reset()
call ale_linters#python#flake8#ClearVersionCache()
call ale#semver#ResetVersionCache()
Execute(The flake8 callbacks should return the correct default values):
AssertEqual
@@ -35,8 +35,9 @@ Execute(The flake8 callbacks should return the correct default values):
AssertEqual
\ ale#Escape('flake8') . ' --format=default --stdin-display-name %s -',
\ ale_linters#python#flake8#GetCommand(bufnr(''), ['3.0.0'])
" Try with older versions.
call ale_linters#python#flake8#ClearVersionCache()
call ale#semver#ResetVersionCache()
AssertEqual
\ ale#Escape('flake8') . ' --format=default -',
\ ale_linters#python#flake8#GetCommand(bufnr(''), ['2.9.9'])
@@ -49,7 +50,9 @@ Execute(The flake8 command callback should let you set options):
\ . ' --some-option --format=default'
\ . ' --stdin-display-name %s -',
\ ale_linters#python#flake8#GetCommand(bufnr(''), ['3.0.4'])
call ale_linters#python#flake8#ClearVersionCache()
call ale#semver#ResetVersionCache()
AssertEqual
\ ale#Escape('flake8')
\ . ' --some-option --format=default -',
@@ -140,7 +143,7 @@ Execute(Using `python -m flake8` should be supported for running flake8):
\ ale#Escape('python') . ' -m flake8 --some-option --format=default -',
\ ale_linters#python#flake8#GetCommand(bufnr(''), ['2.9.9'])
call ale_linters#python#flake8#ClearVersionCache()
call ale#semver#ResetVersionCache()
" Leading spaces shouldn't matter
let g:ale_python_flake8_options = ' -m flake8 --some-option'

View File

@@ -71,17 +71,6 @@ Execute(GCC errors from included files should be parsed correctly):
\ ' ^',
\ ])
Execute(GCC versions should be parsed correctly):
AssertEqual [4, 9, 1], ale#handlers#gcc#ParseGCCVersion([
\ 'g++ (GCC) 4.9.1 20140922 (Red Hat 4.9.1-10)',
\])
AssertEqual [4, 8, 4], ale#handlers#gcc#ParseGCCVersion([
\ 'gcc (Ubuntu 4.8.4-2ubuntu1~14.04.3) 4.8.4',
\ 'Copyright (C) 2013 Free Software Foundation, Inc.',
\ 'This is free software; see the source for copying conditions. There is NO',
\ 'warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.',
\])
Execute(The GCC handler shouldn't complain about #pragma once for headers):
silent file! test.h

View File

@@ -5,6 +5,7 @@ Before:
After:
call ale#test#RestoreDirectory()
call ale#linter#Reset()
call ale#semver#ResetVersionCache()
Execute(flow should return a command to run if a .flowconfig file exists):
call ale#test#SetFilename('flow/a/sub/dummy')

View File

@@ -1,16 +1,50 @@
Execute(ParseSemver should return the correct results):
" We should be able to parse the semver string from flake8
AssertEqual [3, 0, 4], ale#semver#Parse('3.0.4 (mccabe: 0.5.2, pyflakes: 1.2.3, pycodestyle: 2.0.0) CPython 2.7.12 on Linux')
After:
call ale#semver#ResetVersionCache()
Execute(GreaterOrEqual should compare triples correctly):
Assert ale#semver#GreaterOrEqual([3, 0, 4], [3, 0, 0])
Assert ale#semver#GreaterOrEqual([3, 0, 0], [3, 0, 0])
Assert ale#semver#GreaterOrEqual([3, 0, 0], [2, 0, 0])
Assert ale#semver#GreaterOrEqual([3, 1, 0], [3, 1, 0])
Assert ale#semver#GreaterOrEqual([3, 2, 0], [3, 1, 0])
Assert ale#semver#GreaterOrEqual([3, 2, 2], [3, 1, 6])
Assert ale#semver#GreaterOrEqual([3, 2, 5], [3, 2, 5])
Assert ale#semver#GreaterOrEqual([3, 2, 6], [3, 2, 5])
Assert !ale#semver#GreaterOrEqual([2, 9, 1], [3, 0, 0])
Assert !ale#semver#GreaterOrEqual([3, 2, 3], [3, 3, 3])
Assert !ale#semver#GreaterOrEqual([3, 3, 2], [3, 3, 3])
Execute(GetVersion should return the version from the lines of output):
" We should be able to parse the semver string from flake8
AssertEqual [3, 0, 4], ale#semver#GetVersion('dummy', [
\ '3.0.4 (mccabe: 0.5.2, pyflakes: 1.2.3, pycodestyle: 2.0.0) CPython 2.7.12 on Linux',
\ '1.2.3',
\])
Execute(GetVersion should return an empty list when no vesrion can be found):
AssertEqual [], ale#semver#GetVersion('dummy', ['x'])
AssertEqual [], ale#semver#GetVersion('dummy', [])
Execute(GetVersion should cache the version):
AssertEqual [], ale#semver#GetVersion('dummy', [])
AssertEqual [3, 4, 7], ale#semver#GetVersion('dummy', ['Version 3.4.7'])
AssertEqual [3, 4, 7], ale#semver#GetVersion('dummy', [])
Execute(HasVersion should return 1 when the version has been cached):
call ale#semver#GetVersion('dummy', [])
AssertEqual 0, ale#semver#HasVersion('dummy')
call ale#semver#GetVersion('dummy', ['3.4.7'])
AssertEqual 1, ale#semver#HasVersion('dummy')
Execute(GTE should compare triples correctly):
Assert ale#semver#GTE([3, 0, 4], [3, 0, 0])
Assert ale#semver#GTE([3, 0, 0], [3, 0, 0])
Assert ale#semver#GTE([3, 0, 0], [2, 0, 0])
Assert ale#semver#GTE([3, 1, 0], [3, 1, 0])
Assert ale#semver#GTE([3, 2, 0], [3, 1, 0])
Assert ale#semver#GTE([3, 2, 2], [3, 1, 6])
Assert ale#semver#GTE([3, 2, 5], [3, 2, 5])
Assert ale#semver#GTE([3, 2, 6], [3, 2, 5])
Assert !ale#semver#GTE([2, 9, 1], [3, 0, 0])
Assert !ale#semver#GTE([3, 2, 3], [3, 3, 3])
Assert !ale#semver#GTE([3, 3, 2], [3, 3, 3])
Execute(GTE should compare pairs correctly):
Assert ale#semver#GTE([3, 0], [3, 0, 0])
Assert ale#semver#GTE([3, 0], [3, 0])
Assert ale#semver#GTE([3, 1], [3, 0])
Assert ale#semver#GTE([3, 1], [3, 0, 0])
Assert ale#semver#GTE([3, 0, 1], [3, 0])
Assert !ale#semver#GTE([3, 0], [3, 0, 1])
Assert !ale#semver#GTE([3, 0], [3, 1])
Assert !ale#semver#GTE([2, 9, 11], [3, 0])
Execute(GTE should permit the LHS to be an empty List):
Assert !ale#semver#GTE([], [0, 0, 0])