Skip to content

Commit

Permalink
Create GA: tests.yml (#20)
Browse files Browse the repository at this point in the history
Migrate from travis to Github Actions

- Update ruby  version to 3
- Update gemfile
- Rename VimFlavor to Flavorfile
- Don't rely on vim-flavor but directly install vim-UT -- to avoid installing lh-vim-lib twice is different version: we want to test the current sources, not the last tagged version
- Execute tests only on ubuntu-latest (headless) and macos
- Execute tests with Vim (8, currently) and neovim
- Fix CI tests: options.vim, ref.vim, has.vim
- Tests are directly executed without relying on vim-runner and +clientserver interface


TODO:
- test on Windows
- Test different version of Vim
  • Loading branch information
LucHermitte authored Aug 18, 2024
1 parent 612538b commit 767887c
Show file tree
Hide file tree
Showing 11 changed files with 157 additions and 23 deletions.
63 changes: 63 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -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
1 change: 0 additions & 1 deletion .rspec
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
--color
--require spec_helper
--format documentation
-I ~/.vim-flavor/repos/LucHermitte_vim-UT/spec
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'
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
6 changes: 3 additions & 3 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
64 changes: 64 additions & 0 deletions spec/UT_spec.rb
Original file line number Diff line number Diff line change
@@ -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:
1 change: 1 addition & 0 deletions tests/Flavorfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
flavor 'LucHermitte/vim-UT', '>= 2.0.6'
1 change: 0 additions & 1 deletion tests/VimFlavor

This file was deleted.

10 changes: 5 additions & 5 deletions tests/lh/function.vim
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
" <URL:http://github.com/LucHermitte/lh-vim-lib>
" License: GPLv3 with exceptions
" <URL:http://github.com/LucHermitte/lh-vim-lib/License.md>
" 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
Expand Down Expand Up @@ -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
Expand Down
14 changes: 9 additions & 5 deletions tests/lh/options.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
12 changes: 8 additions & 4 deletions tests/lh/ref.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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»
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 767887c

Please sign in to comment.