MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / test_empty_file

Function test_empty_file

atomic-repository/tests/state_based_diff_test.rs:369–409  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

367/// This test verifies that attempting to record an empty file fails as expected.
368#[test]
369fn test_empty_file() {
370 let (repo, _temp, repo_path) = create_test_repo();
371
372 // Create an empty file and add it to tracking
373 let file_path = repo_path.join("empty.txt");
374 fs::write(&file_path, "").expect("Failed to write empty file");
375 repo.add("empty.txt", Default::default())
376 .expect("Failed to add empty file");
377
378 // With the default options (record_empty_files: true), recording an
379 // empty file should succeed — the change captures the file's existence
380 // even though it has no content bytes.
381 let header = ChangeHeader::builder()
382 .message("Add empty file")
383 .author(Author::new("Test", Some("test@example.com")))
384 .build();
385
386 let result = repo.record(header, RecordOptions::default());
387 assert!(
388 result.is_ok(),
389 "Recording empty file should succeed with record_empty_files=true (default)"
390 );
391
392 // With record_empty_files explicitly disabled, recording an empty file
393 // should fail with NothingToRecord because there are no content changes.
394 let file_path2 = repo_path.join("empty2.txt");
395 fs::write(&file_path2, "").expect("Failed to write empty file");
396 repo.add("empty2.txt", Default::default())
397 .expect("Failed to add empty file");
398
399 let header2 = ChangeHeader::builder()
400 .message("Add another empty file")
401 .author(Author::new("Test", Some("test@example.com")))
402 .build();
403
404 let result2 = repo.record(header2, RecordOptions::default().record_empty_files(false));
405 assert!(
406 result2.is_err(),
407 "Recording empty file should fail with record_empty_files=false"
408 );
409}
410
411#[test]
412fn test_binary_content() {

Callers

nothing calls this directly

Calls 8

writeFunction · 0.85
authorMethod · 0.80
create_test_repoFunction · 0.70
addMethod · 0.45
buildMethod · 0.45
messageMethod · 0.45
recordMethod · 0.45
record_empty_filesMethod · 0.45

Tested by

no test coverage detected