From 81ba1bb96b332f1501e909a469ab0ee035c9cc12 Mon Sep 17 00:00:00 2001 From: Jonathan Apodaca Date: Mon, 19 May 2025 19:03:24 -0600 Subject: [PATCH] Use nix to create environment for testing --- .busted | 13 +++++++++++++ .github/workflows/ci.yaml | 25 +++++++++++++++++++------ .gitignore | 3 +-- .luacov | 6 ++++++ Makefile | 27 ++++++++++++++++----------- lux.toml | 19 ------------------- selene.toml | 4 ---- shell.nix | 20 ++++++++++++++++++++ spec/withbuf.lua | 1 + vim.yml | 36 ------------------------------------ 10 files changed, 76 insertions(+), 78 deletions(-) create mode 100644 .busted create mode 100644 .luacov delete mode 100644 lux.toml delete mode 100644 selene.toml create mode 100644 shell.nix delete mode 100644 vim.yml diff --git a/.busted b/.busted new file mode 100644 index 0000000..8c64018 --- /dev/null +++ b/.busted @@ -0,0 +1,13 @@ +return { + _all = { + coverage = false, + lpath = "lua/?.lua;lua/?/init.lua", + lua = "nlua", + }, + default = { + verbose = true + }, + tests = { + verbose = true + }, +} diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index ef4ab02..c8e6c01 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -2,15 +2,28 @@ name: NeoVim tests on: [push] jobs: - plenary-tests: + code-quality: runs-on: ubuntu-latest env: XDG_CONFIG_HOME: ${{ github.workspace }}/.config/ steps: - uses: actions/checkout@v4 - - uses: rhysd/action-setup-vim@v1 + - uses: cachix/install-nix-action@v31 with: - neovim: true - version: v0.11.0 - arch: 'x86_64' - - run: make test + nix_path: nixpkgs=channel:nixos-unstable + + - name: Populate Nix store + run: + nix-shell --run 'true' + + - name: Type-check with lua-language-server + run: + nix-shell --run 'make lint' + + - name: Check formatting with stylua + run: + nix-shell --run 'make fmt-check' + + - name: Run busted tests + run: + nix-shell --run 'make test' diff --git a/.gitignore b/.gitignore index 9718e15..202f9f8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ -/.lux/ -lux.lock *.src.rock *.aider* +luacov.*.out diff --git a/.luacov b/.luacov new file mode 100644 index 0000000..7c09929 --- /dev/null +++ b/.luacov @@ -0,0 +1,6 @@ +return { + include = { + 'lua/u/', + }, + tick = true, +} diff --git a/Makefile b/Makefile index fe9d0eb..0c4a074 100644 --- a/Makefile +++ b/Makefile @@ -1,16 +1,21 @@ -PLENARY_DIR=~/.local/share/nvim/site/pack/test/opt/plenary.nvim - -all: lint test +all: lint fmt-check test lint: - lua-language-server --check=lua/u/ --checklevel=Error - lx check + @echo "## Typechecking" + @lua-language-server --check=lua/u/ --checklevel=Error + +fmt-check: + @echo "## Checking code format" + @stylua --check . fmt: - stylua . + @echo "## Formatting code" + @stylua . -test: $(PLENARY_DIR) - NVIM_APPNAME=noplugstest nvim -u NORC --headless -c 'set packpath+=~/.local/share/nvim/site' -c 'packadd plenary.nvim' -c "PlenaryBustedDirectory spec/" - -$(PLENARY_DIR): - git clone https://github.com/nvim-lua/plenary.nvim/ $(PLENARY_DIR) +test: + @rm -f luacov.*.out + @echo "## Running tests" + @busted --coverage --verbose + @echo "## Generating coverage report" + @luacov + @awk '/^Summary$$/{flag=1;next} flag{print}' luacov.report.out diff --git a/lux.toml b/lux.toml deleted file mode 100644 index 394f8e2..0000000 --- a/lux.toml +++ /dev/null @@ -1,19 +0,0 @@ -package = "u.nvim" -version = "0.2.0" -lua = ">=5.1" - -[description] -summary = "" -maintainer = "jrop" -labels = [ "library", "neovim", "neovim-plugin", "range", "utility" ] - - -[dependencies] -# Add your dependencies here -# `busted = ">=2.0"` - -[run] -args = [ "src/main.lua" ] - -[build] -type = "builtin" \ No newline at end of file diff --git a/selene.toml b/selene.toml deleted file mode 100644 index 9965200..0000000 --- a/selene.toml +++ /dev/null @@ -1,4 +0,0 @@ -std = "vim" - -[lints] -multiple_statements = "allow" diff --git a/shell.nix b/shell.nix new file mode 100644 index 0000000..6050b12 --- /dev/null +++ b/shell.nix @@ -0,0 +1,20 @@ +{ + pkgs ? + import + # neovim@0.11.1: https://history.nix-packages.com/package/neovim/0.11.1 + (fetchTarball "https://github.com/nixos/nixpkgs/tarball/e73c3bf29132da092f9c819b97b6e214367eb71f") + { }, +}: +pkgs.mkShell { + packages = [ + pkgs.git + pkgs.gnumake + pkgs.lua-language-server + pkgs.lua51Packages.busted + pkgs.lua51Packages.luacov + pkgs.lua51Packages.luarocks + pkgs.lua51Packages.nlua + pkgs.neovim + pkgs.stylua + ]; +} diff --git a/spec/withbuf.lua b/spec/withbuf.lua index 9fe85b7..ee1d790 100644 --- a/spec/withbuf.lua +++ b/spec/withbuf.lua @@ -1,3 +1,4 @@ +require 'luacov' local function withbuf(lines, f) vim.go.swapfile = false diff --git a/vim.yml b/vim.yml deleted file mode 100644 index 4e0149f..0000000 --- a/vim.yml +++ /dev/null @@ -1,36 +0,0 @@ ---- -base: lua51 -globals: - vim: - any: true - assert.are.same: - args: - - type: any - - type: any - assert.are_not.same: - args: - - type: any - - type: any - assert.has.error: - args: - - type: any - - type: any - assert.is_true: - args: - - type: any - - type: any - assert.is_false: - args: - - type: any - - type: any - describe: - args: - - type: string - - type: function - it: - args: - - type: string - - type: function - before_each: - args: - - type: function