Skip to content

Commit daf9990

Browse files
committed
Add 32-bit expectations for remaining == size assertions
Most `assert_eq!` data structure size assertions that had failed on 32-bit targets were to safeguard against the size increasing, so using a `==` comparison on 64-bit targets and a `<=` comparison to the same value on 32-bit targets was a suitable fix, which allowed 18 tests to go from failing to passing in the 32-bit container. However, four remaining tests that assert sizes of buffers or streamed data are not just for flagging increases, but are instead cases where a change in either direction, on any platform, should probably draw attention. The most important of these to keep `==`, even on 32-bit platforms, may be two tests that assert the same value for complementary operations: - gix::gix repository::worktree::archive - gix::gix repository::worktree::stream But I think it's useful to do this in the two others, too: - gix-archive::archive from_tree::basic_usage_internal - gix-worktree-stream::stream from_tree::will_provide_all_information_and_respect_export_ignore This commit adds constants with different 64-bit and 32-bit values for the three buffer lengths asserted in those four tests (the two `gix::gix repository::worktree::*` assert the same length). This change should make the four remaining tests that had been failing on the 32-bit container, and 32-bit GNU/Linux targets in general, pass on them. In specifying the expected 32-bit buffer lengths, I have treated these as approval tests, rather than inferring that the exact length and no other length must be correct. The asserted lengths: - Appeared as the value when the tests were run in the 32-bit container. - Are verified to appear repeatedly across different runs in the container as well as in runs on a non-containerized 32-bit Debian 12 system. - Are equal to the values in assertion messages for the same failed tests run on a 32-bit Windows 10 system. This is significant because some values differ between different 32-bit targets, even targets for the same 32-bit architecture, and two such targets where I've observed differences are `i686-unknown-linux-gnu` and `i686-pc-windows-msvc`. - Are, of course, less than the 64-bit sizes, not greater. - Make sense on inspection. (But please note that this is not the same as an analysis that proves they are the only possible correct values.)
1 parent 2f77c9b commit daf9990

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

gix-archive/tests/archive.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,15 @@ mod from_tree {
1414

1515
use crate::hex_to_id;
1616

17+
#[cfg(target_pointer_width = "64")]
18+
const EXPECTED_BUFFER_LENGTH: usize = 551;
19+
#[cfg(target_pointer_width = "32")]
20+
const EXPECTED_BUFFER_LENGTH: usize = 479;
21+
1722
#[test]
1823
fn basic_usage_internal() -> gix_testtools::Result {
1924
basic_usage(gix_archive::Format::InternalTransientNonPersistable, |buf| {
20-
assert_eq!(buf.len(), 551);
25+
assert_eq!(buf.len(), EXPECTED_BUFFER_LENGTH);
2126

2227
let mut stream = gix_worktree_stream::Stream::from_read(std::io::Cursor::new(buf));
2328
let mut paths_and_modes = Vec::new();

gix-worktree-stream/tests/stream.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ mod from_tree {
5858
Ok(())
5959
}
6060

61+
#[cfg(target_pointer_width = "64")]
62+
const EXPECTED_BUFFER_LENGTH: usize = 320302;
63+
#[cfg(target_pointer_width = "32")]
64+
const EXPECTED_BUFFER_LENGTH: usize = 320198;
65+
6166
#[test]
6267
fn will_provide_all_information_and_respect_export_ignore() -> gix_testtools::Result {
6368
let (dir, head_tree, odb, mut cache) = basic()?;
@@ -186,7 +191,7 @@ mod from_tree {
186191
);
187192
assert_eq!(
188193
copy.lock().len(),
189-
320302,
194+
EXPECTED_BUFFER_LENGTH,
190195
"keep track of file size changes of the streaming format"
191196
);
192197

gix/tests/gix/repository/worktree.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
use gix_ref::bstr;
22

3+
#[cfg(target_pointer_width = "64")]
4+
const EXPECTED_BUFFER_LENGTH: usize = 102;
5+
#[cfg(target_pointer_width = "32")]
6+
const EXPECTED_BUFFER_LENGTH: usize = 86;
7+
38
#[test]
49
#[cfg(feature = "worktree-stream")]
510
fn stream() -> crate::Result {
611
let repo = crate::named_repo("make_packed_and_loose.sh")?;
712
let mut stream = repo.worktree_stream(repo.head_commit()?.tree_id()?)?.0.into_read();
813
assert_eq!(
914
std::io::copy(&mut stream, &mut std::io::sink())?,
10-
102,
15+
EXPECTED_BUFFER_LENGTH as u64,
1116
"there is some content in the stream, it works"
1217
);
1318
Ok(())
@@ -27,7 +32,7 @@ fn archive() -> crate::Result {
2732
&std::sync::atomic::AtomicBool::default(),
2833
Default::default(),
2934
)?;
30-
assert_eq!(buf.len(), 102, "default format is internal");
35+
assert_eq!(buf.len(), EXPECTED_BUFFER_LENGTH, "default format is internal");
3136
Ok(())
3237
}
3338

0 commit comments

Comments
 (0)