Skip to content

Commit 64b8ba8

Browse files
author
hyd-dev
authored
Get rid of git_attr__* symbols (#689)
They are morally private, and it turns out they are unreliable, even just for testing purpose.
1 parent ae256db commit 64b8ba8

File tree

1 file changed

+9
-31
lines changed

1 file changed

+9
-31
lines changed

Diff for: src/attr.rs

+9-31
Original file line numberDiff line numberDiff line change
@@ -87,36 +87,26 @@ impl PartialEq for AttrValue<'_> {
8787
#[cfg(test)]
8888
mod tests {
8989
use super::AttrValue;
90-
use std::ffi::CStr;
91-
use std::os::raw::c_char;
92-
93-
extern "C" {
94-
// libgit2 defines them as mutable, so they are also declared mutable here.
95-
// However, libgit2 never mutates them, thus it's always safe to access them in Rust.
96-
static mut git_attr__true: *const c_char;
97-
static mut git_attr__false: *const c_char;
98-
static mut git_attr__unset: *const c_char;
99-
}
10090

10191
macro_rules! test_attr_value {
10292
($function:ident, $variant:ident) => {
103-
let attr_true = unsafe { CStr::from_ptr(git_attr__true) }.to_str().unwrap();
104-
let attr_false = unsafe { CStr::from_ptr(git_attr__false) }.to_str().unwrap();
105-
let attr_unset = unsafe { CStr::from_ptr(git_attr__unset) }.to_str().unwrap();
93+
const ATTR_TRUE: &str = "[internal]__TRUE__";
94+
const ATTR_FALSE: &str = "[internal]__FALSE__";
95+
const ATTR_UNSET: &str = "[internal]__UNSET__";
10696
let as_bytes = AsRef::<[u8]>::as_ref;
10797
// Use `matches!` here since the `PartialEq` implementation does not differentiate
10898
// between `String` and `Bytes`.
10999
assert!(matches!(
110-
AttrValue::$function(Some(attr_true.to_owned().as_ref())),
111-
AttrValue::$variant(s) if as_bytes(s) == attr_true.as_bytes()
100+
AttrValue::$function(Some(ATTR_TRUE.as_ref())),
101+
AttrValue::$variant(s) if as_bytes(s) == ATTR_TRUE.as_bytes()
112102
));
113103
assert!(matches!(
114-
AttrValue::$function(Some(attr_false.to_owned().as_ref())),
115-
AttrValue::$variant(s) if as_bytes(s) == attr_false.as_bytes()
104+
AttrValue::$function(Some(ATTR_FALSE.as_ref())),
105+
AttrValue::$variant(s) if as_bytes(s) == ATTR_FALSE.as_bytes()
116106
));
117107
assert!(matches!(
118-
AttrValue::$function(Some(attr_unset.to_owned().as_ref())),
119-
AttrValue::$variant(s) if as_bytes(s) == attr_unset.as_bytes()
108+
AttrValue::$function(Some(ATTR_UNSET.as_ref())),
109+
AttrValue::$variant(s) if as_bytes(s) == ATTR_UNSET.as_bytes()
120110
));
121111
assert!(matches!(
122112
AttrValue::$function(Some("foo".as_ref())),
@@ -126,18 +116,6 @@ mod tests {
126116
AttrValue::$function(Some("bar".as_ref())),
127117
AttrValue::$variant(s) if as_bytes(s) == b"bar"
128118
));
129-
assert_eq!(
130-
AttrValue::$function(Some(attr_true.as_ref())),
131-
AttrValue::True
132-
);
133-
assert_eq!(
134-
AttrValue::$function(Some(attr_false.as_ref())),
135-
AttrValue::False
136-
);
137-
assert_eq!(
138-
AttrValue::$function(Some(attr_unset.as_ref())),
139-
AttrValue::Unspecified
140-
);
141119
assert_eq!(AttrValue::$function(None), AttrValue::Unspecified);
142120
};
143121
}

0 commit comments

Comments
 (0)