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

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