109 lines
2.4 KiB
Rust
109 lines
2.4 KiB
Rust
use std::str;
|
|
|
|
mod utils;
|
|
use utils::{utils::*, client::ClientTest};
|
|
|
|
fn line_should_contains(lines: &Vec<String>, nb: usize, str: &str) {
|
|
|
|
if lines[nb].find(str).is_none()
|
|
{
|
|
eprintln!("'{}' not found in '{}'", str, lines[nb]);
|
|
dbg!(lines);
|
|
}
|
|
|
|
assert!(lines[nb].find(str).is_some());
|
|
}
|
|
|
|
fn lines_should_not_contains(lines: Vec<String>, str: &str) {
|
|
|
|
for line in lines {
|
|
if line.find("Changes not staged for push").is_some() {
|
|
return;
|
|
}
|
|
|
|
if line.find(str).is_some() {
|
|
eprintln!("'{}' found in '{}'", str, line);
|
|
}
|
|
assert!(line.find(str).is_none());
|
|
}
|
|
}
|
|
|
|
fn collect_status_lines(client: &mut ClientTest) -> Vec<String> {
|
|
let out = client.run_cmd("status");
|
|
|
|
str::from_utf8(&out.stdout)
|
|
.unwrap()
|
|
.split("\n")
|
|
.map(|s| s.to_owned())
|
|
.collect()
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod add_tests {
|
|
use super::*;
|
|
|
|
#[test]
|
|
fn simple_add() {
|
|
let id = get_random_test_id();
|
|
let mut client = ClientTest::new(id).init();
|
|
|
|
let _ = client.add_file("file1", "foo");
|
|
client.run_cmd_ok("add file1");
|
|
|
|
let lines = collect_status_lines(&mut client);
|
|
|
|
// test
|
|
line_should_contains(&lines, 2, "file1");
|
|
|
|
client.clean();
|
|
}
|
|
|
|
#[test]
|
|
fn add_config_file() {
|
|
let id = get_random_test_id();
|
|
let mut client = ClientTest::new(id).init();
|
|
|
|
let _ = client.add_file("file1", "foo");
|
|
client.run_cmd_ok("add .nextsync -f");
|
|
|
|
let lines = collect_status_lines(&mut client);
|
|
|
|
// test
|
|
lines_should_not_contains(lines, ".nextsync");
|
|
|
|
client.clean();
|
|
}
|
|
|
|
#[test]
|
|
fn add_dir_implicit() {
|
|
let id = get_random_test_id();
|
|
let mut client = ClientTest::new(id).init();
|
|
|
|
let _ = client.add_dir("dir");
|
|
let _ = client.add_file("dir/file1", "foo");
|
|
|
|
// adding the file should add the dir
|
|
client.run_cmd_ok("add dir/file1");
|
|
|
|
let lines = collect_status_lines(&mut client);
|
|
|
|
// tests
|
|
line_should_contains(&lines, 2, "dir");
|
|
line_should_contains(&lines, 3, "dir/file1");
|
|
|
|
client.clean();
|
|
}
|
|
|
|
#[test]
|
|
fn add_no_change() {
|
|
assert!(false);
|
|
// add a file push it and add it again
|
|
// let id = get_random_test_id();
|
|
// let mut client = ClientTest::new(id).init();
|
|
//
|
|
//
|
|
// client.clean();
|
|
}
|
|
|
|
}
|