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

Function test_empty_file

atomic-repository/tests/it/state_based_diff_test.rs:374–418  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 9

authorMethod · 0.80
create_test_repoFunction · 0.70
writeFunction · 0.70
working_copyFunction · 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