-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add pregenerated files with all units (#178)
The motivating example is to be able to use the library on godbolt. For this use case, we typically care far more about being comprehensive than we do about compile times. To enable this, we first add an `--all-units` flag to the single file script. This flag will cause the script to act as if the `--units` flag had been populated with every unit that is known to the library. (Under the hood, the script has a safety mechanism to make sure that we actually use every command line parameter in the script. This new parameter would run afoul of this mechanism, because it's mutually exclusive with the `--units` argument. Therefore, we use `--all-units` to populate `--units`, and then delete `--all-units`.) Next, we create build rules that use this new flag to generate single-file versions with all units, with and without the `<iostream>` dependency. Each new rule gets its own unit test. Finally, we update the installation docs to provide this option. We provide an appropriate degree of discouragement for general use, and clarity around suitable use cases. The godbolt link is currently "broken" (it doesn't compile), but we expect it to get fixed automatically once this PR lands. Test plan: - [x] Run script with combinations of arguments: - [x] Neither `--units` nor `--all-units`: builds with no units. - [x] Only `--units`: includes specified units. - [x] Only `--all-units`: includes all units. - [x] Both `--units` and `--all-units`: exits with error. - [x] Add unit tests for both single file generated versions. - [x] View rendered docs and follow links Fixes #174.
- Loading branch information
Showing
6 changed files
with
192 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Copyright 2022 Aurora Operations, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#include <chrono> | ||
|
||
#include "docs/au_all_units.hh" | ||
#include "gtest/gtest.h" | ||
|
||
// clang-format off | ||
// | ||
// This file textually includes all of the test cases which every ready-made | ||
// single-file release should pass. It needs to go after all other includes. | ||
#include "release/common_test_cases.hh" | ||
// clang-format on | ||
|
||
namespace au { | ||
|
||
namespace { | ||
template <typename T> | ||
std::string stream_to_string(const T &x) { | ||
std::ostringstream oss; | ||
oss << x; | ||
return oss.str(); | ||
} | ||
} // namespace | ||
|
||
TEST(AuAllUnitsHh, PrintsValueAndUnitLabel) { EXPECT_EQ(stream_to_string(minutes(3)), "3 min"); } | ||
|
||
} // namespace au |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Copyright 2022 Aurora Operations, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#include <chrono> | ||
|
||
#include "docs/au_all_units_noio.hh" | ||
#include "gtest/gtest.h" | ||
|
||
// clang-format off | ||
// | ||
// This file textually includes all of the test cases which every ready-made | ||
// single-file release should pass. It needs to go after all other includes. | ||
#include "release/common_test_cases.hh" | ||
// clang-format on | ||
|
||
namespace au { | ||
|
||
TEST(AuAllUnitsNoioHh, IncludesMoreObscureUnits) { | ||
EXPECT_EQ(minutes(120), hours(2)); | ||
EXPECT_EQ(fahrenheit_pt(32), celsius_pt(0)); | ||
} | ||
|
||
} // namespace au |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters