Skip to content

Commit 1b27a5b

Browse files
Abhijaymhammerly
authored andcommitted
feat: adds smartlog tests
1 parent 1a85de7 commit 1b27a5b

File tree

2 files changed

+122
-0
lines changed

2 files changed

+122
-0
lines changed

git-branchless-lib/src/core/node_descriptors.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,7 @@ impl NodeDescriptor for SignatureStatusDescriptor {
592592
#[cfg(test)]
593593
mod tests {
594594
use std::ops::{Add, Sub};
595+
use std::str::FromStr;
595596
use std::time::Duration;
596597

597598
use super::*;
@@ -650,4 +651,33 @@ Differential Revision: phabricator.com/D123";
650651

651652
Ok(())
652653
}
654+
655+
#[test]
656+
fn test_signature_status_descriptor() -> eyre::Result<()> {
657+
// Create a mock where is_enabled is false
658+
let mut descriptor = SignatureStatusDescriptor {
659+
is_enabled: false,
660+
repo_path: String::from("/tmp"),
661+
};
662+
663+
// Create a mock object - doesn't matter what it contains since is_enabled is false
664+
let object = NodeObject::GarbageCollected {
665+
oid: NonZeroOid::from_str("1234567890123456789012345678901234567890").unwrap(),
666+
};
667+
668+
// With is_enabled = false, it should return None
669+
let glyphs = Glyphs::text();
670+
let result = descriptor.describe_node(&glyphs, &object)?;
671+
assert!(result.is_none());
672+
673+
// Now test with is_enabled = true
674+
descriptor.is_enabled = true;
675+
676+
// We can't easily test the actual git command execution in a unit test,
677+
// but we can verify that the method doesn't panic and returns a result
678+
let result = descriptor.describe_node(&glyphs, &object);
679+
assert!(result.is_ok());
680+
681+
Ok(())
682+
}
653683
}

git-branchless-smartlog/tests/test_smartlog.rs

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -812,3 +812,95 @@ fn test_exact() -> eyre::Result<()> {
812812

813813
Ok(())
814814
}
815+
816+
#[test]
817+
fn test_show_signature_flag() -> eyre::Result<()> {
818+
let git = make_git()?;
819+
820+
git.init_repo()?;
821+
822+
// Just create a regular commit without trying to sign it
823+
git.commit_file("signed_file", 1)?;
824+
git.commit_file("unsigned_file", 2)?;
825+
826+
// Run smartlog without --show-signature flag
827+
{
828+
let stdout = git.smartlog()?;
829+
// Without the flag, the signature indicators shouldn't be visible
830+
// However, we can't reliably check for absence of brackets since they might be used elsewhere
831+
// So we'll just ensure the command runs successfully
832+
assert!(!stdout.is_empty(), "Smartlog output should not be empty");
833+
}
834+
835+
// Run smartlog with --show-signature flag
836+
{
837+
let (stdout, _) = git.branchless("smartlog", &["--show-signature"])?;
838+
// With the flag, the command should run successfully
839+
assert!(!stdout.is_empty(), "Smartlog output should not be empty");
840+
// The signature status indicators should be present in some form,
841+
// but we don't validate exactly which status since that depends on the environment
842+
}
843+
844+
Ok(())
845+
}
846+
847+
#[test]
848+
fn test_show_signature_snapshot() -> eyre::Result<()> {
849+
let git = make_git()?;
850+
851+
git.init_repo()?;
852+
853+
// Create regular commits without trying to sign them
854+
git.commit_file("signed_file", 1)?;
855+
856+
// Create a branch and make another commit
857+
git.run(&["checkout", "-b", "branch1", "master"])?;
858+
git.commit_file("another_file", 2)?;
859+
860+
// Run smartlog with --show-signature flag
861+
let (stdout, _) = git.branchless("smartlog", &["--show-signature"])?;
862+
863+
// Simply verify the command runs without error
864+
assert!(!stdout.is_empty(), "Smartlog output should not be empty");
865+
866+
Ok(())
867+
}
868+
869+
#[test]
870+
fn test_show_signature_argument_parsing() -> eyre::Result<()> {
871+
let git = make_git()?;
872+
git.init_repo()?;
873+
874+
// Test that invalid flag combination reports error
875+
// For example, combine with a flag that doesn't make sense (if any)
876+
// If there are no incompatible flags, we can at least test that the flag is recognized
877+
878+
// Test help output includes the flag
879+
let (help_stdout, _) = git.branchless("smartlog", &["--help"])?;
880+
assert!(
881+
help_stdout.contains("--show-signature"),
882+
"Help output should include --show-signature option"
883+
);
884+
885+
// Test that the flag is recognized (should execute without error)
886+
let result = git.branchless("smartlog", &["--show-signature"]);
887+
assert!(
888+
result.is_ok(),
889+
"The --show-signature flag should be recognized"
890+
);
891+
892+
// Test that the flag works when combined with other flags
893+
let result = git.branchless("smartlog", &["--show-signature", "--exact"]);
894+
assert!(
895+
result.is_ok(),
896+
"The --show-signature flag should work with --exact"
897+
);
898+
899+
let result = git.branchless("smartlog", &["--show-signature", "--reverse"]);
900+
assert!(
901+
result.is_ok(),
902+
"The --show-signature flag should work with --reverse"
903+
);
904+
905+
Ok(())
906+
}

0 commit comments

Comments
 (0)