Skip to content

Commit cc69d21

Browse files
committed
[libc++/abi] Clean up uses of <iostream> in the test suite
We used <iostream> in several places where we don't actually need the full power of <iostream>, and where using basic `std::printf` is enough. This is better, since `std::printf` can be supported on systems that don't have a notion of locales, while <iostream> can't.
1 parent 9b1c06c commit cc69d21

File tree

39 files changed

+271
-322
lines changed

39 files changed

+271
-322
lines changed

libcxx/test/libcxx/containers/sequences/deque/spare_block_handling.pass.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
// resizes or shrinks at the correct time.
1616

1717
#include <deque>
18-
#include <iostream>
18+
#include <cstdio>
1919
#include <memory>
20-
#include <stack>
2120
#include <queue>
21+
#include <stack>
2222

2323
#include "min_allocator.h"
2424
#include "rapid-cxx-test.h"
@@ -31,12 +31,12 @@ struct ContainerAdaptor : public Adaptor {
3131

3232
template <class Deque>
3333
static void print(const Deque& d) {
34-
std::cout << d.size()
35-
<< " : __front_spare() == " << d.__front_spare()
36-
<< " : __back_spare() == " << d.__back_spare()
37-
<< " : __capacity() == " << d.__capacity()
38-
<< " : bytes allocated == "
39-
<< malloc_allocator_base::outstanding_bytes << '\n';
34+
std::printf("%lu : __front_spare() == %lu"
35+
" : __back_spare() == %lu"
36+
" : __capacity() == %lu"
37+
" : bytes allocated == %lu\n",
38+
d.size(), d.__front_spare(), d.__back_spare(), d.__capacity(),
39+
malloc_allocator_base::outstanding_bytes);
4040
}
4141

4242
template <class T>

libcxx/test/libcxx/iterators/failed.pass.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
// Extension: constructing from NULL is UB; we just make it a failed iterator
1616

1717
#include <iterator>
18-
#include <sstream>
1918
#include <cassert>
2019

2120
#include "test_macros.h"

libcxx/test/std/containers/associative/map/map.cons/copy_assign.pass.cpp

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,11 @@
1313
// map& operator=(const map& m);
1414

1515
#include <map>
16-
#include <cassert>
17-
#include <vector>
1816
#include <algorithm>
17+
#include <cassert>
18+
#include <cstdio>
1919
#include <iterator>
20-
21-
#include <iostream>
20+
#include <vector>
2221

2322
#include "test_macros.h"
2423
#include "../../../test_compare.h"
@@ -78,35 +77,40 @@ class counting_allocatorF {
7877
bool balanced_allocs() {
7978
std::vector<int> temp1, temp2;
8079

81-
std::cout << "Allocations = " << ca_allocs.size() << ", deallocatons = " << ca_deallocs.size() << std::endl;
80+
std::printf("Allocations = %lu, deallocations = %lu\n", ca_allocs.size(), ca_deallocs.size());
8281
if (ca_allocs.size() != ca_deallocs.size())
8382
return false;
8483

8584
temp1 = ca_allocs;
8685
std::sort(temp1.begin(), temp1.end());
8786
temp2.clear();
8887
std::unique_copy(temp1.begin(), temp1.end(), std::back_inserter<std::vector<int>>(temp2));
89-
std::cout << "There were " << temp2.size() << " different allocators\n";
88+
std::printf("There were %lu different allocators\n", temp2.size());
9089

9190
for (std::vector<int>::const_iterator it = temp2.begin(); it != temp2.end(); ++it ) {
92-
std::cout << *it << ": " << std::count(ca_allocs.begin(), ca_allocs.end(), *it) << " vs " << std::count(ca_deallocs.begin(), ca_deallocs.end(), *it) << std::endl;
93-
if ( std::count(ca_allocs.begin(), ca_allocs.end(), *it) != std::count(ca_deallocs.begin(), ca_deallocs.end(), *it))
91+
std::ptrdiff_t const allocs = std::count(ca_allocs.begin(), ca_allocs.end(), *it);
92+
std::ptrdiff_t const deallocs = std::count(ca_deallocs.begin(), ca_deallocs.end(), *it);
93+
std::printf("%d: %ld vs %ld\n", *it, allocs, deallocs);
94+
if (allocs != deallocs)
9495
return false;
95-
}
96+
}
9697

9798
temp1 = ca_allocs;
9899
std::sort(temp1.begin(), temp1.end());
99100
temp2.clear();
100101
std::unique_copy(temp1.begin(), temp1.end(), std::back_inserter<std::vector<int>>(temp2));
101-
std::cout << "There were " << temp2.size() << " different (de)allocators\n";
102+
std::printf("There were %lu different (de)allocators\n", temp2.size());
103+
102104
for (std::vector<int>::const_iterator it = ca_deallocs.begin(); it != ca_deallocs.end(); ++it ) {
103-
std::cout << *it << ": " << std::count(ca_allocs.begin(), ca_allocs.end(), *it) << " vs " << std::count(ca_deallocs.begin(), ca_deallocs.end(), *it) << std::endl;
104-
if ( std::count(ca_allocs.begin(), ca_allocs.end(), *it) != std::count(ca_deallocs.begin(), ca_deallocs.end(), *it))
105+
std::ptrdiff_t const allocs = std::count(ca_allocs.begin(), ca_allocs.end(), *it);
106+
std::ptrdiff_t const deallocs = std::count(ca_deallocs.begin(), ca_deallocs.end(), *it);
107+
std::printf("%d: %ld vs %ld\n", *it, allocs, deallocs);
108+
if (allocs != deallocs)
105109
return false;
106-
}
110+
}
107111

108112
return true;
109-
}
113+
}
110114
#endif
111115

