Skip to content

Commit aa60fdf

Browse files
committed
base setup for index testing (#293)
It should be easy enough to learn from git tests to generate whichever kind of index we need.
1 parent ddb1bf4 commit aa60fdf

File tree

7 files changed

+89
-3
lines changed

7 files changed

+89
-3
lines changed

Cargo.lock

+5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

git-index/Cargo.toml

+6
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,9 @@ doctest = false
1313
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1414

1515
[dependencies]
16+
git-hash = { version ="^0.8.0", path = "../git-hash" }
17+
18+
quick-error = "2.0.0"
19+
20+
[dev-dependencies]
21+
git-testtools = { path = "../tests/tools"}

git-index/src/lib.rs

+48-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,48 @@
1-
#![forbid(unsafe_code, rust_2018_idioms)]
1+
#![forbid(unsafe_code)]
2+
#![deny(rust_2018_idioms)]
3+
#![allow(missing_docs)]
4+
5+
use std::path::PathBuf;
6+
7+
pub mod file {
8+
pub mod init {
9+
#![allow(unused)]
10+
use crate::File;
11+
use std::path::Path;
12+
13+
impl File {
14+
pub fn at(path: impl AsRef<Path>, object_hash: git_hash::Kind) -> std::io::Result<Self> {
15+
todo!("read file")
16+
}
17+
}
18+
}
19+
}
20+
pub mod init {
21+
use crate::State;
22+
23+
impl State {
24+
/// Returns an empty state.
25+
/// TODO: figure out if it needs to know some configuration
26+
pub fn new() -> Self {
27+
State
28+
}
29+
}
30+
31+
impl Default for State {
32+
fn default() -> Self {
33+
State::new()
34+
}
35+
}
36+
}
37+
38+
/// An index file whose state was read from a file on disk.
39+
pub struct File {
40+
pub state: State,
41+
pub path: PathBuf,
42+
}
43+
44+
/// An in-memory cache of a fully parsed git index file.
45+
///
46+
/// As opposed to a snapshot, it's meant to be altered and eventually be written back to disk or converted into a tree.
47+
/// We treat index and its state synonymous.
48+
pub struct State;

git-index/tests/file/mod.rs

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
mod init {
2+
3+
#[test]
4+
#[ignore]
5+
fn v2() {
6+
let _file = git_index::File::at(crate::index_fixture_path("v2"), git_hash::Kind::Sha1).unwrap();
7+
}
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/bash
2+
set -eu -o pipefail
3+
4+
GIT_INDEX_VERSION=2 git init -q
5+
git config commit.gpgsign false
6+
7+
touch a
8+
git add a
9+
git commit -m "empty"

git-index/tests/index.rs

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
use std::path::{Path, PathBuf};
2+
3+
mod file;
4+
5+
pub fn index_fixture_path(name: &str) -> PathBuf {
6+
let dir = git_testtools::scripted_fixture_repo_read_only(Path::new("make_index").join(name).with_extension("sh"))
7+
.expect("script works");
8+
dir.join(".git").join("index")
9+
}

tests/tools/src/lib.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ pub fn hex_to_id(hex: &str) -> git_hash::ObjectId {
1919
pub fn fixture_path(path: impl AsRef<Path>) -> PathBuf {
2020
PathBuf::from("tests").join("fixtures").join(path.as_ref())
2121
}
22-
pub fn scripted_fixture_repo_read_only(script_name: &str) -> std::result::Result<PathBuf, Box<dyn std::error::Error>> {
22+
pub fn scripted_fixture_repo_read_only(
23+
script_name: impl AsRef<Path>,
24+
) -> std::result::Result<PathBuf, Box<dyn std::error::Error>> {
2325
scripted_fixture_repo_read_only_with_args(script_name, None)
2426
}
2527

@@ -59,7 +61,7 @@ pub fn copy_recursively_into_existing_dir(src_dir: impl AsRef<Path>, dst_dir: im
5961

6062
/// Returns the directory at which the data is present
6163
pub fn scripted_fixture_repo_read_only_with_args(
62-
script_name: &str,
64+
script_name: impl AsRef<Path>,
6365
args: impl IntoIterator<Item = &'static str>,
6466
) -> std::result::Result<PathBuf, Box<dyn std::error::Error>> {
6567
let script_path = fixture_path(script_name);

0 commit comments

Comments
 (0)