From d3511721de31701a70d7f453b4927b6b23b28d13 Mon Sep 17 00:00:00 2001 From: Gabriel Kaszewski Date: Sun, 24 Aug 2025 13:42:59 +0200 Subject: [PATCH] feat: add new dependencies and integration tests for markdown and text formats --- Cargo.lock | 49 +++++++++++++++++++++++ Cargo.toml | 1 + tests/fixtures/example.rs | 4 ++ tests/fixtures/example.txt | 1 + tests/integration_tests.rs | 79 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 134 insertions(+) create mode 100644 tests/fixtures/example.rs create mode 100644 tests/fixtures/example.txt create mode 100644 tests/integration_tests.rs diff --git a/Cargo.lock b/Cargo.lock index c97bc8e..a12b06d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -190,6 +190,7 @@ dependencies = [ "clap", "git2", "ignore", + "tempfile", "tracing", "tracing-subscriber", "walkdir", @@ -243,6 +244,22 @@ dependencies = [ "syn", ] +[[package]] +name = "errno" +version = "0.3.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "778e2ac28f6c47af28e4907f13ffd1e1ddbd400980a9abd7c8df189bf578a5ad" +dependencies = [ + "libc", + "windows-sys", +] + +[[package]] +name = "fastrand" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be" + [[package]] name = "form_urlencoded" version = "1.2.2" @@ -523,6 +540,12 @@ dependencies = [ "vcpkg", ] +[[package]] +name = "linux-raw-sys" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd945864f07fe9f5371a27ad7b52a172b4b499999f1d97574c9fa68373937e12" + [[package]] name = "litemap" version = "0.8.0" @@ -664,6 +687,19 @@ version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" +[[package]] +name = "rustix" +version = "1.0.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "11181fbabf243db407ef8df94a6ce0b2f9a733bd8be4ad02b4eda9602296cac8" +dependencies = [ + "bitflags", + "errno", + "libc", + "linux-raw-sys", + "windows-sys", +] + [[package]] name = "rustversion" version = "1.0.22" @@ -754,6 +790,19 @@ dependencies = [ "syn", ] +[[package]] +name = "tempfile" +version = "3.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "15b61f8f20e3a6f7e0649d825294eaf317edce30f82cf6026e7e4cb9222a7d1e" +dependencies = [ + "fastrand", + "getrandom", + "once_cell", + "rustix", + "windows-sys", +] + [[package]] name = "thread_local" version = "1.1.9" diff --git a/Cargo.toml b/Cargo.toml index 1d617d5..3e18da0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,6 +9,7 @@ chrono = "0.4.41" clap = { version = "4.5.45", features = ["derive"] } git2 = "0.20.2" ignore = "0.4.23" +tempfile = "3.21.0" tracing = "0.1.41" tracing-subscriber = "0.3.19" walkdir = "2.5.0" diff --git a/tests/fixtures/example.rs b/tests/fixtures/example.rs new file mode 100644 index 0000000..85c026d --- /dev/null +++ b/tests/fixtures/example.rs @@ -0,0 +1,4 @@ +// This is a sample Rust file for testing purposes. +fn main() { + println!("Hello, world!"); +} diff --git a/tests/fixtures/example.txt b/tests/fixtures/example.txt new file mode 100644 index 0000000..adc37cd --- /dev/null +++ b/tests/fixtures/example.txt @@ -0,0 +1 @@ +Example text file content diff --git a/tests/integration_tests.rs b/tests/integration_tests.rs new file mode 100644 index 0000000..89859c4 --- /dev/null +++ b/tests/integration_tests.rs @@ -0,0 +1,79 @@ +use codebase_to_prompt::{Config, Format, run}; +use std::fs; +use std::path::PathBuf; + +#[test] +fn test_run_with_markdown_format() { + let temp_dir = tempfile::tempdir().unwrap(); + let output_file = temp_dir.path().join("output.md"); + + let config = Config { + directory: PathBuf::from("tests/fixtures"), + output: Some(output_file.clone()), + include: vec!["rs".to_string()], + exclude: vec![], + format: Format::Markdown, + append_date: false, + append_git_hash: false, + line_numbers: false, + ignore_hidden: true, + respect_gitignore: true, + }; + + let result = run(config); + assert!(result.is_ok()); + + let output_content = fs::read_to_string(output_file).unwrap(); + assert!(output_content.contains("### `example.rs`")); +} + +#[test] +fn test_run_with_text_format() { + let temp_dir = tempfile::tempdir().unwrap(); + let output_file = temp_dir.path().join("output.txt"); + + let config = Config { + directory: PathBuf::from("tests/fixtures"), + output: Some(output_file.clone()), + include: vec!["txt".to_string()], + exclude: vec![], + format: Format::Text, + append_date: false, + append_git_hash: false, + line_numbers: true, + ignore_hidden: true, + respect_gitignore: true, + }; + + let result = run(config); + assert!(result.is_ok()); + + let output_content = fs::read_to_string(output_file).unwrap(); + assert!(output_content.contains("1 | Example text file content")); +} + +#[test] +fn test_run_with_git_hash_append() { + let temp_dir = tempfile::tempdir().unwrap(); + let output_file = temp_dir.path().join("output.txt"); + + let config = Config { + directory: PathBuf::from("tests/fixtures"), + output: Some(output_file.clone()), + include: vec!["txt".to_string()], + exclude: vec![], + format: Format::Text, + append_date: false, + append_git_hash: true, + line_numbers: false, + ignore_hidden: true, + respect_gitignore: true, + }; + + let result = run(config); + assert!(result.is_ok()); + + let output_file_name = output_file.file_name().unwrap().to_str().unwrap(); + assert!(output_file_name.contains("output")); + assert!(output_file_name.len() > "output".len()); +}