|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581 |
- import json
- from pathlib import Path
- from typing import NamedTuple, Sequence, List
-
- import pytest
-
- from tests import DDS, fileutil
-
-
- class DepsCase(NamedTuple):
- dep: str
- usage: str
- source: str
-
- def setup_root(self, dds: DDS):
- dds.scope.enter_context(
- fileutil.set_contents(
- dds.source_root / 'package.json',
- json.dumps({
- 'name': 'test-project',
- 'namespace': 'test',
- 'version': '0.0.0',
- 'depends': [self.dep],
- }).encode()))
- dds.scope.enter_context(
- fileutil.set_contents(dds.source_root / 'library.json',
- json.dumps({
- 'name': 'test',
- 'uses': [self.usage],
- }).encode()))
- dds.scope.enter_context(fileutil.set_contents(dds.source_root / 'src/test.test.cpp', self.source.encode()))
-
-
- CASES: List[DepsCase] = []
-
-
- def get_default_pkg_versions(pkg: str) -> Sequence[str]:
- catalog_json = Path(__file__).resolve().parent.parent.parent / 'old-catalog.json'
- catalog_dict = json.loads(catalog_json.read_text())
- return list(catalog_dict['packages'][pkg].keys())
-
-
- def add_cases(pkg: str, uses: str, versions: Sequence[str], source: str):
- if versions == ['auto']:
- versions = get_default_pkg_versions(pkg)
- for ver in versions:
- CASES.append(DepsCase(f'{pkg}@{ver}', uses, source))
-
-
- # magic_enum tests
- """
- ## ## ### ###### #### ###### ######## ## ## ## ## ## ##
- ### ### ## ## ## ## ## ## ## ## ### ## ## ## ### ###
- #### #### ## ## ## ## ## ## #### ## ## ## #### ####
- ## ### ## ## ## ## #### ## ## ###### ## ## ## ## ## ## ### ##
- ## ## ######### ## ## ## ## ## ## #### ## ## ## ##
- ## ## ## ## ## ## ## ## ## ## ## ### ## ## ## ##
- ## ## ## ## ###### #### ###### ####### ######## ## ## ####### ## ##
- """
- add_cases(
- 'magic_enum', 'neargye/magic_enum', ['auto'], r'''
- #include <magic_enum.hpp>
- #include <string_view>
-
- enum my_enum {
- foo,
- bar,
- };
-
- int main() {
- if (magic_enum::enum_name(my_enum::foo) != "foo") {
- return 1;
- }
- }
- ''')
-
- # Range-v3 tests
- """
- ######## ### ## ## ###### ######## ## ## #######
- ## ## ## ## ### ## ## ## ## ## ## ## ##
- ## ## ## ## #### ## ## ## ## ## ##
- ######## ## ## ## ## ## ## #### ###### ####### ## ## #######
- ## ## ######### ## #### ## ## ## ## ## ##
- ## ## ## ## ## ### ## ## ## ## ## ## ##
- ## ## ## ## ## ## ###### ######## ### #######
- """
-
- add_cases(
- 'range-v3', 'range-v3/range-v3', ['auto'], r'''
- #include <range/v3/algorithm/remove_if.hpp>
-
- #include <vector>
- #include <algorithm>
-
- int main() {
- std::vector<int> nums = {1, 2, 3, 5, 1, 4, 2, 7, 8, 0, 9};
- auto end = ranges::remove_if(nums, [](auto i) { return i % 2; });
- return std::distance(nums.begin(), end) != 5;
- }
- ''')
-
- # nlohmann-json
- """
- ## ## ## ####### ## ## ## ## ### ## ## ## ## ## ###### ####### ## ##
- ### ## ## ## ## ## ## ### ### ## ## ### ## ### ## ## ## ## ## ## ### ##
- #### ## ## ## ## ## ## #### #### ## ## #### ## #### ## ## ## ## ## #### ##
- ## ## ## ## ## ## ######### ## ### ## ## ## ## ## ## ## ## ## ####### ## ###### ## ## ## ## ##
- ## #### ## ## ## ## ## ## ## ######### ## #### ## #### ## ## ## ## ## ## ####
- ## ### ## ## ## ## ## ## ## ## ## ## ### ## ### ## ## ## ## ## ## ## ###
- ## ## ######## ####### ## ## ## ## ## ## ## ## ## ## ###### ###### ####### ## ##
- """
- add_cases('nlohmann-json', 'nlohmann/json', ['auto'], r'''
- #include <nlohmann/json.hpp>
-
- int main() {}
- ''')
-
- # ctre
- """
- ###### ######## ######## ########
- ## ## ## ## ## ##
- ## ## ## ## ##
- ## ## ######## ######
- ## ## ## ## ##
- ## ## ## ## ## ##
- ###### ## ## ## ########
- """
- add_cases(
- 'ctre', 'hanickadot/ctre', ['auto'], r'''
- #include <ctre.hpp>
-
- constexpr ctll::fixed_string MY_REGEX{"\\w+-[0-9]+"};
-
- int main() {
- auto [did_match] = ctre::match<MY_REGEX>("foo-44");
- if (!did_match) {
- return 1;
- }
-
- auto [did_match_2] = ctre::match<MY_REGEX>("bar-1ff");
- if (did_match_2) {
- return 2;
- }
- }
- ''')
-
- # fmt
- """
- ######## ## ## ########
- ## ### ### ##
- ## #### #### ##
- ###### ## ### ## ##
- ## ## ## ##
- ## ## ## ##
- ## ## ## ##
- """
- add_cases('fmt', 'fmt/fmt', ['auto'], r'''
- #include <fmt/core.h>
-
- int main() {
- fmt::print("Hello!");
- }
- ''')
-
- # Catch2
- """
- ###### ### ######## ###### ## ## #######
- ## ## ## ## ## ## ## ## ## ## ##
- ## ## ## ## ## ## ## ##
- ## ## ## ## ## ######### #######
- ## ######### ## ## ## ## ##
- ## ## ## ## ## ## ## ## ## ##
- ###### ## ## ## ###### ## ## #########
- """
- add_cases(
- 'catch2', 'catch2/catch2', ['auto'], r'''
- #include <catch2/catch_with_main.hpp>
-
- TEST_CASE("I am a test case") {
- CHECK((2 + 2) == 4);
- CHECK_FALSE((2 + 2) == 5);
- }
- ''')
-
- # Asio
- """
- ### ###### #### #######
- ## ## ## ## ## ## ##
- ## ## ## ## ## ##
- ## ## ###### ## ## ##
- ######### ## ## ## ##
- ## ## ## ## ## ## ##
- ## ## ###### #### #######
- """
- add_cases(
- 'asio', 'asio/asio', ['auto'], r'''
- #include <asio.hpp>
-
- int main() {
- asio::io_context ioc;
-
- int retcode = 12;
- ioc.post([&] {
- retcode = 0;
- });
- ioc.run();
- return retcode;
- }
- ''')
-
- # Abseil
- """
- ### ######## ###### ######## #### ##
- ## ## ## ## ## ## ## ## ##
- ## ## ## ## ## ## ## ##
- ## ## ######## ###### ###### ## ##
- ######### ## ## ## ## ## ##
- ## ## ## ## ## ## ## ## ##
- ## ## ######## ###### ######## #### ########
- """
- add_cases(
- 'abseil', 'abseil/abseil', ['auto'], r'''
- #include <absl/strings/str_cat.h>
-
- int main() {
- std::string_view foo = "foo";
- std::string_view bar = "bar";
- auto cat = absl::StrCat(foo, bar);
- return cat != "foobar";
- }
- ''')
-
- # Zlib
- """
- ######## ## #### ########
- ## ## ## ## ##
- ## ## ## ## ##
- ## ## ## ########
- ## ## ## ## ##
- ## ## ## ## ##
- ######## ######## #### ########
- """
- add_cases(
- 'zlib', 'zlib/zlib', ['auto'], r'''
- #include <zlib.h>
- #include <cassert>
-
- int main() {
- ::z_stream strm = {};
- deflateInit(&strm, 6);
-
- const char buffer[] = "foo bar baz";
- strm.next_in = (Bytef*)buffer;
- strm.avail_in = sizeof buffer;
-
- char dest[256] = {};
- strm.next_out = (Bytef*)dest;
- strm.avail_out = sizeof dest;
- auto ret = deflate(&strm, Z_FINISH);
- deflateEnd(&strm);
- assert(ret == Z_STREAM_END);
- assert(strm.avail_in == 0);
- assert(strm.avail_out != sizeof dest);
- }
- ''')
-
- # sol2
- """
- ###### ####### ## #######
- ## ## ## ## ## ## ##
- ## ## ## ## ##
- ###### ## ## ## #######
- ## ## ## ## ##
- ## ## ## ## ## ##
- ###### ####### ######## #########
- """
- add_cases(
- 'sol2', 'sol2/sol2', ['3.2.1', '3.2.0', '3.0.3', '3.0.2'], r'''
- #include <sol/sol.hpp>
-
- int main() {
- sol::state lua;
- int x = 0;
- lua.set_function("beepboop", [&]{ ++x; });
- lua.script("beepboop()");
- return x != 1;
- }
- ''')
-
- # pegtl
- """
- ######## ######## ###### ######## ##
- ## ## ## ## ## ## ##
- ## ## ## ## ## ##
- ######## ###### ## #### ## ##
- ## ## ## ## ## ##
- ## ## ## ## ## ##
- ## ######## ###### ## ########
- """
- add_cases(
- 'pegtl', 'tao/pegtl', ['auto'], r'''
- #include <tao/pegtl.hpp>
-
- using namespace tao::pegtl;
-
- struct sign : one<'+', '-'> {};
- struct integer : seq<opt<sign>, plus<digit>> {};
-
- int main() {
- tao::pegtl::string_input str{"+44", "[test string]"};
- tao::pegtl::parse<integer>(str);
- }
- ''')
-
- # Boost.PFR
- """
- ######## ####### ####### ###### ######## ######## ######## ########
- ## ## ## ## ## ## ## ## ## ## ## ## ## ##
- ## ## ## ## ## ## ## ## ## ## ## ## ##
- ######## ## ## ## ## ###### ## ######## ###### ########
- ## ## ## ## ## ## ## ## ## ## ## ##
- ## ## ## ## ## ## ## ## ## ### ## ## ## ##
- ######## ####### ####### ###### ## ### ## ## ## ##
- """
- add_cases(
- 'boost.pfr', 'boost/pfr', ['auto'], r'''
- #include <iostream>
- #include <string>
- #include <boost/pfr/precise.hpp>
-
- struct some_person {
- std::string name;
- unsigned birth_year;
- };
-
- int main() {
- some_person val{"Edgar Allan Poe", 1809};
-
- std::cout << boost::pfr::get<0>(val) // No macro!
- << " was born in " << boost::pfr::get<1>(val); // Works with any aggregate initializables!
-
- return boost::pfr::get<0>(val) != "Edgar Allan Poe";
- }
- ''')
-
- # Boost.LEAF
- """
- ## ######## ### ########
- ## ## ## ## ##
- ## ## ## ## ##
- ## ###### ## ## ######
- ## ## ######### ##
- ## ## ## ## ##
- ######## ######## ## ## ##
- """
- add_cases(
- 'boost.leaf', 'boost/leaf', ['auto'], r'''
- #include <boost/leaf/all.hpp>
-
- namespace leaf = boost::leaf;
-
- int main() {
- return leaf::try_handle_all(
- [&]() -> leaf::result<int> {
- return 0;
- },
- [](leaf::error_info const&) {
- return 32;
- }
- );
- }
- ''')
-
- # Boost.mp11
- """
- ######## ####### ####### ###### ######## ## ## ######## ## ##
- ## ## ## ## ## ## ## ## ## ### ### ## ## #### ####
- ## ## ## ## ## ## ## ## #### #### ## ## ## ##
- ######## ## ## ## ## ###### ## ## ### ## ######## ## ##
- ## ## ## ## ## ## ## ## ## ## ## ## ##
- ## ## ## ## ## ## ## ## ## ### ## ## ## ## ##
- ######## ####### ####### ###### ## ### ## ## ## ###### ######
- """
- add_cases(
- 'boost.mp11', 'boost/mp11', ['auto'], r'''
- #include <boost/mp11.hpp>
-
- int main() {
- return boost::mp11::mp_false() == boost::mp11::mp_true();
- }
- ''')
-
- # libsodium
- """
- ## #### ######## ###### ####### ######## #### ## ## ## ##
- ## ## ## ## ## ## ## ## ## ## ## ## ## ### ###
- ## ## ## ## ## ## ## ## ## ## ## ## #### ####
- ## ## ######## ###### ## ## ## ## ## ## ## ## ### ##
- ## ## ## ## ## ## ## ## ## ## ## ## ## ##
- ## ## ## ## ## ## ## ## ## ## ## ## ## ## ##
- ######## #### ######## ###### ####### ######## #### ####### ## ##
- """
- add_cases(
- 'libsodium', 'sodium/sodium', ['auto'], r'''
- #include <sodium.h>
-
- #include <algorithm>
-
- int main() {
- char arr[256] = {};
- ::randombytes_buf(arr, sizeof arr);
- for (auto b : arr) {
- if (b != '\x00') {
- return 0;
- }
- }
- return 1;
- }
- ''')
-
- # toml++
- """
- ######## ####### ## ## ##
- ## ## ## ### ### ## ## ##
- ## ## ## #### #### ## ## ##
- ## ## ## ## ### ## ## ###### ######
- ## ## ## ## ## ## ## ##
- ## ## ## ## ## ## ## ##
- ## ####### ## ## ########
- """
- add_cases(
- 'tomlpp', 'tomlpp/tomlpp', ['auto'], r'''
- #include <toml++/toml.h>
-
- #include <string_view>
-
- int main() {
- std::string_view sv = R"(
- [library]
- something = "cats"
- person = "Joe"
- )";
-
- toml::table tbl = toml::parse(sv);
- return tbl["library"]["person"] != "Joe";
- }
- ''')
-
- # Inja
- """
- #### ## ## ## ###
- ## ### ## ## ## ##
- ## #### ## ## ## ##
- ## ## ## ## ## ## ##
- ## ## #### ## ## #########
- ## ## ### ## ## ## ##
- #### ## ## ###### ## ##
- """
- add_cases(
- 'inja', 'inja/inja', ['2.0.0', '2.0.1', '2.1.0', '2.2.0'], r'''
- #include <inja/inja.hpp>
- #include <nlohmann/json.hpp>
-
- int main() {
- nlohmann::json data;
- data["foo"] = "bar";
-
- auto result = inja::render("foo {{foo}}", data);
- return result != "foo bar";
- }
- ''')
-
- # Cereal
- """
- ###### ######## ######## ######## ### ##
- ## ## ## ## ## ## ## ## ##
- ## ## ## ## ## ## ## ##
- ## ###### ######## ###### ## ## ##
- ## ## ## ## ## ######### ##
- ## ## ## ## ## ## ## ## ##
- ###### ######## ## ## ######## ## ## ########
- """
- add_cases(
- 'cereal', 'cereal/cereal', ['auto'], r'''
- #include <cereal/types/memory.hpp>
- #include <cereal/types/string.hpp>
- #include <cereal/archives/binary.hpp>
-
- #include <sstream>
-
- struct something {
- int a, b, c;
- std::string str;
-
- template <typename Ar>
- void serialize(Ar& ar) {
- ar(a, b, c, str);
- }
- };
-
- int main() {
- std::stringstream strm;
- cereal::BinaryOutputArchive ar{strm};
-
- something s;
- ar(s);
-
- return 0;
- }
- ''')
-
- # pcg
- """
- ######## ###### ######
- ## ## ## ## ## ##
- ## ## ## ##
- ######## ## ## ####
- ## ## ## ##
- ## ## ## ## ##
- ## ###### ######
- """
- add_cases(
- 'pcg-cpp', 'pcg/pcg-cpp', ['auto'], r'''
- #include <pcg_random.hpp>
-
- #include <iostream>
-
- int main() {
- pcg64 rng{1729};
- return rng() != 14925250045015479985;
- }
- ''')
-
- # spdlog
- """
- ###### ######## ######## ## ####### ######
- ## ## ## ## ## ## ## ## ## ## ##
- ## ## ## ## ## ## ## ## ##
- ###### ######## ## ## ## ## ## ## ####
- ## ## ## ## ## ## ## ## ##
- ## ## ## ## ## ## ## ## ## ##
- ###### ## ######## ######## ####### ######
- """
- add_cases('spdlog', 'spdlog/spdlog', ['auto'], r'''
- #include <spdlog/spdlog.h>
-
- int main() {
- spdlog::info("Howdy!");
- }
- ''')
-
- # date
- """
- ######## ### ######## ########
- ## ## ## ## ## ##
- ## ## ## ## ## ##
- ## ## ## ## ## ######
- ## ## ######### ## ##
- ## ## ## ## ## ##
- ######## ## ## ## ########
- """
- add_cases(
- 'hinnant-date', 'hinnant/date', ['auto'], r'''
- #include <date/date.h>
- #include <iostream>
-
- int main() {
- auto now = std::chrono::system_clock::now();
- using namespace date::literals;
- auto year = date::year_month_day{date::floor<date::days>(now)}.year();
- std::cout << "The current year is " << year << '\n';
- return year < 2020_y;
- }
- ''')
-
-
- @pytest.mark.deps_test
- @pytest.mark.parametrize('case', CASES, ids=[c.dep for c in CASES])
- def test_dep(case: DepsCase, dds_pizza_catalog: Path, dds: DDS) -> None:
- case.setup_root(dds)
- dds.build(catalog_path=dds_pizza_catalog)
|