Skip to content

Commit

Permalink
Migrate tests to GitHub actions (#2)
Browse files Browse the repository at this point in the history
* TST: Fix isk restoration
* TST: Make _analyse_parameter resilient to &isk
* BUG: Make lh#dev#type resilient to &isk
* CONF: Rename vim-flavor file
* CI: Update dependencies
* CI: Remove vimrunner
* DOC: Update README badges
  • Loading branch information
LucHermitte authored Aug 23, 2024
1 parent 8bffd56 commit 99682f9
Show file tree
Hide file tree
Showing 12 changed files with 267 additions and 223 deletions.
58 changes: 58 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
# This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
# For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby

name: CI

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

permissions:
contents: read

jobs:
test:
name: "test on ${{ matrix.os }} ; ${{ matrix.neovim && 'neovim' || 'vim' }}"

strategy:
matrix:
# Testing doesn't seem to work on Windows: output log file
# cannot be read...
# os: [ubuntu-latest, macos-latest, windows-latest]
os: [ubuntu-latest, macos-latest]
neovim: [false, true]
# TODO: Test different flavours of Vim...

runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v4
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 3.0
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
- name: Setup Vim
uses: rhysd/action-setup-vim@v1
# uses: thinca/action-setup-vim@v2
id: vim
with:
neovim: ${{matrix.neovim }}
configure-args: |
--with-features=huge
- name: Run tests on Linux
if: runner.os == 'Linux' # headless execution is required on Linux
run: |
bundle list
xvfb-run bundle exec rake ci
- name: Run tests on ${{ matrix.os }}
if: runner.os != 'Linux'
run: |
bundle exec rake ci
2 changes: 2 additions & 0 deletions Flavorfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
flavor 'LucHermitte/lh-vim-lib', '>= 5.3.3'
flavor 'LucHermitte/lh-tags', '>= 3.0.7'
6 changes: 3 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
source 'https://rubygems.org'

gem 'rspec', '~> 3.9.0'
gem 'vimrunner', '~> 0.3.4'
gem 'rspec', '~> 3.13.0'
# gem 'vimrunner', '~> 0.3.5'
gem 'rake', '~> 13.0.1'
gem 'vim-flavor', '~> 2.2.2'
gem 'vim-flavor', '~> 4.0.3'
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
# lh-dev [![Build Status](https://secure.travis-ci.org/LucHermitte/lh-dev.png?branch=master)](http://travis-ci.org/LucHermitte/lh-dev) [![Project Stats](https://www.openhub.net/p/21020/widgets/project_thin_badge.gif)](https://www.openhub.net/p/21020)
# lh-dev [![Last release][Releases-badge]][Releases-url] [![Build Status][gh-action-badge]][gh-action-result] [![Project Stats][openhub-badge]][openhub-url]

[Releases-badge]: https://img.shields.io/github/tag/LucHermitte/lh-dev.svg
[Releases-url]: https://github.com/LucHermitte/lh-dev/tags
[gh-action-badge]: ./../../actions/workflows/tests.yml/badge.svg?branch=master "Test"
[gh-action-result]: ./../../actions/workflows/tests.yml?query=branch%3Amaster
[openhub-badge]: https://www.openhub.net/p/21020/widgets/project_thin_badge.gif
[openhub-url]: https://www.openhub.net/p/21020

## Introduction

Expand Down
4 changes: 2 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ end
task :test => :spec

task :spec do
sh "rspec ~/.vim-flavor/repos/LucHermitte_vim-UT/spec"
sh "bundle exec rspec ~/.vim-flavor/repos/LucHermitte_vim-UT/spec/UT_spec_v2.rb"
end

task :install do
sh 'cat VimFlavor >> tests/VimFlavor'
sh 'cat Flavorfile >> tests/Flavorfile'
sh 'cd tests && bundle exec vim-flavor install'
end

2 changes: 0 additions & 2 deletions VimFlavor

This file was deleted.

170 changes: 90 additions & 80 deletions autoload/lh/dev/c/function.vim
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
" Version: 2.0.0
let s:k_version = 2000
" Created: 31st May 2010
" Last Update: 09th Apr 2021
" Last Update: 23rd Aug 2024
"------------------------------------------------------------------------
" Description:
" Overridden functions from lh#dev#function, for C and derived languages
Expand All @@ -17,6 +17,7 @@ let s:k_version = 2000
" (*) Fix lh#dev#c#function#_build_param_call/decl
" (*) Support template types in lh#dev#c#function#_analyse_parameter
" when the expected parameter name is known
" (*) Make _analyse_parameter resilient to &isk
" 1.6.2
" (*) Fix :GOTOIMPL to support operators like +=
" 1.5.1
Expand Down Expand Up @@ -197,90 +198,99 @@ endfunction
" [/] UT
" [X] variadic parameter "..."
function! lh#dev#c#function#_analyse_parameter(param, ...) abort
if a:0 > 0 && type(a:1) != type({})
" Old API...
let must_clean_space = a:1
let expected_param_name = '[^=]{-}'
else
let opts = get(a:, 1, {})
let must_clean_space = get(opts, 'must_clean_space', 0)
let expected_param_name = get(opts, 'expected_param_name', '[^=]{-}')
endif
let param = a:param
let res = {}
let cleanup = lh#on#exit()
\.restore('&isk')
try
setlocal isk-=<
setlocal isk-=>
setlocal isk-=:
if a:0 > 0 && type(a:1) != type({})
" Old API...
let must_clean_space = a:1
let expected_param_name = '[^=]{-}'
else
let opts = get(a:, 1, {})
let must_clean_space = get(opts, 'must_clean_space', 0)
let expected_param_name = get(opts, 'expected_param_name', '[^=]{-}')
endif
let param = a:param
let res = {}

" Merge spaces
if must_clean_space
let param = substitute(param, '\v\_s+', ' ', 'g')
endif
" variadic ?
if param == '...'
let res.type = 'va_list'
let res.default = ''
let res.name = '...'
return res
endif
" Default Value: after = sign
let match_res = matchlist(param, '\v^\s*(.{-}<'.expected_param_name.'>)\s*\=\s*(.{-})\s*$')
if !empty(match_res)
" Cannot use stridx for types likes `sometype<I==42>`
" let [all, param, res.default ; rest] = matchlist(param, '\v^\s*([^=]{-})\s*\=\s*(.{-})\s*$')
let [all, param, res.default ; rest] = match_res
else
" trim spaces
let param = matchstr(param, '\v^\s*\zs.{-}\ze\s*$')
let res.default = ''
endif
" Special Case: array
let purge_inner_dimension = 1
let array = match(param, '\v(\s*\[.*\])+$')
if array != -1
let array_spec = matchstr(param[array : -1], '\v\s*\zs.*')
let param = param[ : array-1]
else
let array_spec = ''
endif
" Special Case: function pointer
if param =~ '\v(.{-})\s*\(\s*\*(\S{-})\s*\)\s*(\(.*\))'
let [all, ret_type, res.name, func_type; rest] = matchlist(param, '\v(.{-})\s*\(\s*\*(\S{-})\s*\)\s*(\(.*\))')
let res.type = ret_type.' (*)'.func_type
elseif param =~ '\v(.{-})\s*\(\s*\*(\S{-})\s*\)'
" Special Case: array, (*name)[] syntax
let [all, ret_type, res.name; rest] = matchlist(param, '\v(.{-})\s*\(\s*\*(\S{-})\s*\)')
let res.type = ret_type.'(*)'
let purge_inner_dimension = 0
else
" Name: last part in usual case, or separated with * or &
let res.name = matchstr(param, '\v\S([*& ])+\zs\S+$')
" unless the last part is
" - "int", "float", "char", "short", ...
" - or "something>(::othething)="
" - or everything
if res.name =~ '\v<(int|char|short|long|float|double)>|\>'
" \ || res.type =~ '\v(::)$' " doesn't exist yet
let res.name = ''
" Merge spaces
if must_clean_space
let param = substitute(param, '\v\_s+', ' ', 'g')
endif
" Type:
let res.type = matchstr(param[:strlen(param)-strlen(res.name)-1], '\v.*\S')
if res.type =~ '\v(::)$' " merge back
let res.name = ''
let res.type = param
" variadic ?
if param == '...'
let res.type = 'va_list'
let res.default = ''
let res.name = '...'
return res
endif
" Remove spaces around *, &
" TODO: remove space around < and > (in C++11 only?)
if must_clean_space
let res.type = substitute(res.type, '\v\s*([*&]+)\s*', '\1', 'g')
" Default Value: after = sign
let match_res = matchlist(param, '\v^\s*(.*<'.expected_param_name.'>)\s*\=\s*(.{-})\s*$')
if !empty(match_res)
" Cannot use stridx for types likes `sometype<I==42>`
" let [all, param, res.default ; rest] = matchlist(param, '\v^\s*([^=]{-})\s*\=\s*(.{-})\s*$')
let [all, param, res.default ; rest] = match_res
else
" trim spaces
let param = matchstr(param, '\v^\s*\zs.{-}\ze\s*$')
let res.default = ''
endif
" Special Case: array
let purge_inner_dimension = 1
let array = match(param, '\v(\s*\[.*\])+$')
if array != -1
let array_spec = matchstr(param[array : -1], '\v\s*\zs.*')
let param = param[ : array-1]
else
let array_spec = ''
endif
" Special Case: function pointer
if param =~ '\v(.{-})\s*\(\s*\*(\S{-})\s*\)\s*(\(.*\))'
let [all, ret_type, res.name, func_type; rest] = matchlist(param, '\v(.{-})\s*\(\s*\*(\S{-})\s*\)\s*(\(.*\))')
let res.type = ret_type.' (*)'.func_type
elseif param =~ '\v(.{-})\s*\(\s*\*(\S{-})\s*\)'
" Special Case: array, (*name)[] syntax
let [all, ret_type, res.name; rest] = matchlist(param, '\v(.{-})\s*\(\s*\*(\S{-})\s*\)')
let res.type = ret_type.'(*)'
let purge_inner_dimension = 0
else
" Name: last part in usual case, or separated with * or &
let res.name = matchstr(param, '\v\S([*& ])+\zs\S+$')
" unless the last part is
" - "int", "float", "char", "short", ...
" - or "something>(::othething)="
" - or everything
if res.name =~ '\v<(int|char|short|long|float|double)>|\>'
" \ || res.type =~ '\v(::)$' " doesn't exist yet
let res.name = ''
endif
" Type:
let res.type = matchstr(param[:strlen(param)-strlen(res.name)-1], '\v.*\S')
if res.type =~ '\v(::)$' " merge back
let res.name = ''
let res.type = param
endif
" Remove spaces around *, &
" TODO: remove space around < and > (in C++11 only?)
if must_clean_space
let res.type = substitute(res.type, '\v\s*([*&]+)\s*', '\1', 'g')
endif
endif
endif

if purge_inner_dimension
let array_spec = substitute(array_spec, '\v^\[\zs\d+\ze\]', '', '')
endif
let res.type .= array_spec
" New line before the parameter
let res.nl = match(a:param, "\\v^\\s*[\n\r]") >= 0
" Result
return res
if purge_inner_dimension
let array_spec = substitute(array_spec, '\v^\[\zs\d+\ze\]', '', '')
endif
let res.type .= array_spec
" New line before the parameter
let res.nl = match(a:param, "\\v^\\s*[\n\r]") >= 0
" Result
return res
finally
call cleanup.finalize()
endtry
endfunction

function! lh#dev#c#function#_type(variable_tag) abort "{{{3
Expand Down
Loading

0 comments on commit 99682f9

Please sign in to comment.