mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
[wpiutil] Upgrade to fmt 10.2.1, add wpi::print (#6161)
We now use a wrapper (wpi::print) to catch exceptions since we can't patch std::print() to not throw when we ultimately migrate to it. fmtlib and std format/print throw the same exceptions and always have. We previously patched fmt::print() to not throw a write failure exception, but we can't do that for std::print(); wpi::print() is the migration plan.
This commit is contained in:
@@ -5,8 +5,8 @@
|
||||
#include "DARETestUtil.h"
|
||||
|
||||
#include <Eigen/Eigenvalues>
|
||||
#include <fmt/core.h>
|
||||
#include <gtest/gtest.h>
|
||||
#include <wpi/print.h>
|
||||
|
||||
#include "frc/fmt/Eigen.h"
|
||||
|
||||
@@ -20,9 +20,9 @@ void ExpectMatrixEqual(const Eigen::MatrixXd& lhs, const Eigen::MatrixXd& rhs,
|
||||
}
|
||||
|
||||
if (::testing::Test::HasFailure()) {
|
||||
fmt::print("lhs =\n{}\n", lhs);
|
||||
fmt::print("rhs =\n{}\n", rhs);
|
||||
fmt::print("delta =\n{}\n", Eigen::MatrixXd{lhs - rhs});
|
||||
wpi::print("lhs =\n{}\n", lhs);
|
||||
wpi::print("rhs =\n{}\n", rhs);
|
||||
wpi::print("delta =\n{}\n", Eigen::MatrixXd{lhs - rhs});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include <type_traits>
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <wpi/print.h>
|
||||
|
||||
#include "units/acceleration.h"
|
||||
#include "units/angle.h"
|
||||
@@ -1426,59 +1427,59 @@ TEST_F(UnitContainer, cout) {
|
||||
#if __has_include(<fmt/format.h>) && !defined(UNIT_LIB_DISABLE_FMT)
|
||||
TEST_F(UnitContainer, fmtlib) {
|
||||
testing::internal::CaptureStdout();
|
||||
fmt::print("{}", degree_t(349.87));
|
||||
wpi::print("{}", degree_t(349.87));
|
||||
std::string output = testing::internal::GetCapturedStdout();
|
||||
EXPECT_STREQ("349.87 deg", output.c_str());
|
||||
|
||||
testing::internal::CaptureStdout();
|
||||
fmt::print("{}", meter_t(1.0));
|
||||
wpi::print("{}", meter_t(1.0));
|
||||
output = testing::internal::GetCapturedStdout();
|
||||
EXPECT_STREQ("1 m", output.c_str());
|
||||
|
||||
testing::internal::CaptureStdout();
|
||||
fmt::print("{}", dB_t(31.0));
|
||||
wpi::print("{}", dB_t(31.0));
|
||||
output = testing::internal::GetCapturedStdout();
|
||||
EXPECT_STREQ("31 dB", output.c_str());
|
||||
|
||||
testing::internal::CaptureStdout();
|
||||
fmt::print("{}", volt_t(21.79));
|
||||
wpi::print("{}", volt_t(21.79));
|
||||
output = testing::internal::GetCapturedStdout();
|
||||
EXPECT_STREQ("21.79 V", output.c_str());
|
||||
|
||||
testing::internal::CaptureStdout();
|
||||
fmt::print("{}", dBW_t(12.0));
|
||||
wpi::print("{}", dBW_t(12.0));
|
||||
output = testing::internal::GetCapturedStdout();
|
||||
EXPECT_STREQ("12 dBW", output.c_str());
|
||||
|
||||
testing::internal::CaptureStdout();
|
||||
fmt::print("{}", dBm_t(120.0));
|
||||
wpi::print("{}", dBm_t(120.0));
|
||||
output = testing::internal::GetCapturedStdout();
|
||||
EXPECT_STREQ("120 dBm", output.c_str());
|
||||
|
||||
testing::internal::CaptureStdout();
|
||||
fmt::print("{}", miles_per_hour_t(72.1));
|
||||
wpi::print("{}", miles_per_hour_t(72.1));
|
||||
output = testing::internal::GetCapturedStdout();
|
||||
EXPECT_STREQ("72.1 mph", output.c_str());
|
||||
|
||||
// undefined unit
|
||||
testing::internal::CaptureStdout();
|
||||
fmt::print("{}", units::math::cpow<4>(meter_t(2)));
|
||||
wpi::print("{}", units::math::cpow<4>(meter_t(2)));
|
||||
output = testing::internal::GetCapturedStdout();
|
||||
EXPECT_STREQ("16 m^4", output.c_str());
|
||||
|
||||
testing::internal::CaptureStdout();
|
||||
fmt::print("{}", units::math::cpow<3>(foot_t(2)));
|
||||
wpi::print("{}", units::math::cpow<3>(foot_t(2)));
|
||||
output = testing::internal::GetCapturedStdout();
|
||||
EXPECT_STREQ("8 cu_ft", output.c_str());
|
||||
|
||||
testing::internal::CaptureStdout();
|
||||
fmt::print("{:.9}", units::math::cpow<4>(foot_t(2)));
|
||||
wpi::print("{:.9}", units::math::cpow<4>(foot_t(2)));
|
||||
output = testing::internal::GetCapturedStdout();
|
||||
EXPECT_STREQ("0.138095597 m^4", output.c_str());
|
||||
|
||||
// constants
|
||||
testing::internal::CaptureStdout();
|
||||
fmt::print("{:.8}", constants::k_B);
|
||||
wpi::print("{:.8}", constants::k_B);
|
||||
output = testing::internal::GetCapturedStdout();
|
||||
#if defined(_MSC_VER) && (_MSC_VER <= 1800)
|
||||
EXPECT_STREQ("1.3806485e-023 m^2 kg s^-2 K^-1", output.c_str());
|
||||
@@ -1487,7 +1488,7 @@ TEST_F(UnitContainer, fmtlib) {
|
||||
#endif
|
||||
|
||||
testing::internal::CaptureStdout();
|
||||
fmt::print("{:.9}", constants::mu_B);
|
||||
wpi::print("{:.9}", constants::mu_B);
|
||||
output = testing::internal::GetCapturedStdout();
|
||||
#if defined(_MSC_VER) && (_MSC_VER <= 1800)
|
||||
EXPECT_STREQ("9.27400999e-024 m^2 A", output.c_str());
|
||||
@@ -1496,7 +1497,7 @@ TEST_F(UnitContainer, fmtlib) {
|
||||
#endif
|
||||
|
||||
testing::internal::CaptureStdout();
|
||||
fmt::print("{:.7}", constants::sigma);
|
||||
wpi::print("{:.7}", constants::sigma);
|
||||
output = testing::internal::GetCapturedStdout();
|
||||
#if defined(_MSC_VER) && (_MSC_VER <= 1800)
|
||||
EXPECT_STREQ("5.670367e-008 kg s^-3 K^-4", output.c_str());
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include <utility>
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <wpi/print.h>
|
||||
|
||||
#include "frc/StateSpaceUtil.h"
|
||||
#include "frc/estimator/DifferentialDrivePoseEstimator.h"
|
||||
@@ -50,7 +51,7 @@ void testFollowTrajectory(
|
||||
double errorSum = 0;
|
||||
|
||||
if (debug) {
|
||||
fmt::print(
|
||||
wpi::print(
|
||||
"time, est_x, est_y, est_theta, true_x, true_y, true_theta, left, "
|
||||
"right\n");
|
||||
}
|
||||
@@ -95,7 +96,7 @@ void testFollowTrajectory(
|
||||
leftDistance, rightDistance);
|
||||
|
||||
if (debug) {
|
||||
fmt::print(
|
||||
wpi::print(
|
||||
"{}, {}, {}, {}, {}, {}, {}, {}, {}\n", t.value(), xhat.X().value(),
|
||||
xhat.Y().value(), xhat.Rotation().Radians().value(),
|
||||
groundTruthState.pose.X().value(), groundTruthState.pose.Y().value(),
|
||||
@@ -116,14 +117,14 @@ void testFollowTrajectory(
|
||||
}
|
||||
|
||||
if (debug) {
|
||||
fmt::print("apply_time, measured_time, vision_x, vision_y, vision_theta\n");
|
||||
wpi::print("apply_time, measured_time, vision_x, vision_y, vision_theta\n");
|
||||
|
||||
units::second_t apply_time;
|
||||
units::second_t measure_time;
|
||||
frc::Pose2d vision_pose;
|
||||
for (auto record : visionLog) {
|
||||
std::tie(apply_time, measure_time, vision_pose) = record;
|
||||
fmt::print("{}, {}, {}, {}, {}\n", apply_time.value(),
|
||||
wpi::print("{}, {}, {}, {}, {}\n", apply_time.value(),
|
||||
measure_time.value(), vision_pose.X().value(),
|
||||
vision_pose.Y().value(),
|
||||
vision_pose.Rotation().Radians().value());
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include <tuple>
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <wpi/print.h>
|
||||
|
||||
#include "frc/estimator/MecanumDrivePoseEstimator.h"
|
||||
#include "frc/geometry/Pose2d.h"
|
||||
@@ -42,7 +43,7 @@ void testFollowTrajectory(
|
||||
double errorSum = 0;
|
||||
|
||||
if (debug) {
|
||||
fmt::print("time, est_x, est_y, est_theta, true_x, true_y, true_theta\n");
|
||||
wpi::print("time, est_x, est_y, est_theta, true_x, true_y, true_theta\n");
|
||||
}
|
||||
|
||||
while (t < trajectory.TotalTime()) {
|
||||
@@ -87,7 +88,7 @@ void testFollowTrajectory(
|
||||
wheelPositions);
|
||||
|
||||
if (debug) {
|
||||
fmt::print("{}, {}, {}, {}, {}, {}, {}\n", t.value(), xhat.X().value(),
|
||||
wpi::print("{}, {}, {}, {}, {}, {}, {}\n", t.value(), xhat.X().value(),
|
||||
xhat.Y().value(), xhat.Rotation().Radians().value(),
|
||||
groundTruthState.pose.X().value(),
|
||||
groundTruthState.pose.Y().value(),
|
||||
@@ -107,14 +108,14 @@ void testFollowTrajectory(
|
||||
}
|
||||
|
||||
if (debug) {
|
||||
fmt::print("apply_time, measured_time, vision_x, vision_y, vision_theta\n");
|
||||
wpi::print("apply_time, measured_time, vision_x, vision_y, vision_theta\n");
|
||||
|
||||
units::second_t apply_time;
|
||||
units::second_t measure_time;
|
||||
frc::Pose2d vision_pose;
|
||||
for (auto record : visionLog) {
|
||||
std::tie(apply_time, measure_time, vision_pose) = record;
|
||||
fmt::print("{}, {}, {}, {}, {}\n", apply_time.value(),
|
||||
wpi::print("{}, {}, {}, {}, {}\n", apply_time.value(),
|
||||
measure_time.value(), vision_pose.X().value(),
|
||||
vision_pose.Y().value(),
|
||||
vision_pose.Rotation().Radians().value());
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
|
||||
#include <fmt/format.h>
|
||||
#include <gtest/gtest.h>
|
||||
#include <wpi/print.h>
|
||||
#include <wpi/timestamp.h>
|
||||
|
||||
#include "frc/estimator/SwerveDrivePoseEstimator.h"
|
||||
@@ -45,7 +46,7 @@ void testFollowTrajectory(
|
||||
double errorSum = 0;
|
||||
|
||||
if (debug) {
|
||||
fmt::print("time, est_x, est_y, est_theta, true_x, true_y, true_theta\n");
|
||||
wpi::print("time, est_x, est_y, est_theta, true_x, true_y, true_theta\n");
|
||||
}
|
||||
|
||||
while (t < trajectory.TotalTime()) {
|
||||
@@ -90,7 +91,7 @@ void testFollowTrajectory(
|
||||
positions);
|
||||
|
||||
if (debug) {
|
||||
fmt::print("{}, {}, {}, {}, {}, {}, {}\n", t.value(), xhat.X().value(),
|
||||
wpi::print("{}, {}, {}, {}, {}, {}, {}\n", t.value(), xhat.X().value(),
|
||||
xhat.Y().value(), xhat.Rotation().Radians().value(),
|
||||
groundTruthState.pose.X().value(),
|
||||
groundTruthState.pose.Y().value(),
|
||||
@@ -110,14 +111,14 @@ void testFollowTrajectory(
|
||||
}
|
||||
|
||||
if (debug) {
|
||||
fmt::print("apply_time, measured_time, vision_x, vision_y, vision_theta\n");
|
||||
wpi::print("apply_time, measured_time, vision_x, vision_y, vision_theta\n");
|
||||
|
||||
units::second_t apply_time;
|
||||
units::second_t measure_time;
|
||||
frc::Pose2d vision_pose;
|
||||
for (auto record : visionLog) {
|
||||
std::tie(apply_time, measure_time, vision_pose) = record;
|
||||
fmt::print("{}, {}, {}, {}, {}\n", apply_time.value(),
|
||||
wpi::print("{}, {}, {}, {}, {}\n", apply_time.value(),
|
||||
measure_time.value(), vision_pose.X().value(),
|
||||
vision_pose.Y().value(),
|
||||
vision_pose.Rotation().Radians().value());
|
||||
|
||||
Reference in New Issue
Block a user