Skip to content

Commit d5553e7

Browse files
authored
Merge pull request #330 from cameronr/main
Unit test fixes and run them as a GH action
2 parents 08c2798 + 54c9ec7 commit d5553e7

28 files changed

+433
-208
lines changed

.github/workflows/tests.yml

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# From
2+
# https://github.com/shortcuts/neovim-plugin-boilerplate/blob/main/.github/workflows/main.yml
3+
4+
name: tests
5+
6+
on:
7+
push:
8+
pull_request:
9+
types: [opened, synchronize]
10+
11+
jobs:
12+
lint:
13+
runs-on: ubuntu-latest
14+
name: lint
15+
steps:
16+
- uses: actions/checkout@v4
17+
18+
- uses: JohnnyMorganz/stylua-action@v4
19+
with:
20+
token: ${{ secrets.GITHUB_TOKEN }}
21+
version: latest
22+
args: --check . -g '*.lua' -g '!deps/'
23+
24+
test:
25+
runs-on: ubuntu-latest
26+
timeout-minutes: 2
27+
strategy:
28+
matrix:
29+
neovim_version: ["v0.7.2", "v0.8.3", "v0.9.5", "v0.10.0", "nightly"]
30+
31+
steps:
32+
- uses: actions/checkout@v4
33+
34+
- run: date +%F > todays-date
35+
36+
- name: restore cache for today's nightly.
37+
uses: actions/cache@v4
38+
with:
39+
path: _neovim
40+
key: ${{ runner.os }}-x64-${{ hashFiles('todays-date') }}
41+
42+
- name: setup neovim
43+
uses: rhysd/action-setup-vim@v1
44+
with:
45+
neovim: true
46+
version: ${{ matrix.neovim_version }}
47+
48+
- name: install ripgrep
49+
run: |
50+
sudo apt-get update
51+
sudo apt-get install -y ripgrep
52+
53+
- name: run tests
54+
run: |
55+
make test

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Auto-generated tag files
22
doc/tags
33
.luarc.json
4+
.test
45
.build_tools
56

67
tests/test_sessions

Makefile

+10-9
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
PLENARY_VER = v0.1.4
2-
PLENARY_DIR = .build_tools/plenary
2+
PLENARY_DIR = .test/plenary
33
PLENARY_URL = https://github.com/nvim-lua/plenary.nvim
44

