-
Notifications
You must be signed in to change notification settings - Fork 3
refactor(deco,zest): make macro.h a pure macro header in both libraries #181
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
12 changes: 9 additions & 3 deletions
12
include/kota/deco/facade/macro.h → include/kota/deco/macro.h
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,4 +1,14 @@ | ||
| #pragma once | ||
|
|
||
| #include "kota/zest/assert/check.h" | ||
| #include "kota/zest/assert/trace.h" | ||
| #include "kota/zest/macro.h" | ||
| #include "kota/zest/runner/run.h" | ||
| #include "kota/zest/runner/suite.h" | ||
| #include "kota/zest/snapshot/snapshot.h" | ||
|
|
||
| // Matches the guard "kota/zest/macro.h" uses for the snapshot-JSON macros, which | ||
| // name ::kota::codec::json but cannot include it themselves. | ||
| #if __has_include("kota/codec/json/json.h") | ||
| #include "kota/codec/json/json.h" | ||
| #endif |
This file contains hidden or 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 hidden or 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,47 @@ | ||
| // "kota/deco/macro.h" is what a downstream consuming kotatsu as a module has to | ||
| // include: modules cannot export macros, so the Deco* macros must arrive through | ||
| // a textual include that drags in no deco declarations of its own. Including it | ||
| // as the very first header here keeps that contract honest — if it ever grows a | ||
| // dependency on a facade header, this translation unit stops compiling. | ||
| #include "kota/deco/macro.h" | ||
|
|
||
| #if !defined(DECO_CFG) || !defined(DecoFlag) || !defined(DecoKV) || !defined(DecoInput) || \ | ||
| !defined(DecoPack) || !defined(DecoMulti) || !defined(DecoComma) || !defined(DecoFlagAlias) | ||
| #error "kota/deco/macro.h must define the deco declaration macros on its own" | ||
| #endif | ||
|
|
||
| #include <string> | ||
| #include <vector> | ||
|
|
||
| #include "kota/deco/deco.h" | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| #include "kota/zest/zest.h" | ||
|
|
||
| namespace kota::deco { | ||
| namespace { | ||
|
|
||
| // Declared with the macros already in scope from the standalone include above, | ||
| // which is the order a module consumer ends up with. | ||
| struct StandaloneCfg { | ||
| DecoFlag(names = {"-v", "--verbose"}; help = "verbose") | ||
| verbose; | ||
| DecoKV(help = "output") | ||
| <std::string> output = "a.out"; | ||
| }; | ||
|
|
||
| TEST_SUITE(deco_macro_standalone) { | ||
|
|
||
| TEST_CASE(DeclaresOptions) { | ||
| auto cmd = cli::command<StandaloneCfg>("app [OPTIONS]"); | ||
|
|
||
| std::vector<std::string> args = {"--verbose", "--output", "b.out"}; | ||
| auto res = cmd.invoke(args); | ||
| ASSERT_TRUE(res.has_value()); | ||
|
|
||
| EXPECT_TRUE(res->options.verbose.value()); | ||
| EXPECT_EQ(res->options.output.value(), "b.out"); | ||
| } | ||
|
|
||
| }; // TEST_SUITE(deco_macro_standalone) | ||
|
|
||
| } // namespace | ||
| } // namespace kota::deco | ||
This file contains hidden or 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 hidden or 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,33 @@ | ||
| // "kota/zest/macro.h" is what a downstream consuming kotatsu as a module has to | ||
| // include: modules cannot export macros, so the test macros must arrive through | ||
| // a textual include that drags in no zest declarations of its own. Including it | ||
| // as the very first header here keeps that contract honest — if it ever grows a | ||
| // dependency on another zest header, this translation unit stops compiling. | ||
| #include "kota/zest/macro.h" | ||
|
|
||
| #if !defined(TEST_SUITE) || !defined(TEST_CASE) || !defined(EXPECT_TRUE) || !defined(EXPECT_EQ) || \ | ||
| !defined(ASSERT_TRUE) || !defined(EXPECT_SNAPSHOT) || !defined(STATIC_EXPECT_EQ) | ||
| #error "kota/zest/macro.h must define the zest test macros on its own" | ||
| #endif | ||
|
|
||
| #include "kota/zest/zest.h" | ||
|
|
||
| namespace kota::zest { | ||
|
|
||
| namespace { | ||
|
|
||
| // Written against the macros already in scope from the standalone include above, | ||
| // which is the order a module consumer ends up with. | ||
| TEST_SUITE(zest_macro_standalone) { | ||
|
|
||
| TEST_CASE(macros_usable_without_declaration_headers) { | ||
| STATIC_EXPECT_EQ(1 + 1, 2); | ||
| ASSERT_TRUE(true); | ||
| EXPECT_EQ(std::string("a"), std::string("a")); | ||
| } | ||
|
|
||
| }; // TEST_SUITE(zest_macro_standalone) | ||
|
|
||
| } // namespace | ||
|
|
||
| } // namespace kota::zest |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.