Skip to content

Commit

Permalink
test run the cli
Browse files Browse the repository at this point in the history
  • Loading branch information
tompscanlan committed Aug 28, 2023
1 parent 6fa428f commit ebce728
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
45 changes: 44 additions & 1 deletion kondo/tests/test.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
mod common;
use std::process::Command;
use std::{io::Write, process::Command};

use kondo;

Expand All @@ -23,3 +23,46 @@ fn test_version() {
.expect("failed to execute process");
assert!(output.status.success());
}

#[test]
fn test_can_run_cargo() {
let tmpdir = create_fake_python_project("testing".to_string());
let bin = common::bin();

let output = Command::new(bin)
.arg(tmpdir.path())
.arg("--all")
.output()
.expect("failed to execute process");
assert!(output.status.success());
// clean up
tmpdir.close().unwrap();
}

// Given a name, create a new simulated python project in a safe to delete directry
fn create_fake_python_project(name: String) -> tempfile::TempDir {
// Make a new project in a temporary directory
let tmp_dir = tempfile::tempdir().unwrap();

// make a new root in the tmp dir
let project_dir = tmp_dir.path().join(&name);
std::fs::create_dir(&project_dir).unwrap();

// Must have a directory to hold the project.
let cache_dir = project_dir.join("__pycache__");
std::fs::create_dir(&cache_dir).unwrap();

// Must have data in the cache to delete
let mut data_file = std::fs::File::create(cache_dir.join("cache.data")).unwrap();
data_file.write_all(b"#oodles of cache')\n").unwrap();
let mut data_file_b = std::fs::File::create(cache_dir.join("other.cache")).unwrap();
data_file_b.write_all(b"#oodles of cache')\n").unwrap();

// and a file of type .py to signal we're a python project
let mut python_file = std::fs::File::create(project_dir.join("main.py")).unwrap();
python_file
.write_all(b"#!/bin/python\n\nprint('Hello, world!')\n")
.unwrap();

return tmp_dir;
}
Empty file.
3 changes: 3 additions & 0 deletions x/test_data/test_discover/python-project-b/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/python

print('Hello, world!')

0 comments on commit ebce728

Please sign in to comment.