55
FILES := $(wildcard tests/*_spec.lua)
66

77
.PHONY: test $(FILES) args-tests
88
test: $(PLENARY_DIR) $(FILES) args-tests
99

10-
$(FILES):
11-
nvim --clean --headless --embed -u tests/minimal.vim +"PlenaryBustedFile $@"
10+
$(FILES): $(PLENARY_DIR)
11+
nvim --clean --headless -u tests/minimal.lua +"PlenaryBustedFile $@"
12+
1213

13-
args-tests:
14-
nvim --clean --headless --embed -u tests/minimal.vim +"PlenaryBustedFile tests/args/args_setup_spec.lua"
15-
nvim --clean --headless --embed -u tests/minimal.vim +"PlenaryBustedFile tests/args/args_not_enabled_spec.lua"
16-
nvim --clean --headless --embed -u tests/minimal.vim +"PlenaryBustedFile tests/args/args_single_dir_enabled_spec.lua"
17-
nvim --clean --headless --embed -u tests/minimal.vim +"PlenaryBustedFile tests/args/args_files_enabled_spec.lua"
14+
args-tests: $(PLENARY_DIR)
15+
nvim --clean --headless -u tests/minimal.lua +"PlenaryBustedFile tests/args/args_setup_spec.lua"
16+
nvim --clean --headless -u tests/minimal.lua +"PlenaryBustedFile tests/args/args_not_enabled_spec.lua"
17+
nvim --clean --headless -u tests/minimal.lua +"PlenaryBustedFile tests/args/args_single_dir_enabled_spec.lua"
18+
nvim --clean --headless -u tests/minimal.lua +"PlenaryBustedFile tests/args/args_files_enabled_spec.lua"
1819

1920

2021
$(PLENARY_DIR):
21-
git clone --depth=1 --branch $(PLENARY_VER) $(PLENARY_URL) $(PLENARY_DIR)
22+
git clone --depth=1 --branch $(PLENARY_VER) $(PLENARY_URL) $(PLENARY_DIR)

README.md

+37-34
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
1-
# 🗒️ Description
1+
# 🗒️ AutoSession
22

3-
Auto Session takes advantage of Neovim's existing session management capabilities to provide seamless automatic session management.
3+
AutoSession takes advantage of Neovim's existing session management capabilities to provide seamless automatic session management.
44

55
<img src="https://github.com/rmagatti/readme-assets/blob/main/auto-session-new-example.gif" width="800" />
66

7+
[<img alt="GitHub Actions Workflow Status" src="https://img.shields.io/github/actions/workflow/status/rmagatti/auto-session/tests.yml?style=for-the-badge&label=tests">](https://github.com/rmagatti/auto-session/actions/workflows/tests.yml)
8+
79
# 💡 Behaviour
810

9-
1. When starting `nvim` with no arguments, auto-session will try to restore an existing session for the current `cwd` if one exists.
10-
2. When starting `nvim .` (or another directory), auto-session will try to restore the session for that directory.
11-
3. When starting `nvim some_file.txt` (or multiple files), by default, auto-session won't do anything. See [argument handling](#argument-handling) for more details.
11+
1. When starting `nvim` with no arguments, AutoSession will try to restore an existing session for the current `cwd` if one exists.
12+
2. When starting `nvim .` (or another directory), AutoSession will try to restore the session for that directory.
13+
3. When starting `nvim some_file.txt` (or multiple files), by default, AutoSession won't do anything. See [argument handling](#argument-handling) for more details.
1214
4. Even after starting `nvim` with a file argument, a session can still be manually restored by running `:SessionRestore`.
1315
5. Any session saving and restoration takes into consideration the current working directory `cwd`.
14-
6. When piping to `nvim`, e.g: `cat myfile | nvim`, auto-session won't do anything.
16+
6. When piping to `nvim`, e.g: `cat myfile | nvim`, AutoSession won't do anything.
1517

1618
:warning: Please note that if there are errors in your config, restoring the session might fail, if that happens, auto session will then disable auto saving for the current session.
1719
Manually saving a session can still be done by calling `:SessionSave`.
@@ -20,16 +22,16 @@ AutoSession can now track `cwd` changes!
2022
By default, `cwd` handling is disabled but when enabled, it works as follows:
2123

2224
- DirChangedPre (before the cwd actually changes):
23-
- Save the current session
24-
- Clear all buffers `%bd!`. This guarantees buffers don't bleed to the
25-
next session.
26-
- Clear jumps. Also done so there is no bleeding between sessions.
27-
- Run the `pre_cwd_changed_hook`/
25+
- Save the current session
26+
- Clear all buffers `%bd!`. This guarantees buffers don't bleed to the
27+
next session.
28+
- Clear jumps. Also done so there is no bleeding between sessions.
29+
- Run the `pre_cwd_changed_hook`/
2830
- DirChanged (after the cwd has changed):
29-
- Restore session using new cwd
30-
- Run the `post_cwd_changed_hook`
31+
- Restore session using new cwd
32+
- Run the `post_cwd_changed_hook`
3133

32-
Now when the user changes the cwd with `:cd some/new/dir` auto-session handles it gracefully, saving the current session so there aren't losses and loading the session for the upcoming cwd if it exists.
34+
Now when the user changes the cwd with `:cd some/new/dir` AutoSession handles it gracefully, saving the current session so there aren't losses and loading the session for the upcoming cwd if it exists.
3335

3436
Hooks are available for custom actions _before_ and _after_ the `cwd` is changed. These hooks can be configured through the `cwd_change_handling` key as follows:
3537

@@ -85,7 +87,7 @@ use {
8587

8688
### Default
8789

88-
Auto Session by default stores sessions in `vim.fn.stdpath('data').."/sessions/"`.
90+
AutoSession by default stores sessions in `vim.fn.stdpath('data').."/sessions/"`.
8991

9092
### Custom
9193

@@ -194,7 +196,7 @@ Now last session will be restored only when Neovim is launched in the home direc
194196

195197
# 📢 Commands
196198

197-
Auto Session exposes two commands that can be used or mapped to any keybindings for manually saving and restoring sessions.
199+
AutoSession exposes the following commands that can be used or mapped to any keybindings for manually saving and restoring sessions.
198200

199201
```viml
200202
:SessionSave " saves or creates a session in the currently set `auto_session_root_dir`.
@@ -205,8 +207,8 @@ Auto Session exposes two commands that can be used or mapped to any keybindings
205207
:SessionDelete " deletes a session in the currently set `auto_session_root_dir`.
206208
:SessionDelete ~/my/custom/path " deletes a session based on the provided path.
207209
:SessionPurgeOrphaned " removes all orphaned sessions with no working directory left.
208-
:Autosession search
209-
:Autosession delete
210+
:Autosession search " open a vim.ui.select picker to choose a session to load.
211+
:Autosession delete " open a vim.ui.select picker to choose a session to delete.
210212
```
211213

212214
You can use the `Autosession {delete|search}` command to open a picker using `vim.ui.select` this will allow you to either delete or search for a session to restore.
@@ -218,14 +220,14 @@ There's also Telescope support, see the [Session Lens](#-session-lens) section b
218220

219221
Command hooks exist in the format: {hook_name}
220222

221-
- {pre_save}: executes _before_ a session is saved
222-
- {save_extra}: executes _after_ a session is saved, return string will save to `*x.vim`, reference `:help mks`
223-
- {post_save}: executes _after_ a session is saved
224-
- {pre_restore}: executes _before_ a session is restored
225-
- {post_restore}: executes _after_ a session is restored
226-
- {pre_delete}: executes _before_ a session is deleted
227-
- {post_delete}: executes _after_ a session is deleted
228-
- {no_restore}: executes _at_ `VimEnter` _when_ no session is restored
223+
- `{pre_save}`: executes _before_ a session is saved
224+
- `{save_extra}`: executes _after_ a session is saved, return string will save to `*x.vim`, reference `:help mks`
225+
- `{post_save}`: executes _after_ a session is saved
226+
- `{pre_restore}`: executes _before_ a session is restored
227+
- `{post_restore}`: executes _after_ a session is restored
228+
- `{pre_delete}`: executes _before_ a session is deleted
229+
- `{post_delete}`: executes _after_ a session is deleted
230+
- `{no_restore}`: executes _at_ `VimEnter` _when_ no session is restored
229231

230232
Hooks are configured by setting
231233

@@ -290,7 +292,7 @@ use this to only create sessions for git projects:
290292

291293
## Argument Handling
292294

293-
By default, when `nvim` is run with a single directory argument, auto-session will try to restore the session for that directory. If `nvim` is run with multiple directories or any file arguments, auto-session won't try to restore a session and won't auto-save a session on exit (if enabled). Those behaviors can be changed with these config parameters:
295+
By default, when `nvim` is run with a single directory argument, AutoSession will try to restore the session for that directory. If `nvim` is run with multiple directories or any file arguments, AutoSession won't try to restore a session and won't auto-save a session on exit (if enabled). Those behaviors can be changed with these config parameters:
294296

295297
```lua
296298
args_allow_single_directory = true, -- boolean Follow normal sesion save/load logic if launched with a single directory as the only argument
@@ -303,7 +305,7 @@ For `args_allow_single_directory`, if you frequently use `netrw` to look at dire
303305
bypass_session_save_file_types = { 'netrw' }
304306
```
305307

306-
If `args_allow_files_auto_save` is true, auto-session won't load any session when `nvim` is launched with file argument(s) but it will save on exit. What's probably more useful is to set `args_allow_files_auto_save` to a function that returns true if a session should be saved and false otherwise. auto-session will call that function on auto save when run with arguments. Here's one example config where it will save the session if at least two buffers are open after being launched with arguments:
308+
If `args_allow_files_auto_save` is true, AutoSession won't load any session when `nvim` is launched with file argument(s) but it will save on exit. What's probably more useful is to set `args_allow_files_auto_save` to a function that returns true if a session should be saved and false otherwise. AutoSession will call that function on auto save when run with arguments. Here's one example config where it will save the session if at least two buffers are open after being launched with arguments:
307309

308310
```lua
309311
return {
@@ -379,7 +381,7 @@ For troubleshooting refer to the [wiki page](https://github.com/rmagatti/auto-se
379381

380382
## 🔭 Session Lens
381383

382-
Session Lens has been merged into Auto Session so now you can see, load, and delete your sessions using Telescope! It's enabled by
384+
Session Lens has been merged into AutoSession so now you can see, load, and delete your sessions using Telescope! It's enabled by
383385
default if you have Telescope, but here's the Lazy config that shows the configuration options:
384386

385387
```lua
@@ -419,20 +421,21 @@ vim.keymap.set("n", "<C-s>", require("auto-session.session-lens").search_session
419421
You can also use `:Telescope session-lens` to launch the session picker.
420422

421423
The following shortcuts are available when the session-lens picker is open
422-
* `<c-s>` restores the previously opened session. This can give you a nice flow if you're constantly switching between two projects.
423-
* `<c-d>` will delete the currently highlighted session. This makes it easy to keep the session list clean.
424+
425+
- `<c-s>` restores the previously opened session. This can give you a nice flow if you're constantly switching between two projects.
426+
- `<c-d>` will delete the currently highlighted session. This makes it easy to keep the session list clean.
424427

425428
NOTE: If you previously installed `rmagatti/session-lens`, you should remove it from your config as it is no longer necessary.
426429

427-
Auto Session provides its own `:Autosession search` and `:Autosession delete` commands, but session-lens is a more complete version of those commands that is specifically built to be used with `telescope.nvim`. These commands make use of `vim.ui.select` which can itself be implemented by other plugins other than telescope.
430+
AutoSession provides its own `:Autosession search` and `:Autosession delete` commands, but session-lens is a more complete version of those commands that is specifically built to be used with `telescope.nvim`. These commands make use of `vim.ui.select` which can itself be implemented by other plugins other than telescope.
428431

429432
### Preview
430433

431434
<img src="https://github.com/rmagatti/readme-assets/blob/main/session-lens.gif" width=800 />
432435

433436
### Statusline
434437

435-
One can show the current session name in the statusline by using an auto-session helper function.
438+
One can show the current session name in the statusline by using an AutoSession helper function.
436439

437440
Lualine example config and how it looks
438441

@@ -454,5 +457,5 @@ Neovim > 0.7
454457
Tested with:
455458

456459
```
457-
NVIM v0.7.0
460+
NVIM v0.7.0 - NVIM 0.10.0
458461
```

0 commit comments

Comments
 (0)