Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ jobs:
check:
name: Build and Check
runs-on: ubuntu-latest
timeout-minutes: 10

steps:
- uses: actions/checkout@v4
- uses: actions/cache@v3
Expand Down Expand Up @@ -44,11 +46,11 @@ jobs:
override: true
components: rustfmt, clippy

- name: Run cargo clippy (workspace)
uses: actions-rs/cargo@v1
with:
command: clippy
args: --workspace
# - name: Run cargo clippy (workspace)
# uses: actions-rs/cargo@v1
# with:
# command: clippy
# args: --workspace

- name: Run cargo build (workspace)
uses: actions-rs/cargo@v1
Expand Down
29 changes: 28 additions & 1 deletion crates/vim9-gen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1768,13 +1768,38 @@ pub fn generate(contents: &str, opts: ParserOpts) -> Result<Output, (Output, Str

#[cfg(test)]
mod test {
use std::{fs::File, io::Write};
use std::{fs::File, io::Write, process::Command};

use pretty_assertions::assert_eq;

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

fn ensure_plenary_downloaded() {
static DOWNLOADED: std::sync::Once = std::sync::Once::new();
// Download and install Plenary if needed
DOWNLOADED.call_once(|| {
let path = std::env::var("HOME").expect("to have a home var")
+ "/.local/share/nvim/site/pack/vendor/start/plenary.nvim";

if Path::new(&path).exists() {
return;
}

// Download git repo
let status = Command::new("git")
.arg("clone")
.arg("--depth")
.arg("1")
.arg("https://github.com/nvim-lua/plenary.nvim")
.arg(path)
.status()
.expect("failed to execute git command");

assert!(status.success());
});
}

macro_rules! snapshot {
($name:tt, $path:tt) => {
#[test]
Expand Down Expand Up @@ -1802,6 +1827,8 @@ mod test {
($name:tt, $path:tt) => {
#[test]
fn $name() {
ensure_plenary_downloaded();

let vim_contents = include_str!($path);
let lua_contents = generate(
vim_contents,
Expand Down
2 changes: 1 addition & 1 deletion crates/vim9-gen/src/test_harness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ pub fn exec_lua(preamble: &str) -> Result<HashMap<String, Value>> {
drop(child_stdin);

// Wait til output has completed.
let _ = child.wait_with_output()?;
child.wait_with_output()?;

// TODO: For some reason we get a weird 256 wait status on my machine...
// assert!(
Expand Down
2 changes: 1 addition & 1 deletion crates/vim9-gen/testdata/busted/defer.vim
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,5 @@ def Test_defer()
assert_equal([3, 2, 1], x)

var y = RangeDefer()
assert_equal([3, 2, 1], x)
assert_equal([2, 1, 0], y)
enddef
2 changes: 1 addition & 1 deletion crates/vim9-gen/testdata/output/busted_defer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ describe('filename', function()
vim9.fn.assert_equal({ 3, 2, 1 }, x)

local y = RangeDefer()
vim9.fn.assert_equal({ 3, 2, 1 }, x)
vim9.fn.assert_equal({ 2, 1, 0 }, y)

-- Assert that errors is still empty
assert.are.same({}, vim.v.errors)
Expand Down
14 changes: 5 additions & 9 deletions scripts/init.lua
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
-- Add target dir, if not exists
vim.fn.mkdir('target', 'p')
local plenary_path = vim.fn.expand('~/.local/share/nvim/site/pack/vendor/start/plenary.nvim') --[[@as string]]

if not vim.uv.fs_stat('target/plenary.nvim') then
vim
.system({ 'git', 'clone', 'https://github.com/nvim-lua/plenary.nvim', 'target/plenary.nvim' })
:wait()
end

vim.opt.rtp:append({ '.', './target/plenary.nvim' })
vim.opt.rtp:append({
'.',
plenary_path,
})

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