Skip to content

Commit 1b5ede3

Browse files
authored
ci: fix not downloading plenary and make easier for users (#30)
1 parent 8836ed5 commit 1b5ede3

6 files changed

Lines changed: 43 additions & 18 deletions

File tree

.github/workflows/build-and-test.yml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ jobs:
1414
check:
1515
name: Build and Check
1616
runs-on: ubuntu-latest
17+
timeout-minutes: 10
18+
1719
steps:
1820
- uses: actions/checkout@v4
1921
- uses: actions/cache@v3
@@ -44,11 +46,11 @@ jobs:
4446
override: true
4547
components: rustfmt, clippy
4648

47-
- name: Run cargo clippy (workspace)
48-
uses: actions-rs/cargo@v1
49-
with:
50-
command: clippy
51-
args: --workspace
49+
# - name: Run cargo clippy (workspace)
50+
# uses: actions-rs/cargo@v1
51+
# with:
52+
# command: clippy
53+
# args: --workspace
5254

5355
- name: Run cargo build (workspace)
5456
uses: actions-rs/cargo@v1

crates/vim9-gen/src/lib.rs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1768,13 +1768,38 @@ pub fn generate(contents: &str, opts: ParserOpts) -> Result<Output, (Output, Str
17681768

17691769
#[cfg(test)]
17701770
mod test {
1771-
use std::{fs::File, io::Write};
1771+
use std::{fs::File, io::Write, process::Command};
17721772

17731773
use pretty_assertions::assert_eq;
17741774

17751775
use super::*;
17761776
use crate::test_harness::{exec_busted, exec_lua};
17771777

1778+
fn ensure_plenary_downloaded() {
1779+
static DOWNLOADED: std::sync::Once = std::sync::Once::new();
1780+
// Download and install Plenary if needed
1781+
DOWNLOADED.call_once(|| {
1782+
let path = std::env::var("HOME").expect("to have a home var")
1783+
+ "/.local/share/nvim/site/pack/vendor/start/plenary.nvim";
1784+
1785+
if Path::new(&path).exists() {
1786+
return;
1787+
}
1788+
1789+
// Download git repo
1790+
let status = Command::new("git")
1791+
.arg("clone")
1792+
.arg("--depth")
1793+
.arg("1")
1794+
.arg("https://github.com/nvim-lua/plenary.nvim")
1795+
.arg(path)
1796+
.status()
1797+
.expect("failed to execute git command");
1798+
1799+
assert!(status.success());
1800+
});
1801+
}
1802+
17781803
macro_rules! snapshot {
17791804
($name:tt, $path:tt) => {
17801805
#[test]
@@ -1802,6 +1827,8 @@ mod test {
18021827
($name:tt, $path:tt) => {
18031828
#[test]
18041829
fn $name() {
1830+
ensure_plenary_downloaded();
1831+
18051832
let vim_contents = include_str!($path);
18061833
let lua_contents = generate(
18071834
vim_contents,

crates/vim9-gen/src/test_harness.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ pub fn exec_lua(preamble: &str) -> Result<HashMap<String, Value>> {
9797
drop(child_stdin);
9898

9999
// Wait til output has completed.
100-
let _ = child.wait_with_output()?;
100+
child.wait_with_output()?;
101101

102102
// TODO: For some reason we get a weird 256 wait status on my machine...
103103
// assert!(

crates/vim9-gen/testdata/busted/defer.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,5 +55,5 @@ def Test_defer()
5555
assert_equal([3, 2, 1], x)
5656

5757
var y = RangeDefer()
58-
assert_equal([3, 2, 1], x)
58+
assert_equal([2, 1, 0], y)
5959
enddef

crates/vim9-gen/testdata/output/busted_defer.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ describe('filename', function()
100100
vim9.fn.assert_equal({ 3, 2, 1 }, x)
101101

102102
local y = RangeDefer()
103-
vim9.fn.assert_equal({ 3, 2, 1 }, x)
103+
vim9.fn.assert_equal({ 2, 1, 0 }, y)
104104

105105
-- Assert that errors is still empty
106106
assert.are.same({}, vim.v.errors)

scripts/init.lua

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
1-
-- Add target dir, if not exists
2-
vim.fn.mkdir('target', 'p')
1+
local plenary_path = vim.fn.expand('~/.local/share/nvim/site/pack/vendor/start/plenary.nvim') --[[@as string]]
32

4-
if not vim.uv.fs_stat('target/plenary.nvim') then
5-
vim
6-
.system({ 'git', 'clone', 'https://github.com/nvim-lua/plenary.nvim', 'target/plenary.nvim' })
7-
:wait()
8-
end
9-
10-
vim.opt.rtp:append({ '.', './target/plenary.nvim' })
3+
vim.opt.rtp:append({
4+
'.',
5+
plenary_path,
6+
})
117

128
vim.cmd([[runtime! plugin/plenary.vim]])

0 commit comments

Comments
 (0)