@@ -39,8 +39,14 @@ pub fn git() -> &'static str {
3939
4040pub fn long ( ) -> String {
4141 let xdr = stellar_xdr:: VERSION ;
42+ let git_rev = if git ( ) . is_empty ( ) {
43+ String :: new ( )
44+ } else {
45+ format ! ( " ({})" , git( ) )
46+ } ;
47+
4248 [
43- format ! ( "{} ({}) " , pkg( ) , git ( ) ) ,
49+ format ! ( "{}{git_rev} " , pkg( ) ) ,
4450 format ! (
4551 "stellar-xdr {} ({})
4652xdr curr ({})" ,
@@ -55,3 +61,29 @@ pub fn one_line() -> String {
5561 let git = git ( ) ;
5662 format ! ( "{pkg}#{git}" )
5763}
64+
65+ #[ test]
66+ fn test_long_without_git_rev ( ) {
67+ let expected = format ! (
68+ "{}\n stellar-xdr {} ({})\n xdr curr ({})" ,
69+ pkg( ) ,
70+ stellar_xdr:: VERSION . pkg,
71+ stellar_xdr:: VERSION . rev,
72+ stellar_xdr:: VERSION . xdr_curr,
73+ ) ;
74+ assert_eq ! ( long( ) , expected) ;
75+ }
76+
77+ #[ test]
78+ fn test_long_with_git_rev ( ) {
79+ std:: env:: set_var ( "GIT_REVISION" , "REF" ) ;
80+ let expected = format ! (
81+ "{} (REF)\n stellar-xdr {} ({})\n xdr curr ({})" ,
82+ pkg( ) ,
83+ stellar_xdr:: VERSION . pkg,
84+ stellar_xdr:: VERSION . rev,
85+ stellar_xdr:: VERSION . xdr_curr,
86+ ) ;
87+ assert_eq ! ( long( ) , expected) ;
88+ std:: env:: remove_var ( "GIT_REVISION" ) ;
89+ }
0 commit comments