Skip to content

Commit

Permalink
Merge pull request #58 from NoahTheDuke/ftdetect-tests
Browse files Browse the repository at this point in the history
Add ftdetect tests
  • Loading branch information
laniakea64 authored Nov 16, 2023
2 parents 8fa4691 + 0841864 commit fda7259
Show file tree
Hide file tree
Showing 8 changed files with 287 additions and 29 deletions.
28 changes: 24 additions & 4 deletions tests/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 13 additions & 5 deletions tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,19 @@ name = "tests"
version = "0.0.0"
authors = ["Casey Rodarmor <[email protected]>", "Noah Bogart <[email protected]"]
edition = "2021"
default-run = "tests"

[[bin]]
name = "test-ftdetect"
path = "src/test-ftdetect.rs"

[dependencies]
regex = "~1.9"
scraper = "0.17.1"
clap = { version = "4", features = ["derive"] }
tempfile = "3.8.0"
ctrlc = "3.4.1"
regex = "~1.9"
scraper = "0.17.1"
clap = { version = "4", features = ["derive"] }
tempfile = "3.8.0"
ctrlc = "3.4.1"
wait-timeout = "0.2.0"
serde = { version = "1.0.190", features = ["derive"] }
serde_json = "1.0.108"
rand = "0.8.5"
3 changes: 3 additions & 0 deletions tests/batch_ftdetect_res.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
bufdo redir >> $OUTPUT | echo @% | set ft? | redir END

qa
24 changes: 24 additions & 0 deletions tests/cases/ftdetect.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[
{
"filename": "justfile"
},
{
"filename": "Justfile"
},
{
"filename": "*.just"
},
{
"content": "#!/usr/bin/env -S just -f\n"
},
{
"content": "#!/usr/bin/env just -f\n"
},
{
"content": "#!/usr/local/bin/just -f\n"
},
{
"content": "",
"not_justfile": true
}
]
4 changes: 4 additions & 0 deletions tests/justfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ watch FILTER='':
--exec "run {{FILTER}}" \
--watch ..

# run ftdetect tests
ftdetect:
cargo run --bin=test-ftdetect

# install development dependencies
deps:
cargo install cargo-watch
Expand Down
32 changes: 32 additions & 0 deletions tests/src/common.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
use std::{
fs,
os::unix::fs as ufs,
sync::{
atomic::{AtomicBool, Ordering::Relaxed},
Arc,
},
};

pub fn clean_dotvim_symlink() {
if fs::metadata(".vim").is_ok() {
fs::remove_file(".vim").unwrap();
}
}

pub fn create_dotvim_symlink() {
clean_dotvim_symlink();
ufs::symlink("../", ".vim").unwrap();
}

pub fn setup_ctrlc_handler() -> Arc<AtomicBool> {
let interrupted = Arc::new(AtomicBool::new(false));
let _interrupted = Arc::clone(&interrupted);

ctrlc::set_handler(move || {
_interrupted.store(true, Relaxed);
eprintln!("Received Ctrl+C");
})
.unwrap();

interrupted
}
27 changes: 7 additions & 20 deletions tests/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
mod common;
use crate::common::*;

use clap::Parser;
use regex::Regex;
use scraper::{Html, Selector};
Expand All @@ -6,13 +9,9 @@ use std::{
ffi::OsStr,
fs,
io::{self, ErrorKind},
os::unix::fs as ufs,
path::Path,
process::{Command, Stdio},
sync::{
atomic::{AtomicBool, Ordering::Relaxed},
Arc,
},
sync::atomic::Ordering::Relaxed,
time::Duration,
};
use wait_timeout::ChildExt;
Expand All @@ -26,23 +25,13 @@ struct Arguments {
fn _main() -> io::Result<()> {
let arguments = Arguments::parse();

let interrupted = Arc::new(AtomicBool::new(false));
let _interrupted = Arc::clone(&interrupted);

ctrlc::set_handler(move || {
_interrupted.store(true, Relaxed);
eprintln!("Received Ctrl+C");
})
.unwrap();
let interrupted = setup_ctrlc_handler();

let tempdir = tempfile::tempdir().unwrap();

let case_dir = Path::new("cases");

if fs::metadata(".vim").is_ok() {
fs::remove_file(".vim").unwrap();
}
ufs::symlink("../", ".vim").unwrap();
create_dotvim_symlink();

let mut cases = 0;
let mut passed = 0;
Expand Down Expand Up @@ -177,9 +166,7 @@ fn main() -> io::Result<()> {
let real_main = _main();

// cleanup
if fs::metadata(".vim").is_ok() {
fs::remove_file(".vim").unwrap();
}
clean_dotvim_symlink();

real_main
}
Loading

0 comments on commit fda7259

Please sign in to comment.