diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 0000000..ecf639d --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,29 @@ +--- +name: Bug report +about: Create a report to help us improve +labels: bug + +--- + +**Describe the bug** +A clear and concise description of what the bug is. + +**To Reproduce** +Steps to reproduce the behavior: +1. Go to '...' +2. Click on '....' +3. Scroll down to '....' +4. See error + +**Expected behavior** +A clear and concise description of what you expected to happen. + +**Screenshots** +If pertinent, add screenshots to help explain your problem. + +** Context (please complete the following information):** + - Vim version [e.g. 8.0.1157] + - Other plugins installed + +**Additional context** +Add any other context about the problem here. diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md new file mode 100644 index 0000000..ef4aa7d --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -0,0 +1,17 @@ +--- +name: Feature request +about: Suggest an idea for this project + +--- + +**Is your feature request related to a problem? Please describe.** +A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] ; I'd like to be able to [...] + +**Describe the solution you'd like** +A clear and concise description of what you want to happen. + +**Describe alternatives you've considered** +A clear and concise description of any alternative solutions or features you've considered. + +**Additional context** +Add any other context or screenshots about the feature request here. diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..979cda7 --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,82 @@ +# 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] + # neovim: [false, true] + # TODO: Test different flavours of Vim... + + runs-on: ${{ matrix.os }} + + env: + CTAGS_VERSION: v6.1.0 + 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 + + # Install universal-ctags in cache + - uses: actions/cache@v4 + id: cache-ctags + with: + path: $HOME/local + key: ${{ runner.os }}-ctags-${{ env.CTAGS_VERSION }} + + # If cache is missed, re-install universal-ctags + - name: Install Universal ctags + if: steps.cache-ctags.outputs.cache-hit != 'true' + run: | + git clone https://github.com/universal-ctags/ctags.git + cd ctags + git checkout tags/$CTAGS_VERSION + builtin type -P brew &> /dev/null && brew install automake + ./autogen.sh + ./configure --prefix=$HOME/local + make -j 4 install + - name: Add ctags to PATH + run: echo "PATH=$HOME/local/bin:$PATH" >> $GITHUB_ENV + + - 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 diff --git a/.gitignore b/.gitignore index 02cdacb..7601deb 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,5 @@ tags *.sw* *~ *.pyc +tests/lh/*.log +*.lock diff --git a/Flavorfile b/Flavorfile new file mode 100644 index 0000000..774cefd --- /dev/null +++ b/Flavorfile @@ -0,0 +1,7 @@ +flavor 'LucHermitte/lh-vim-lib', '>= 5.3.1' +flavor 'LucHermitte/lh-brackets', '>= 3.6.0' +flavor 'LucHermitte/lh-style', '>= 0.9.2' +flavor 'LucHermitte/lh-dev' +flavor 'LucHermitte/mu-template', '>= 4.4.1' +flavor 'LucHermitte/VimFold4C', '>= 3.0.9' +flavor 'LucHermitte/alternate-lite', '>= 0.1.0' diff --git a/Gemfile b/Gemfile index 9a19252..eda7be8 100644 --- a/Gemfile +++ b/Gemfile @@ -1,6 +1,6 @@ source 'https://rubygems.org' -gem 'rspec', '~> 3.1.0' -gem 'vimrunner', '~> 0.3.1' -gem 'rake', '~> 10.3.2' -gem 'vim-flavor', '~> 2.1.1' +gem 'rspec', '~> 3.13.0' +gem 'vimrunner', '~> 0.3.5' +gem 'rake', '~> 13.0.1' +gem 'vim-flavor', '~> 4.0.3' diff --git a/README.md b/README.md index f590fd8..b29bc4d 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,12 @@ -# lh-cpp [![Build Status](https://secure.travis-ci.org/LucHermitte/lh-cpp.png?branch=master)](http://travis-ci.org/LucHermitte/lh-cpp) [![Project Stats](https://www.openhub.net/p/21020/widgets/project_thin_badge.gif)](https://www.openhub.net/p/21020) +# lh-cpp [![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-cpp.svg +[Releases-url]: https://github.com/LucHermitte/lh-cpp/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 + ## Features lh-cpp is an heterogeneous suite of helpers for C and C++ programming. diff --git a/Rakefile b/Rakefile index 07a39fb..0508a17 100644 --- a/Rakefile +++ b/Rakefile @@ -16,11 +16,11 @@ task :test => :spec task :spec do # 'spec' is implicitly run as well - sh 'rspec ~/.vim-flavor/repos/LucHermitte_vim-UT/spec' + # sh 'rspec --require spec_helper' + 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 diff --git a/VimFlavor b/VimFlavor deleted file mode 100644 index f63d8a7..0000000 --- a/VimFlavor +++ /dev/null @@ -1,7 +0,0 @@ -flavor 'LucHermitte/lh-vim-lib', '>= 4.1.0' -flavor 'LucHermitte/lh-brackets', '>= 3.1.1' -flavor 'LucHermitte/lh-style' -flavor 'LucHermitte/lh-dev' -flavor 'LucHermitte/mu-template', '>= 4.3.1' -flavor 'LucHermitte/VimFold4C', '>= 3.0.9' -flavor 'LucHermitte/alternate-lite', '>= 0.1.0' diff --git a/mkVba/mk-lh-cpp.vim b/mkVba/mk-lh-cpp.vim index 897bcab..2cabfbe 100644 --- a/mkVba/mk-lh-cpp.vim +++ b/mkVba/mk-lh-cpp.vim @@ -6,7 +6,7 @@ " " Version: 2.2.1 " Created: 06th Nov 2007 -" Last Update: 28th Nov 2019 +" Last Update: 27th Aug 2024 "------------------------------------------------------------------------ let s:version = '2.2.1' let s:project = 'lh-cpp' @@ -21,7 +21,7 @@ finally let &rtp = save_rtp endtry finish -VimFlavor +Flavorfile addon-info.json after/plugin/a.vim after/template/c/assert.template diff --git a/spec/class-with-attributes_spec.rb b/spec/class-with-attributes_spec.rb index 342a3d3..a3b26a2 100644 --- a/spec/class-with-attributes_spec.rb +++ b/spec/class-with-attributes_spec.rb @@ -43,7 +43,7 @@ specify "attribute-class copy-neutral, C++98", :cpp98 do expect(vim.command('call lh#mut#expand_and_jump(0, "cpp/internals/class-skeleton", {"attributes": [{"name": "foo", "type": "int"}, {"name": "str", "type": "string", "functions": ["set", "get"]}, {"name": "bar", "type": "Bar", "includes":"bar.h"}]})')).to match(/^$|#include added/) - vim.feedkeys('\\:silent! $call append("$", ["",""])\G') + # vim.feedkeys('\\:silent! $call append("$", ["",""])\G') assert_buffer_contents <<-EOF /** File Header line to trick auto-inclusion */ #include @@ -93,7 +93,7 @@ class «Test» specify "attribute-class copy-neutral, C++11", :cpp11 do vim.command('silent! let g:cpp_std_flavour=11') expect(vim.command('call lh#mut#expand_and_jump(0, "cpp/internals/class-skeleton", {"attributes": [{"name": "foo", "type": "int"}, {"name": "bar", "type": "string", "functions": ["set", "get"]}]})')).to match(/^$|#include added/) - vim.feedkeys('\\:silent! $call append("$", ["",""])\G') + # vim.feedkeys('\\:silent! $call append("$", ["",""])\G') assert_buffer_contents <<-EOF /** File Header line to trick auto-inclusion */ #include diff --git a/spec/constructor-command_spec.rb b/spec/constructor-command_spec.rb index 2955c8f..f2e2bd9 100644 --- a/spec/constructor-command_spec.rb +++ b/spec/constructor-command_spec.rb @@ -34,6 +34,7 @@ vim.set('ft=cpp') vim.set('expandtab') vim.set('sw=4') + vim.set('isk&vim') vim.command('silent! unlet g:cpp_explicit_default') vim.command('silent! unlet g:cpp_std_flavour') vim.command('silent! unlet g:mocked_input') @@ -74,9 +75,11 @@ class Foo { context "when expanding default-constructor", :default_ctr do it "has a pointer attribute" do # {{{3 + pp vim.echo('execute("scriptnames")') + pp vim.echo('execute("set")') # TODO: In C++11, no need for m_bar() if there is a default # initialisation at class scope - # expect(vim.echo('lh#dev#class#attributes("Foo")')).to eq('m_bar') + expect(vim.echo('lh#list#get(lh#dev#class#attributes("Foo"), "name")')).to eq("['Foo::m_bar', 'Foo::m_foo']") # expect(vim.echo('lh#cpp#constructors#debug("s:Attributes(\"Foo\")")')).to eq('m_bar') # vim.command('Constructor default') vim.echo('lh#cpp#constructors#Main("default")') diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index a421679..5075c25 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -14,73 +14,115 @@ def runtime(script) script_path = Path.new(script) command("runtime #{script_path}") end + + def append_rtp(dir) + dir_path = Path.new(dir) + if File.directory?(dir.to_s) + append_runtimepath(dir) + else + puts "Path #{dir_path} doesn't exist => ignored" + end + end + + def prepend_rtp(dir) + dir_path = Path.new(dir) + if File.directory?(dir.to_s) + prepend_runtimepath(dir) + else + puts "Path #{dir_path} doesn't exist => ignored" + end + end end -end + module Platform + # For tests use in order of priority: + # 1. gvim -- when available + # 2. vim -- if possible + # nvim is not compatible with vimrunner, let's ignore it now + def best_vim + prefered_vims.find { |vim| suitable?(vim) } or raise NoSuitableVimError + end + private + + def prefered_vims + gvims + %w( vim ) + end + end + +end Vimrunner::RSpec.configure do |config| + # Use a single Vim instance for the test suite. Set to false to use an + # instance per test (slower, but can be easier to manage). config.reuse_server = true vim_plugin_path = File.expand_path('.') vim_flavor_path = ENV['HOME']+'/.vim/flavors' - config.start_vim do - vim = Vimrunner.start_gvim - # vim = Vimrunner.start + # Use different vimrc in order to see packages installed by vim-flavor + vimrc = File.expand_path('../support/test.vimrc', __FILE__) + # Decide how to start a Vim instance. In this block, an instance + # should be spawned and set up with anything project-specific. + config.start_vim do + vim = Vimrunner::Server.new(:executable => Vimrunner::Platform.best_vim, :vimrc => vimrc).start vim.add_plugin(vim_flavor_path, 'bootstrap.vim') - vim.prepend_runtimepath(vim_plugin_path+'/after') - vim.prepend_runtimepath(vim_plugin_path) + vim.prepend_rtp(vim_plugin_path) # lh-UT vim_UT_path = File.expand_path('../../../vim-UT', __FILE__) - vim.prepend_runtimepath(vim_UT_path) + vim.prepend_rtp(vim_UT_path) vim.runtime('plugin/UT.vim') # pp vim_flavor_path # lh-vim-lib vim_lib_path = File.expand_path('../../../lh-vim-lib', __FILE__) - vim.prepend_runtimepath(vim_lib_path) + vim.prepend_rtp(vim_lib_path) vim.runtime('plugin/let.vim') # LetIfUndef # vim.runtime('plugin/ui-functions.vim') # lh#ui#confirm # vim.command(':messages') # lh-tags vim_tags_path = File.expand_path('../../../lh-tags', __FILE__) - vim.prepend_runtimepath(vim_tags_path) + vim.prepend_rtp(vim_tags_path) vim.runtime('plugin/lh-tags.vim') # AddStyle # lh-style vim_style_path = File.expand_path('../../../lh-style', __FILE__) - vim.prepend_runtimepath(vim_style_path) + vim.prepend_rtp(vim_style_path) vim.runtime('plugin/lh-style.vim') # AddStyle # lh-dev vim_dev_path = File.expand_path('../../../lh-dev', __FILE__) - vim.prepend_runtimepath(vim_dev_path) + vim.prepend_rtp(vim_dev_path) # lh-brackets vim_brackets_path = File.expand_path('../../../lh-brackets', __FILE__) - vim.prepend_runtimepath(vim_brackets_path) + vim.prepend_rtp(vim_brackets_path) vim.runtime('plugin/misc_map.vim') # Inoreab vim.runtime('plugin/common_brackets.vim') # Brackets - vim.runtime('plugin/bracketing.base.vim') # !mark! + vim.runtime('plugin/bracketing.base.vim') # !mark!, !jump! vim.command('set enc=utf-8') #vim.command('SetMarker <+ +>') # mu-template mu_template_path = File.expand_path('../../../mu-template@lh', __FILE__) - vim.prepend_runtimepath(mu_template_path+'/after') - vim.prepend_runtimepath(mu_template_path) - vim.runtime('plugin/mu-template.vim') # !mark! + vim.append_rtp(mu_template_path+'/after') + vim.prepend_rtp(mu_template_path) + vim.runtime('plugin/mu-template.vim') + vim.append_rtp(vim_plugin_path+'/after') - # pp vim.echo('&rtp') + pp vim.echo('"RTP -> " . &rtp') vim.command('set shm=') has_redo = vim.echo('has("patch-7.4.849")') if has_redo != "1" puts "WARNING: this flavor of vim won't permit to support redo" end + + pp vim.echo('"mut-dir -> " . string(lh#mut#dirs#update())') + + # The returned value is the Client available in the tests. vim end end diff --git a/spec/support/test.vimrc b/spec/support/test.vimrc new file mode 100644 index 0000000..c50a77f --- /dev/null +++ b/spec/support/test.vimrc @@ -0,0 +1,12 @@ +" Special vimrc to used instead of vimrunner vimrc which disable all plugins +" It should automatically load plugins installed as packages by vim-flavor +set nocompatible + +filetype plugin on +filetype indent on +syntax on + +set rtp-=~/.vim +set rtp-=~/.vim/after +set noswapfile nobackup +set loadplugins diff --git a/spec/value-class-with-attributes_spec.rb b/spec/value-class-with-attributes_spec.rb index 11ff3ea..4e37de7 100644 --- a/spec/value-class-with-attributes_spec.rb +++ b/spec/value-class-with-attributes_spec.rb @@ -20,6 +20,7 @@ vim.command('UseStyle breakbeforebraces=stroustrup -ft=c') vim.command('UseStyle spacesbeforeparens=control-statements -ft=c') vim.command('UseStyle empty_braces=nl -ft=c') + vim.command('let g:cpp_nullptr = "NULL"') end # ====[ Always executed before each test {{{2 @@ -48,7 +49,7 @@ specify "value-attribute-class copyable", :cpp98, :cpp11, :copyable do expect(vim.echo('lh#mut#dirs#get_templates_for("cpp/value-class")')).to match(/value-class.template/) expect(vim.command('call lh#mut#expand_and_jump(0, "cpp/value-class", {"attributes": [{"name": "foo", "type": "int"}, {"name": "bar", "type": "string", "functions": ["set", "get"]}]})')).to match(/^$|#include added/) - vim.feedkeys('\\:silent! $call append("$", ["",""])\G') + # vim.feedkeys('\\:silent! $call append("$", ["",""])\G') assert_buffer_contents <<-EOF /** File Header line to trick auto-inclusion */ #include @@ -101,7 +102,7 @@ class «Test» vim.command('let g:cpp_std_flavour=11') vim.command("let g:cpp_explicit_default = 1") expect(vim.command('call lh#mut#expand_and_jump(0, "cpp/value-class", {"attributes": [{"name": "foo", "type": "int"}, {"name": "bar", "type": "string", "functions": ["set", "get"]}]})')).to match(/^$|#include added/) - vim.feedkeys('\\:silent! $call append("$", ["",""])\G') + # vim.feedkeys('\\:silent! $call append("$", ["",""])\G') assert_buffer_contents <<-EOF /** File Header line to trick auto-inclusion */ #include @@ -164,7 +165,7 @@ class «Test» specify "value-attribute-class copyable, with ptr attributes", :cpp98, :cpp11, :copyable do expect(vim.echo('lh#mut#dirs#get_templates_for("cpp/value-class")')).to match(/value-class.template/) expect(vim.command('call lh#mut#expand_and_jump(0, "cpp/value-class", {"use_copy_and_swap": 0, "attributes": [{"name": "foo", "type": "int"}, {"name": "bar", "type": "std::auto_ptr", "includes":["", ""], "functions": ["ref_set", "set", "get"]}]})')).to match(/^$|#include added/) - vim.feedkeys('\\:silent! $call append("$", ["",""])\G') + # vim.feedkeys('\\:silent! $call append("$", ["",""])\G') # T* will require a destructor in current class # auto_ptr<> will require a destructor in current class, even empty # unique_ptr<>, doesn't require anything @@ -261,7 +262,7 @@ class «Test» specify "value-attribute-class copyable, with ptr attributes", :cpp98, :cpp11, :copyable, :copy_n_swap do expect(vim.echo('lh#mut#dirs#get_templates_for("cpp/value-class")')).to match(/value-class.template/) expect(vim.command('call lh#mut#expand_and_jump(0, "cpp/value-class", {"use_copy_and_swap": 1, "attributes": [{"name": "foo", "type": "int"}, {"name": "bar", "type": "std::auto_ptr", "includes":["", ""], "functions": ["ref_set", "set", "get"]}]})')).to match(/^$|#include added/) - vim.feedkeys('\\:silent! $call append("$", ["",""])\G') + # vim.feedkeys('\\:silent! $call append("$", ["",""])\G') # T* will require a destructor in current class # auto_ptr<> will require a destructor in current class, even empty # unique_ptr<>, doesn't require anything diff --git a/tests/Flavorfile b/tests/Flavorfile new file mode 100644 index 0000000..1ff4bb4 --- /dev/null +++ b/tests/Flavorfile @@ -0,0 +1 @@ +flavor 'LucHermitte/vim-UT', '>= 2.0.9' diff --git a/tests/VimFlavor b/tests/VimFlavor deleted file mode 100644 index 48c19d0..0000000 --- a/tests/VimFlavor +++ /dev/null @@ -1 +0,0 @@ -flavor 'LucHermitte/vim-UT', '>= 0.6.0'