112116
int main(int, char**)

libcxx/test/std/containers/associative/map/map.modifiers/insert_or_assign.pass.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@
2525
#include <cassert>
2626
#include <tuple>
2727

28-
#include <iostream>
29-
3028
#include "test_macros.h"
3129

3230
class Moveable

libcxx/test/std/containers/associative/set/set.cons/assign_initializer_list.pass.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
#include <set>
1818
#include <cassert>
19-
#include <iostream>
2019

2120
#include "test_macros.h"
2221
#include "min_allocator.h"

libcxx/test/std/containers/sequences/forwardlist/forwardlist.ops/sort_pred.pass.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
#include <functional>
1818
#include <random>
1919
#include <cassert>
20-
#include <iostream>
2120

2221
#include "test_macros.h"
2322
#include "min_allocator.h"

libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/move_alloc.pass.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616

1717
// unordered_multimap(unordered_multimap&& u, const allocator_type& a);
1818

19-
#include <iostream>
20-
2119
#include <unordered_map>
2220
#include <string>
2321
#include <set>
@@ -272,5 +270,5 @@ int main(int, char**)
272270
assert(c0.empty());
273271
}
274272

275-
return 0;
273+
return 0;
276274
}

libcxx/test/std/input.output/filesystems/class.directory_entry/directory_entry.obs/file_size.pass.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222
#include "filesystem_test_helper.h"
2323
#include "rapid-cxx-test.h"
2424

25-
#include <iostream>
26-
2725
#include "test_macros.h"
2826

2927
TEST_SUITE(directory_entry_obs_testsuite)

libcxx/test/std/input.output/filesystems/class.directory_iterator/directory_iterator.members/increment.pass.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
#include "test_macros.h"
2424
#include "rapid-cxx-test.h"
2525
#include "filesystem_test_helper.h"
26-
#include <iostream>
2726

2827
using namespace fs;
2928

libcxx/test/std/input.output/filesystems/class.directory_iterator/directory_iterator.nonmembers/begin_end.pass.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
#include "test_macros.h"
2424
#include "rapid-cxx-test.h"
2525
#include "filesystem_test_helper.h"
26-
#include <iostream>
2726

2827
using namespace fs;
2928

0 commit comments

Comments
 (0)