diff options
author | Roland Reichwein <mail@reichwein.it> | 2024-05-09 18:40:42 +0200 |
---|---|---|
committer | Roland Reichwein <mail@reichwein.it> | 2024-05-09 18:40:42 +0200 |
commit | 6086ec079a31276c81decdd7b5b5daaafdeb58ca (patch) | |
tree | 0e70f69fe5e626b544df69dfa9a0e62ff4332373 /yscan.cpp | |
parent | 1eaf818aa9339f29d08cf79601836c0ea763c622 (diff) |
Sort yscan output, tests
Diffstat (limited to 'yscan.cpp')
-rw-r--r-- | yscan.cpp | 27 |
1 files changed, 19 insertions, 8 deletions
@@ -2,9 +2,12 @@ #include "file.h" +#include <algorithm> #include <filesystem> #include <iostream> +#include <numeric> #include <string> +#include <vector> #include <fmt/format.h> @@ -18,24 +21,32 @@ int yscan(int argc, char* argv[]) try { std::string name {fs::current_path().stem().string()}; - std::string sources; - std::string test_sources; + std::vector<std::string> sources; + std::vector<std::string> test_sources; for (const auto& i: fs::directory_iterator(".")) { fs::path p{i.path().filename()}; if (is_compile_unit_source_by_extension(p)) { if (p.string().substr(0, 4) == "test") { - test_sources += " <source>" + p.string() + "</source>\n"; + test_sources.push_back(p.string()); } else { - sources += " <source>" + p.string() + "</source>\n"; + sources.push_back(p.string()); } } } - if (!test_sources.empty()) { - test_sources = fmt::format(R"( <test> + std::sort(sources.begin(), sources.end()); + std::sort(test_sources.begin(), test_sources.end()); + + std::string sources_string{std::accumulate(sources.begin(), sources.end(), std::string{}, + [](const std::string& sum, const std::string& i){return sum + " <source>" + i + "</source>\n";})}; + std::string test_sources_string{std::accumulate(test_sources.begin(), test_sources.end(), std::string{}, + [](const std::string& sum, const std::string& i){return sum + " <source>" + i + "</source>\n";})}; + + if (!test_sources_string.empty()) { + test_sources_string = fmt::format(R"( <test> <name>{}</name> {} </test> -)", "test-"s + name, test_sources); +)", "test-"s + name, test_sources_string); } std::string contents {R"(<ymake> @@ -43,7 +54,7 @@ int yscan(int argc, char* argv[]) <name>{}</name> {} </build> {}</ymake>)"}; - contents = fmt::format(contents, name, sources, test_sources); + contents = fmt::format(contents, name, sources_string, test_sources_string); std::cout << contents << std::endl; } catch (const std::exception& ex) { std::cerr << "yscan: " << ex.what() << std::endl; |