Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

test_basics.py 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. from subprocess import CalledProcessError
  2. import time
  3. import pytest
  4. from dds_ci import paths
  5. from dds_ci.testing.error import expect_error_marker
  6. from dds_ci.testing import Project, PackageJSON
  7. def test_build_empty(tmp_project: Project) -> None:
  8. """Check that dds is okay with building an empty project directory"""
  9. tmp_project.build()
  10. def test_lib_with_app_only(tmp_project: Project) -> None:
  11. """Test that dds can build a simple application"""
  12. tmp_project.write('src/foo.main.cpp', r'int main() {}')
  13. tmp_project.build()
  14. assert (tmp_project.build_root / f'foo{paths.EXE_SUFFIX}').is_file()
  15. def test_build_simple(tmp_project: Project) -> None:
  16. """
  17. Test that dds can build a simple library, and handles rebuilds correctly.
  18. """
  19. # Build a bad project
  20. tmp_project.write('src/f.cpp', 'syntax error')
  21. with pytest.raises(CalledProcessError):
  22. tmp_project.build()
  23. # Now we can build:
  24. tmp_project.write('src/f.cpp', r'void f() {}')
  25. tmp_project.build()
  26. # Writing again will build again:
  27. time.sleep(1) # Sleep long enough to register a file change
  28. tmp_project.write('src/f.cpp', r'bad again')
  29. with pytest.raises(CalledProcessError):
  30. tmp_project.build()
  31. def test_simple_lib(tmp_project: Project) -> None:
  32. """
  33. Test that dds can build a simple library withsome actual content, and that
  34. the manifest files will affect the output name.
  35. """
  36. tmp_project.write('src/foo.cpp', 'int the_answer() { return 42; }')
  37. tmp_project.package_json = {
  38. 'name': 'test-project',
  39. 'version': '0.0.0',
  40. 'namespace': 'test',
  41. }
  42. tmp_project.library_json = {'name': 'test-library'}
  43. tmp_project.build()
  44. assert (tmp_project.build_root / 'compile_commands.json').is_file(), 'compdb was not created'
  45. assert list(tmp_project.build_root.glob('libtest-library.*')) != [], 'No archive was created'
  46. def test_lib_with_just_test(tmp_project: Project) -> None:
  47. tmp_project.write('src/foo.test.cpp', 'int main() {}')
  48. tmp_project.build()
  49. assert tmp_project.build_root.joinpath(f'test/foo{paths.EXE_SUFFIX}').is_file()
  50. def test_lib_with_failing_test(tmp_project: Project) -> None:
  51. tmp_project.write('src/foo.test.cpp', 'int main() { return 2; }')
  52. with expect_error_marker('build-failed-test-failed'):
  53. tmp_project.build()
  54. def test_invalid_names(tmp_project: Project) -> None:
  55. tmp_project.package_json = {
  56. 'name': 'test',
  57. 'version': '1.2.3',
  58. 'namespace': 'test',
  59. 'depends': ['invalid name@1.2.3']
  60. }
  61. with expect_error_marker('invalid-pkg-dep-name'):
  62. tmp_project.build()
  63. with expect_error_marker('invalid-pkg-dep-name'):
  64. tmp_project.pkg_create()
  65. with expect_error_marker('invalid-pkg-dep-name'):
  66. tmp_project.dds.build_deps(['invalid name@1.2.3'])
  67. tmp_project.package_json = {
  68. **tmp_project.package_json,
  69. 'name': 'invalid name',
  70. 'depends': [],
  71. }
  72. with expect_error_marker('invalid-pkg-name'):
  73. tmp_project.build()
  74. with expect_error_marker('invalid-pkg-name'):
  75. tmp_project.pkg_create()
  76. tmp_project.package_json = {
  77. **tmp_project.package_json,
  78. 'name': 'simple_name',
  79. 'namespace': 'invalid namespace',
  80. }
  81. with expect_error_marker('invalid-pkg-namespace-name'):
  82. tmp_project.build()
  83. with expect_error_marker('invalid-pkg-namespace-name'):
  84. tmp_project.pkg_create()
  85. tmp_project.package_json = {
  86. 'name': 'test',
  87. 'version': '1.2.3',
  88. 'namespace': 'test',
  89. 'depends': [],
  90. }
  91. tmp_project.library_json = {'name': 'invalid name'}
  92. # Need a source directory for dds to load the lib manifest
  93. tmp_project.write('src/empty.hpp', '')
  94. with expect_error_marker('invalid-lib-name'):
  95. tmp_project.build()
  96. TEST_PACKAGE: PackageJSON = {
  97. 'name': 'test-pkg',
  98. 'version': '0.2.2',
  99. 'namespace': 'test',
  100. }
  101. def test_empty_with_pkg_json(tmp_project: Project) -> None:
  102. tmp_project.package_json = TEST_PACKAGE
  103. tmp_project.build()
  104. def test_empty_sdist_create(tmp_project: Project) -> None:
  105. tmp_project.package_json = TEST_PACKAGE
  106. tmp_project.pkg_create()
  107. assert tmp_project.build_root.joinpath('test-pkg@0.2.2.tar.gz').is_file(), \
  108. 'The expected sdist tarball was not generated'