From 4d4ade7f2b8f403e8816ca50c05ed16e259b21fb Mon Sep 17 00:00:00 2001 From: James Trew <66286082+jamestrew@users.noreply.github.com> Date: Sat, 13 Apr 2024 11:27:53 -0400 Subject: [PATCH] build: rework ci tests to include windows (#3011) --- .github/workflows/ci.yml | 49 +++++++------------ .github/workflows/docgen.yml | 6 +-- .github/workflows/lint.yml | 6 +-- .github/workflows/release.yml | 6 +-- Makefile | 2 + doc/telescope.txt | 31 ++++++++++-- lua/telescope/utils.lua | 2 +- .../automated/pickers/find_files_spec.lua | 2 +- lua/tests/automated/telescope_spec.lua | 12 +++-- scripts/minimal_init.vim | 1 - 10 files changed, 67 insertions(+), 50 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f8aa989cda..eedf0bc8c1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,48 +9,33 @@ jobs: strategy: fail-fast: false matrix: + os: [ubuntu-22.04, macos-12, windows-2022] + rev: [nightly, v0.9.0] include: - os: ubuntu-22.04 - rev: nightly/nvim-linux64.tar.gz - manager: sudo apt-get - packages: -y ripgrep - - os: ubuntu-22.04 - rev: v0.9.0/nvim-linux64.tar.gz - manager: sudo apt-get - packages: -y ripgrep - - os: macos-12 - rev: nightly/nvim-macos.tar.gz - manager: brew - packages: ripgrep + install-rg: sudo apt-get update && sudo apt-get install -y ripgrep - os: macos-12 - rev: v0.9.0/nvim-macos.tar.gz - manager: brew - packages: ripgrep + install-rg: brew update && brew install ripgrep + - os: windows-2022 + install-rg: choco install ripgrep + steps: - - uses: actions/checkout@v3 - - run: date +%F > todays-date - - name: Restore from todays cache - uses: actions/cache@v3 + - uses: actions/checkout@v4 + + - uses: rhysd/action-setup-vim@v1 with: - path: _neovim - key: ${{ runner.os }}-${{ matrix.rev }}-${{ hashFiles('todays-date') }} + neovim: true + version: ${{ matrix.rev }} - name: Prepare run: | - ${{ matrix.manager }} update - ${{ matrix.manager }} install ${{ matrix.packages }} - test -d _neovim || { - mkdir -p _neovim - curl -sL "https://github.com/neovim/neovim/releases/download/${{ matrix.rev }}" | tar xzf - --strip-components=1 -C "${PWD}/_neovim" - } - mkdir -p ~/.local/share/nvim/site/pack/vendor/start - git clone --depth 1 https://github.com/nvim-lua/plenary.nvim ~/.local/share/nvim/site/pack/vendor/start/plenary.nvim - git clone --depth 1 https://github.com/nvim-tree/nvim-web-devicons ~/.local/share/nvim/site/pack/vendor/start/nvim-web-devicons - ln -s $(pwd) ~/.local/share/nvim/site/pack/vendor/start + ${{ matrix.install-rg }} + rg --version + + git clone --depth 1 https://github.com/nvim-lua/plenary.nvim ../plenary.nvim + git clone --depth 1 https://github.com/nvim-tree/nvim-web-devicons ../nvim-web-devicons - name: Run tests run: | - export PATH="${PWD}/_neovim/bin:${PATH}" - export VIM="${PWD}/_neovim/share/nvim/runtime" nvim --version make test diff --git a/.github/workflows/docgen.yml b/.github/workflows/docgen.yml index d436125eba..56b5780213 100644 --- a/.github/workflows/docgen.yml +++ b/.github/workflows/docgen.yml @@ -14,12 +14,12 @@ jobs: matrix: include: - os: ubuntu-22.04 - url: https://github.com/neovim/neovim/releases/download/nightly/nvim-linux64.tar.gz + url: https://github.com/neovim/neovim/releases/download/v0.9.5/nvim-linux64.tar.gz steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - run: date +%F > todays-date - name: Restore cache for today's nightly. - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: _neovim key: ${{ runner.os }}-${{ matrix.url }}-${{ hashFiles('todays-date') }} diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index b35b834794..c1afb24334 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -7,7 +7,7 @@ jobs: name: Luacheck runs-on: ubuntu-22.04 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Prepare run: | @@ -22,8 +22,8 @@ jobs: name: stylua runs-on: ubuntu-22.04 steps: - - uses: actions/checkout@v3 - - uses: JohnnyMorganz/stylua-action@v3 + - uses: actions/checkout@v4 + - uses: JohnnyMorganz/stylua-action@v4 with: token: ${{ secrets.GITHUB_TOKEN }} version: latest diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 84ed031716..819a147b6e 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -7,7 +7,7 @@ jobs: luarocks-upload: runs-on: ubuntu-22.04 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: LuaRocks Upload uses: nvim-neorocks/luarocks-tag-release@v1.0.2 env: @@ -15,8 +15,8 @@ jobs: with: summary: "Find, Filter, Preview, Pick. All lua, all the time." detailed_description: | - A highly extendable fuzzy finder over lists. - Built on the latest awesome features from neovim core. + A highly extendable fuzzy finder over lists. + Built on the latest awesome features from neovim core. Telescope is centered around modularity, allowing for easy customization. dependencies: | plenary.nvim diff --git a/Makefile b/Makefile index c3da51def6..e520d60749 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,5 @@ +.PHONY: test lint docgen + test: nvim --headless --noplugin -u scripts/minimal_init.vim -c "PlenaryBustedDirectory lua/tests/automated/ { minimal_init = './scripts/minimal_init.vim' }" diff --git a/doc/telescope.txt b/doc/telescope.txt index b7e06a3c59..690298d5f5 100644 --- a/doc/telescope.txt +++ b/doc/telescope.txt @@ -2536,6 +2536,31 @@ UTILS *telescope.utils* Utilities for writing telescope pickers +utils.path_expand({path}) *telescope.utils.path_expand()* + Hybrid of `vim.fn.expand()` and custom `vim.fs.normalize()` + + Paths starting with '%', '#' or '<' are expanded with `vim.fn.expand()`. + Otherwise avoids using `vim.fn.expand()` due to its overly aggressive + expansion behavior which can sometimes lead to errors or the creation of + non-existent paths when dealing with valid absolute paths. + + Other paths will have '~' and environment variables expanded. Unlike + `vim.fs.normalize()`, backslashes are preserved. This has better + compatibility with `plenary.path` and also avoids mangling valid Unix paths + with literal backslashes. + + Trailing slashes are trimmed. With the exception of root paths. eg. `/` on + Unix or `C:\` on Windows + + + + Parameters: ~ + {path} (string) + + Return: ~ + string + + utils.transform_path({opts}, {path}) *telescope.utils.transform_path()* Transform path is a util function that formats a path based on path_display found in `opts` or the default value from config. It is meant to be used in @@ -2546,9 +2571,9 @@ utils.transform_path({opts}, {path}) *telescope.utils.transform_path()* Parameters: ~ - {opts} (table) The opts the users passed into the picker. Might - contains a path_display key - {path} (string) The path that should be formatted + {opts} (table) The opts the users passed into the picker. Might + contains a path_display key + {path} (string|nil) The path that should be formatted Return: ~ string: The transformed path ready to be displayed diff --git a/lua/telescope/utils.lua b/lua/telescope/utils.lua index 944c82d805..e515142474 100644 --- a/lua/telescope/utils.lua +++ b/lua/telescope/utils.lua @@ -269,7 +269,7 @@ end --- this function outside of telescope might yield to undefined behavior and will --- not be addressed by us ---@param opts table: The opts the users passed into the picker. Might contains a path_display key ----@param path string?: The path that should be formatted +---@param path string|nil: The path that should be formatted ---@return string: The transformed path ready to be displayed utils.transform_path = function(opts, path) if path == nil then diff --git a/lua/tests/automated/pickers/find_files_spec.lua b/lua/tests/automated/pickers/find_files_spec.lua index f285d4f62b..5a1c460b16 100644 --- a/lua/tests/automated/pickers/find_files_spec.lua +++ b/lua/tests/automated/pickers/find_files_spec.lua @@ -1,5 +1,5 @@ -- Just skip on mac, it has flaky CI for some reason -if vim.fn.has "mac" == 1 then +if vim.fn.has "mac" == 1 or require("telescope.utils").iswin then return end diff --git a/lua/tests/automated/telescope_spec.lua b/lua/tests/automated/telescope_spec.lua index 3bb76c36b7..44594dd3fa 100644 --- a/lua/tests/automated/telescope_spec.lua +++ b/lua/tests/automated/telescope_spec.lua @@ -1,7 +1,12 @@ local picker = require "telescope.pickers" +local Path = require "plenary.path" local eq = assert.are.same +local function new_path(unix_path) + return Path:new(unpack(vim.split(unix_path, "/"))).filename +end + describe("telescope", function() describe("Picker", function() describe("window_dimensions", function() @@ -84,8 +89,8 @@ describe("telescope", function() it("sorts matches after last os sep better", function() local sorter = require("telescope.sorters").get_fuzzy_file() - local better_match = sorter:score("aaa", { ordinal = "bbb/aaa" }) - local worse_match = sorter:score("aaa", { ordinal = "aaa/bbb" }) + local better_match = sorter:score("aaa", { ordinal = new_path "bbb/aaa" }) + local worse_match = sorter:score("aaa", { ordinal = new_path "aaa/bbb" }) assert(better_match < worse_match, "Final match should be stronger") end) @@ -103,6 +108,7 @@ describe("telescope", function() describe("fzy", function() local sorter = require("telescope.sorters").get_fzy_sorter() local function score(prompt, line) + line = new_path(line) return sorter:score(prompt, { ordinal = line }, function(val) return val end, function() @@ -171,7 +177,7 @@ describe("telescope", function() end) local function positions(prompt, line) - return sorter:highlighter(prompt, line) + return sorter:highlighter(prompt, new_path(line)) end describe("positioning", function() diff --git a/scripts/minimal_init.vim b/scripts/minimal_init.vim index c2fd6eaf5a..6f6731f756 100644 --- a/scripts/minimal_init.vim +++ b/scripts/minimal_init.vim @@ -4,6 +4,5 @@ set rtp+=../tree-sitter-lua/ runtime! plugin/plenary.vim runtime! plugin/telescope.lua -runtime! plugin/ts_lua.vim let g:telescope_test_delay = 100