Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

80 lines
2.5KB

  1. from subprocess import CalledProcessError
  2. import time
  3. import pytest
  4. from dds_ci import paths
  5. from dds_ci.testing import Project, PackageJSON
  6. def test_build_empty(tmp_project: Project) -> None:
  7. """Check that dds is okay with building an empty project directory"""
  8. tmp_project.build()
  9. def test_lib_with_app_only(tmp_project: Project) -> None:
  10. """Test that dds can build a simple application"""
  11. tmp_project.write('src/foo.main.cpp', r'int main() {}')
  12. tmp_project.build()
  13. assert (tmp_project.build_root / f'foo{paths.EXE_SUFFIX}').is_file()
  14. def test_build_simple(tmp_project: Project) -> None:
  15. """
  16. Test that dds can build a simple library, and handles rebuilds correctly.
  17. """
  18. # Build a bad project
  19. tmp_project.write('src/f.cpp', 'syntax error')
  20. with pytest.raises(CalledProcessError):
  21. tmp_project.build()
  22. # Now we can build:
  23. tmp_project.write('src/f.cpp', r'void f() {}')
  24. tmp_project.build()
  25. # Writing again will build again:
  26. time.sleep(1) # Sleep long enough to register a file change
  27. tmp_project.write('src/f.cpp', r'bad again')
  28. with pytest.raises(CalledProcessError):
  29. tmp_project.build()
  30. def test_simple_lib(tmp_project: Project) -> None:
  31. """
  32. Test that dds can build a simple library withsome actual content, and that
  33. the manifest files will affect the output name.
  34. """
  35. tmp_project.write('src/foo.cpp', 'int the_answer() { return 42; }')
  36. tmp_project.package_json = {
  37. 'name': 'TestProject',
  38. 'version': '0.0.0',
  39. 'namespace': 'test',
  40. }
  41. tmp_project.library_json = {'name': 'TestLibrary'}
  42. tmp_project.build()
  43. assert (tmp_project.build_root / 'compile_commands.json').is_file()
  44. assert list(tmp_project.build_root.glob('libTestLibrary.*')) != []
  45. def test_lib_with_just_test(tmp_project: Project) -> None:
  46. tmp_project.write('src/foo.test.cpp', 'int main() {}')
  47. tmp_project.build()
  48. assert tmp_project.build_root.joinpath(f'test/foo{paths.EXE_SUFFIX}').is_file()
  49. TEST_PACKAGE: PackageJSON = {
  50. 'name': 'test-pkg',
  51. 'version': '0.2.2',
  52. 'namespace': 'test',
  53. }
  54. def test_empty_with_pkg_json(tmp_project: Project) -> None:
  55. tmp_project.package_json = TEST_PACKAGE
  56. tmp_project.build()
  57. def test_empty_sdist_create(tmp_project: Project) -> None:
  58. tmp_project.package_json = TEST_PACKAGE
  59. tmp_project.sdist_create()
  60. assert tmp_project.build_root.joinpath('test-pkg@0.2.2.tar.gz').is_file(), \
  61. 'The expected sdist tarball was not generated'