You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

deps_test.py 16KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587
  1. import json
  2. from pathlib import Path
  3. from typing import NamedTuple, Sequence, List
  4. import pytest
  5. from tests import DDS, fileutil
  6. class DepsCase(NamedTuple):
  7. dep: str
  8. usage: str
  9. source: str
  10. def setup_root(self, dds: DDS):
  11. dds.scope.enter_context(
  12. fileutil.set_contents(
  13. dds.source_root / 'package.json',
  14. json.dumps({
  15. 'name': 'test-project',
  16. 'namespace': 'test',
  17. 'version': '0.0.0',
  18. 'depends': [self.dep],
  19. }).encode()))
  20. dds.scope.enter_context(
  21. fileutil.set_contents(
  22. dds.source_root / 'library.json',
  23. json.dumps({
  24. 'name': 'test',
  25. 'uses': [self.usage],
  26. }).encode()))
  27. dds.scope.enter_context(
  28. fileutil.set_contents(dds.source_root / 'src/test.test.cpp',
  29. self.source.encode()))
  30. CASES: List[DepsCase] = []
  31. def get_default_pkg_versions(pkg: str) -> Sequence[str]:
  32. catalog_json = Path(
  33. __file__).resolve().parent.parent.parent / 'catalog.json'
  34. catalog_dict = json.loads(catalog_json.read_text())
  35. return list(catalog_dict['packages'][pkg].keys())
  36. def add_cases(pkg: str, uses: str, versions: Sequence[str], source: str):
  37. if versions == ['auto']:
  38. versions = get_default_pkg_versions(pkg)
  39. for ver in versions:
  40. CASES.append(DepsCase(f'{pkg}@{ver}', uses, source))
  41. # magic_enum tests
  42. """
  43. ## ## ### ###### #### ###### ######## ## ## ## ## ## ##
  44. ### ### ## ## ## ## ## ## ## ## ### ## ## ## ### ###
  45. #### #### ## ## ## ## ## ## #### ## ## ## #### ####
  46. ## ### ## ## ## ## #### ## ## ###### ## ## ## ## ## ## ### ##
  47. ## ## ######### ## ## ## ## ## ## #### ## ## ## ##
  48. ## ## ## ## ## ## ## ## ## ## ## ### ## ## ## ##
  49. ## ## ## ## ###### #### ###### ####### ######## ## ## ####### ## ##
  50. """
  51. add_cases(
  52. 'magic_enum', 'neargye/magic_enum', ['auto'], r'''
  53. #include <magic_enum.hpp>
  54. #include <string_view>
  55. enum my_enum {
  56. foo,
  57. bar,
  58. };
  59. int main() {
  60. if (magic_enum::enum_name(my_enum::foo) != "foo") {
  61. return 1;
  62. }
  63. }
  64. ''')
  65. # Range-v3 tests
  66. """
  67. ######## ### ## ## ###### ######## ## ## #######
  68. ## ## ## ## ### ## ## ## ## ## ## ## ##
  69. ## ## ## ## #### ## ## ## ## ## ##
  70. ######## ## ## ## ## ## ## #### ###### ####### ## ## #######
  71. ## ## ######### ## #### ## ## ## ## ## ##
  72. ## ## ## ## ## ### ## ## ## ## ## ## ##
  73. ## ## ## ## ## ## ###### ######## ### #######
  74. """
  75. add_cases(
  76. 'range-v3', 'range-v3/range-v3', ['auto'], r'''
  77. #include <range/v3/algorithm/remove_if.hpp>
  78. #include <vector>
  79. #include <algorithm>
  80. int main() {
  81. std::vector<int> nums = {1, 2, 3, 5, 1, 4, 2, 7, 8, 0, 9};
  82. auto end = ranges::remove_if(nums, [](auto i) { return i % 2; });
  83. return std::distance(nums.begin(), end) != 5;
  84. }
  85. ''')
  86. # nlohmann-json
  87. """
  88. ## ## ## ####### ## ## ## ## ### ## ## ## ## ## ###### ####### ## ##
  89. ### ## ## ## ## ## ## ### ### ## ## ### ## ### ## ## ## ## ## ## ### ##
  90. #### ## ## ## ## ## ## #### #### ## ## #### ## #### ## ## ## ## ## #### ##
  91. ## ## ## ## ## ## ######### ## ### ## ## ## ## ## ## ## ## ## ####### ## ###### ## ## ## ## ##
  92. ## #### ## ## ## ## ## ## ## ######### ## #### ## #### ## ## ## ## ## ## ####
  93. ## ### ## ## ## ## ## ## ## ## ## ## ### ## ### ## ## ## ## ## ## ## ###
  94. ## ## ######## ####### ## ## ## ## ## ## ## ## ## ## ###### ###### ####### ## ##
  95. """
  96. add_cases('nlohmann-json', 'nlohmann/json', ['auto'], r'''
  97. #include <nlohmann/json.hpp>
  98. int main() {}
  99. ''')
  100. # ctre
  101. """
  102. ###### ######## ######## ########
  103. ## ## ## ## ## ##
  104. ## ## ## ## ##
  105. ## ## ######## ######
  106. ## ## ## ## ##
  107. ## ## ## ## ## ##
  108. ###### ## ## ## ########
  109. """
  110. add_cases(
  111. 'ctre', 'hanickadot/ctre', ['auto'], r'''
  112. #include <ctre.hpp>
  113. constexpr ctll::fixed_string MY_REGEX{"\\w+-[0-9]+"};
  114. int main() {
  115. auto [did_match] = ctre::match<MY_REGEX>("foo-44");
  116. if (!did_match) {
  117. return 1;
  118. }
  119. auto [did_match_2] = ctre::match<MY_REGEX>("bar-1ff");
  120. if (did_match_2) {
  121. return 2;
  122. }
  123. }
  124. ''')
  125. # fmt
  126. """
  127. ######## ## ## ########
  128. ## ### ### ##
  129. ## #### #### ##
  130. ###### ## ### ## ##
  131. ## ## ## ##
  132. ## ## ## ##
  133. ## ## ## ##
  134. """
  135. add_cases(
  136. 'fmt', 'fmt/fmt', ['auto'], r'''
  137. #include <fmt/core.h>
  138. int main() {
  139. fmt::print("Hello!");
  140. }
  141. ''')
  142. # Catch2
  143. """
  144. ###### ### ######## ###### ## ## #######
  145. ## ## ## ## ## ## ## ## ## ## ##
  146. ## ## ## ## ## ## ## ##
  147. ## ## ## ## ## ######### #######
  148. ## ######### ## ## ## ## ##
  149. ## ## ## ## ## ## ## ## ## ##
  150. ###### ## ## ## ###### ## ## #########
  151. """
  152. add_cases(
  153. 'catch2', 'catch2/catch2', ['auto'], r'''
  154. #include <catch2/catch_with_main.hpp>
  155. TEST_CASE("I am a test case") {
  156. CHECK((2 + 2) == 4);
  157. CHECK_FALSE((2 + 2) == 5);
  158. }
  159. ''')
  160. # Asio
  161. """
  162. ### ###### #### #######
  163. ## ## ## ## ## ## ##
  164. ## ## ## ## ## ##
  165. ## ## ###### ## ## ##
  166. ######### ## ## ## ##
  167. ## ## ## ## ## ## ##
  168. ## ## ###### #### #######
  169. """
  170. add_cases(
  171. 'asio', 'asio/asio', ['auto'], r'''
  172. #include <asio.hpp>
  173. int main() {
  174. asio::io_context ioc;
  175. int retcode = 12;
  176. ioc.post([&] {
  177. retcode = 0;
  178. });
  179. ioc.run();
  180. return retcode;
  181. }
  182. ''')
  183. # Abseil
  184. """
  185. ### ######## ###### ######## #### ##
  186. ## ## ## ## ## ## ## ## ##
  187. ## ## ## ## ## ## ## ##
  188. ## ## ######## ###### ###### ## ##
  189. ######### ## ## ## ## ## ##
  190. ## ## ## ## ## ## ## ## ##
  191. ## ## ######## ###### ######## #### ########
  192. """
  193. add_cases(
  194. 'abseil', 'abseil/abseil', ['auto'], r'''
  195. #include <absl/strings/str_cat.h>
  196. int main() {
  197. std::string_view foo = "foo";
  198. std::string_view bar = "bar";
  199. auto cat = absl::StrCat(foo, bar);
  200. return cat != "foobar";
  201. }
  202. ''')
  203. # Zlib
  204. """
  205. ######## ## #### ########
  206. ## ## ## ## ##
  207. ## ## ## ## ##
  208. ## ## ## ########
  209. ## ## ## ## ##
  210. ## ## ## ## ##
  211. ######## ######## #### ########
  212. """
  213. add_cases(
  214. 'zlib', 'zlib/zlib', ['auto'], r'''
  215. #include <zlib.h>
  216. #include <cassert>
  217. int main() {
  218. ::z_stream strm = {};
  219. deflateInit(&strm, 6);
  220. const char buffer[] = "foo bar baz";
  221. strm.next_in = (Bytef*)buffer;
  222. strm.avail_in = sizeof buffer;
  223. char dest[256] = {};
  224. strm.next_out = (Bytef*)dest;
  225. strm.avail_out = sizeof dest;
  226. auto ret = deflate(&strm, Z_FINISH);
  227. deflateEnd(&strm);
  228. assert(ret == Z_STREAM_END);
  229. assert(strm.avail_in == 0);
  230. assert(strm.avail_out != sizeof dest);
  231. }
  232. ''')
  233. # sol2
  234. """
  235. ###### ####### ## #######
  236. ## ## ## ## ## ## ##
  237. ## ## ## ## ##
  238. ###### ## ## ## #######
  239. ## ## ## ## ##
  240. ## ## ## ## ## ##
  241. ###### ####### ######## #########
  242. """
  243. add_cases(
  244. 'sol2', 'sol2/sol2', ['3.2.1', '3.2.0', '3.0.3', '3.0.2'], r'''
  245. #include <sol/sol.hpp>
  246. int main() {
  247. sol::state lua;
  248. int x = 0;
  249. lua.set_function("beepboop", [&]{ ++x; });
  250. lua.script("beepboop()");
  251. return x != 1;
  252. }
  253. ''')
  254. # pegtl
  255. """
  256. ######## ######## ###### ######## ##
  257. ## ## ## ## ## ## ##
  258. ## ## ## ## ## ##
  259. ######## ###### ## #### ## ##
  260. ## ## ## ## ## ##
  261. ## ## ## ## ## ##
  262. ## ######## ###### ## ########
  263. """
  264. add_cases(
  265. 'pegtl', 'tao/pegtl', ['auto'], r'''
  266. #include <tao/pegtl.hpp>
  267. using namespace tao::pegtl;
  268. struct sign : one<'+', '-'> {};
  269. struct integer : seq<opt<sign>, plus<digit>> {};
  270. int main() {
  271. tao::pegtl::string_input str{"+44", "[test string]"};
  272. tao::pegtl::parse<integer>(str);
  273. }
  274. ''')
  275. # Boost.PFR
  276. """
  277. ######## ####### ####### ###### ######## ######## ######## ########
  278. ## ## ## ## ## ## ## ## ## ## ## ## ## ##
  279. ## ## ## ## ## ## ## ## ## ## ## ## ##
  280. ######## ## ## ## ## ###### ## ######## ###### ########
  281. ## ## ## ## ## ## ## ## ## ## ## ##
  282. ## ## ## ## ## ## ## ## ## ### ## ## ## ##
  283. ######## ####### ####### ###### ## ### ## ## ## ##
  284. """
  285. add_cases(
  286. 'boost.pfr', 'boost/pfr', ['auto'], r'''
  287. #include <iostream>
  288. #include <string>
  289. #include <boost/pfr/precise.hpp>
  290. struct some_person {
  291. std::string name;
  292. unsigned birth_year;
  293. };
  294. int main() {
  295. some_person val{"Edgar Allan Poe", 1809};
  296. std::cout << boost::pfr::get<0>(val) // No macro!
  297. << " was born in " << boost::pfr::get<1>(val); // Works with any aggregate initializables!
  298. return boost::pfr::get<0>(val) != "Edgar Allan Poe";
  299. }
  300. ''')
  301. # Boost.LEAF
  302. """
  303. ## ######## ### ########
  304. ## ## ## ## ##
  305. ## ## ## ## ##
  306. ## ###### ## ## ######
  307. ## ## ######### ##
  308. ## ## ## ## ##
  309. ######## ######## ## ## ##
  310. """
  311. add_cases(
  312. 'boost.leaf', 'boost/leaf', ['auto'], r'''
  313. #include <boost/leaf/all.hpp>
  314. namespace leaf = boost::leaf;
  315. int main() {
  316. return leaf::try_handle_all(
  317. [&]() -> leaf::result<int> {
  318. return 0;
  319. },
  320. [](leaf::error_info const&) {
  321. return 32;
  322. }
  323. );
  324. }
  325. ''')
  326. # Boost.mp11
  327. """
  328. ######## ####### ####### ###### ######## ## ## ######## ## ##
  329. ## ## ## ## ## ## ## ## ## ### ### ## ## #### ####
  330. ## ## ## ## ## ## ## ## #### #### ## ## ## ##
  331. ######## ## ## ## ## ###### ## ## ### ## ######## ## ##
  332. ## ## ## ## ## ## ## ## ## ## ## ## ##
  333. ## ## ## ## ## ## ## ## ## ### ## ## ## ## ##
  334. ######## ####### ####### ###### ## ### ## ## ## ###### ######
  335. """
  336. add_cases(
  337. 'boost.mp11', 'boost/mp11', ['auto'], r'''
  338. #include <boost/mp11.hpp>
  339. int main() {
  340. return boost::mp11::mp_false() == boost::mp11::mp_true();
  341. }
  342. ''')
  343. # libsodium
  344. """
  345. ## #### ######## ###### ####### ######## #### ## ## ## ##
  346. ## ## ## ## ## ## ## ## ## ## ## ## ## ### ###
  347. ## ## ## ## ## ## ## ## ## ## ## ## #### ####
  348. ## ## ######## ###### ## ## ## ## ## ## ## ## ### ##
  349. ## ## ## ## ## ## ## ## ## ## ## ## ## ##
  350. ## ## ## ## ## ## ## ## ## ## ## ## ## ## ##
  351. ######## #### ######## ###### ####### ######## #### ####### ## ##
  352. """
  353. add_cases(
  354. 'libsodium', 'sodium/sodium', ['auto'], r'''
  355. #include <sodium.h>
  356. #include <algorithm>
  357. int main() {
  358. char arr[256] = {};
  359. ::randombytes_buf(arr, sizeof arr);
  360. for (auto b : arr) {
  361. if (b != '\x00') {
  362. return 0;
  363. }
  364. }
  365. return 1;
  366. }
  367. ''')
  368. # toml++
  369. """
  370. ######## ####### ## ## ##
  371. ## ## ## ### ### ## ## ##
  372. ## ## ## #### #### ## ## ##
  373. ## ## ## ## ### ## ## ###### ######
  374. ## ## ## ## ## ## ## ##
  375. ## ## ## ## ## ## ## ##
  376. ## ####### ## ## ########
  377. """
  378. add_cases(
  379. 'tomlpp', 'tomlpp/tomlpp', ['auto'], r'''
  380. #include <toml++/toml.h>
  381. #include <string_view>
  382. int main() {
  383. std::string_view sv = R"(
  384. [library]
  385. something = "cats"
  386. person = "Joe"
  387. )";
  388. toml::table tbl = toml::parse(sv);
  389. return tbl["library"]["person"] != "Joe";
  390. }
  391. ''')
  392. # Inja
  393. """
  394. #### ## ## ## ###
  395. ## ### ## ## ## ##
  396. ## #### ## ## ## ##
  397. ## ## ## ## ## ## ##
  398. ## ## #### ## ## #########
  399. ## ## ### ## ## ## ##
  400. #### ## ## ###### ## ##
  401. """
  402. add_cases(
  403. 'inja', 'inja/inja', ['2.0.0', '2.0.1', '2.1.0', '2.2.0'], r'''
  404. #include <inja/inja.hpp>
  405. #include <nlohmann/json.hpp>
  406. int main() {
  407. nlohmann::json data;
  408. data["foo"] = "bar";
  409. auto result = inja::render("foo {{foo}}", data);
  410. return result != "foo bar";
  411. }
  412. ''')
  413. # Cereal
  414. """
  415. ###### ######## ######## ######## ### ##
  416. ## ## ## ## ## ## ## ## ##
  417. ## ## ## ## ## ## ## ##
  418. ## ###### ######## ###### ## ## ##
  419. ## ## ## ## ## ######### ##
  420. ## ## ## ## ## ## ## ## ##
  421. ###### ######## ## ## ######## ## ## ########
  422. """
  423. add_cases(
  424. 'cereal', 'cereal/cereal', ['auto'], r'''
  425. #include <cereal/types/memory.hpp>
  426. #include <cereal/types/string.hpp>
  427. #include <cereal/archives/binary.hpp>
  428. #include <sstream>
  429. struct something {
  430. int a, b, c;
  431. std::string str;
  432. template <typename Ar>
  433. void serialize(Ar& ar) {
  434. ar(a, b, c, str);
  435. }
  436. };
  437. int main() {
  438. std::stringstream strm;
  439. cereal::BinaryOutputArchive ar{strm};
  440. something s;
  441. ar(s);
  442. return 0;
  443. }
  444. ''')
  445. # pcg
  446. """
  447. ######## ###### ######
  448. ## ## ## ## ## ##
  449. ## ## ## ##
  450. ######## ## ## ####
  451. ## ## ## ##
  452. ## ## ## ## ##
  453. ## ###### ######
  454. """
  455. add_cases(
  456. 'pcg-cpp', 'pcg/pcg-cpp', ['auto'], r'''
  457. #include <pcg_random.hpp>
  458. #include <iostream>
  459. int main() {
  460. pcg64 rng{1729};
  461. return rng() != 14925250045015479985;
  462. }
  463. ''')
  464. # spdlog
  465. """
  466. ###### ######## ######## ## ####### ######
  467. ## ## ## ## ## ## ## ## ## ## ##
  468. ## ## ## ## ## ## ## ## ##
  469. ###### ######## ## ## ## ## ## ## ####
  470. ## ## ## ## ## ## ## ## ##
  471. ## ## ## ## ## ## ## ## ## ##
  472. ###### ## ######## ######## ####### ######
  473. """
  474. add_cases(
  475. 'spdlog', 'spdlog/spdlog', ['auto'], r'''
  476. #include <spdlog/spdlog.h>
  477. int main() {
  478. spdlog::info("Howdy!");
  479. }
  480. ''')
  481. # date
  482. """
  483. ######## ### ######## ########
  484. ## ## ## ## ## ##
  485. ## ## ## ## ## ##
  486. ## ## ## ## ## ######
  487. ## ## ######### ## ##
  488. ## ## ## ## ## ##
  489. ######## ## ## ## ########
  490. """
  491. add_cases(
  492. 'hinnant-date', 'hinnant/date', ['auto'], r'''
  493. #include <date/date.h>
  494. #include <iostream>
  495. int main() {
  496. auto now = std::chrono::system_clock::now();
  497. using namespace date::literals;
  498. auto year = date::year_month_day{date::floor<date::days>(now)}.year();
  499. std::cout << "The current year is " << year << '\n';
  500. return year < 2020_y;
  501. }
  502. ''')
  503. @pytest.mark.deps_test
  504. @pytest.mark.parametrize('case', CASES, ids=[c.dep for c in CASES])
  505. def test_dep(case: DepsCase, dds: DDS) -> None:
  506. case.setup_root(dds)
  507. dds.build()