diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..30ba681 --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,63 @@ +# 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: Install vim plugin dependencies + # Manually install UT -- without vim-flavor which will install + # lh-vim-lib a second time and create conflicts... + run: | + mkdir -p ~/.vim/pack/flavors/start + git clone https://github.com/LucHermitte/vim-UT ~/.vim/pack/flavors/start/UT + - name: Run tests on Linux + if: runner.os == 'Linux' # headless execution is required on Linux + run: | + xvfb-run bundle exec rake test + - name: Run tests on ${{ matrix.os }} + if: runner.os != 'Linux' + run: | + bundle exec rake test diff --git a/.rspec b/.rspec index b079174..43ae203 100644 --- a/.rspec +++ b/.rspec @@ -1,4 +1,3 @@ --color --require spec_helper --format documentation --I ~/.vim-flavor/repos/LucHermitte_vim-UT/spec diff --git a/Gemfile b/Gemfile index e6bce45..964a273 100644 --- a/Gemfile +++ b/Gemfile @@ -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' diff --git a/README.md b/README.md index 304b9c4..0d733d2 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# lh-vim-lib [![Last release](https://img.shields.io/github/tag/LucHermitte/lh-vim-lib.svg)](https://github.com/LucHermitte/lh-vim-lib/releases) [![Build Status](https://secure.travis-ci.org/LucHermitte/lh-vim-lib.png?branch=master)](http://travis-ci.org/LucHermitte/lh-vim-lib) [![Project Stats](https://www.openhub.net/p/21020/widgets/project_thin_badge.gif)](https://www.openhub.net/p/21020) +# lh-vim-lib [![Last release](https://img.shields.io/github/tag/LucHermitte/lh-vim-lib.svg)](https://github.com/LucHermitte/lh-vim-lib/releases) [![Build Status](https://github.com/LucHermitte/lh-vim-lib/actions/workflows/tests.yml/badge.svg)](http://travis-ci.org/LucHermitte/lh-vim-lib) [![Project Stats](https://www.openhub.net/p/21020/widgets/project_thin_badge.gif)](https://www.openhub.net/p/21020) ## Introduction diff --git a/Rakefile b/Rakefile index bb1f0df..4f62a2b 100644 --- a/Rakefile +++ b/Rakefile @@ -14,9 +14,9 @@ end task :test => :spec -task :spec do - sh "rspec ~/.vim-flavor/repos/LucHermitte_vim-UT/spec" -end +# task :spec do +# sh "bundle exec rspec spec/UT_spec.rb" +# end task :install do sh 'cd tests && bundle exec vim-flavor install' diff --git a/spec/UT_spec.rb b/spec/UT_spec.rb new file mode 100644 index 0000000..b1fa859 --- /dev/null +++ b/spec/UT_spec.rb @@ -0,0 +1,64 @@ +# encoding: UTF-8 +# +# unit tests spec runner dedicated to lh-vim-lib +# -> These tests needs to rely 100% on clones lh-vim-lib + +require 'pp' + +RSpec.describe "unit tests" do + # First search for a vimrc that bootstraps vim-flavor v2 + # (v3 uses global packadd from vim8) + # It could be: + # - either {plugin}/spec/flavor.vimrc + # - or ~/.vimrc/flavors/bootstrap.vim + vimrc_candidates = ['spec/flavor.vimrc', + ENV['HOME']+'/.vim/flavors/bootstrap.vim', + ENV['HOME']+'/vimfiles/flavors/bootstrap.vim'] + vimrc = vimrc_candidates.find{ |candidate| File.file?(candidate)} + if vimrc.nil? + print "no bootstrapping vimrc found...\n" + vim_plugin_path = File.expand_path('.') + u_vimrc = "--cmd 'set rtp+=#{vim_plugin_path},#{vim_plugin_path}/after' --cmd 'filetype plugin on'" + else + print "bootstrapping vimrc found: #{vimrc}\n" + vim_plugin_path = File.expand_path('.') + # '-u {file}' forces '&compatible' => '-N' + u_vimrc = "-u #{vimrc} -N --cmd 'set rtp+=#{vim_plugin_path},#{vim_plugin_path}/after' --cmd 'filetype plugin on'" + end + + cmd = %(vim #{u_vimrc} -X -V1 -e -s -c "echo 'RTP: '..&rtp" -c "scriptnames" -c "q") + pp system(cmd) + + # The tests + describe "Check all tests", :unit_tests => true do + pwd = Dir.pwd + files = Dir.glob('./tests/**/*.vim') + pp "In directory #{pwd}, run #{files}" + files.each{ |file| + it "[#{file}] runs fine" do + abs_file = pwd + '/' + file + log_file = abs_file + '.log' + # pp "file: #{file}" + # pp "abs: #{abs_file}" + # pp "log: #{log_file}" + # TODO: collect verbose mode messages + cmd = %(vim #{u_vimrc} -N -X -e -s -c "UTBatch #{log_file} #{abs_file}") + # pp cmd + ok = system(cmd) + # print "Check log file '#{log_file}' exists\n" + # expect(log_file).to be_an_existing_file + if ! ok + # print "Log file: #{file}.log\n" + if File.file?(log_file) + log = File.read(log_file) + else + log = "Warning: Cannot read #{log_file}" + end + end + expect(ok).to be_truthy, "expected test to succeed, got\n#{log}\n" + end + } + end +end + +# vim:set sw=2: diff --git a/tests/Flavorfile b/tests/Flavorfile new file mode 100644 index 0000000..55af87a --- /dev/null +++ b/tests/Flavorfile @@ -0,0 +1 @@ +flavor 'LucHermitte/vim-UT', '>= 2.0.6' diff --git a/tests/VimFlavor b/tests/VimFlavor deleted file mode 100644 index 1ef99cf..0000000 --- a/tests/VimFlavor +++ /dev/null @@ -1 +0,0 @@ -flavor 'LucHermitte/vim-UT', '>= 1.0.4' diff --git a/tests/lh/function.vim b/tests/lh/function.vim index 20b91b2..6cd0d26 100644 --- a/tests/lh/function.vim +++ b/tests/lh/function.vim @@ -4,9 +4,9 @@ " " License: GPLv3 with exceptions " -" Version: 4.0.0 +" Version: 5.4.0 " Created: 03rd Nov 2008 -" Last Update: 26th Jul 2018 +" Last Update: 17th Aug 2024 "------------------------------------------------------------------------ " Description: " Tests for autoload/lh/function.vim @@ -299,11 +299,11 @@ endfunction " Function: s:Test_partial() {{{3 function! s:Test_partial() abort - let l:Cb = lh#partial#make('has', ['gui_running']) + let l:Cb = lh#partial#make('has', ['eval']) AssertEquals(1, lh#partial#execute(l:Cb)) let l:Cb = lh#partial#make('has', []) - AssertEquals(1, lh#partial#execute(l:Cb, 'gui_running')) - AssertEquals(0, lh#partial#execute(l:Cb, 'g*i_running')) + AssertEquals(1, lh#partial#execute(l:Cb, 'eval')) + AssertEquals(0, lh#partial#execute(l:Cb, 'e*val')) endfunction " }}}1 diff --git a/tests/lh/options.vim b/tests/lh/options.vim index 8b99d0e..a1fce35 100644 --- a/tests/lh/options.vim +++ b/tests/lh/options.vim @@ -7,7 +7,7 @@ " Version: 5.3.3. let s:k_version = '533' " Created: 18th Aug 2021 -" Last Update: 18th Aug 2021 +" Last Update: 17th Aug 2024 "------------------------------------------------------------------------ " Description: " Test lh#option#get() function @@ -78,11 +78,15 @@ function! s:Test_global() " {{{2 let b:foo = 43 AssertEquals(lh#option#get('foo', 12) , 43) - LetTo p:foo = 44 - AssertEquals(lh#option#get('foo', 12) , 43) + if lh#project#is_in_a_project() + " Cannot be tested if not in a project. + " -> tests/lh/project.vim will tests this scenario + LetTo p:foo = 44 + AssertEquals(lh#option#get('foo', 12) , 43) - Unlet b:foo - AssertEquals(lh#option#get('foo', 12) , 44) + Unlet b:foo + AssertEquals(lh#option#get('foo', 12) , 44) + endif finally call cleanup.finalize() endtry diff --git a/tests/lh/ref.vim b/tests/lh/ref.vim index e38a693..e89902d 100644 --- a/tests/lh/ref.vim +++ b/tests/lh/ref.vim @@ -5,7 +5,7 @@ " Version: 4.6.0. let s:k_version = '40600' " Created: 09th Sep 2016 -" Last Update: 18th Oct 2018 +" Last Update: 18th Aug 2024 "------------------------------------------------------------------------ " Description: " «description» @@ -134,12 +134,16 @@ function! s:Test_scoped() " {{{2 AssertIs(res.resolve(), b:dummy) let g:__d = {'k': 42} - LetTo p:dummy = g:__d - AssertIs(res.resolve(), b:dummy) + if lh#project#is_in_a_project() + LetTo p:dummy = g:__d + AssertIs(res.resolve(), b:dummy) + endif unlet b:dummy Assert ! has_key(b:, 'dummy') - AssertIs(res.resolve(), g:__d) + if lh#project#is_in_a_project() + AssertIs(res.resolve(), g:__d) + endif finally Unlet g:__d Unlet p:dummy