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 2.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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': 'TestProject',
  39. 'version': '0.0.0',
  40. 'namespace': 'test',
  41. }
  42. tmp_project.library_json = {'name': 'TestLibrary'}
  43. tmp_project.build()
  44. assert (tmp_project.build_root / 'compile_commands.json').is_file()
  45. assert list(tmp_project.build_root.glob('libTestLibrary.*')) != []
  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. TEST_PACKAGE: PackageJSON = {
  55. 'name': 'test-pkg',
  56. 'version': '0.2.2',
  57. 'namespace': 'test',
  58. }
  59. def test_empty_with_pkg_json(tmp_project: Project) -> None:
  60. tmp_project.package_json = TEST_PACKAGE
  61. tmp_project.build()
  62. def test_empty_sdist_create(tmp_project: Project) -> None:
  63. tmp_project.package_json = TEST_PACKAGE
  64. tmp_project.pkg_create()
  65. assert tmp_project.build_root.joinpath('test-pkg@0.2.2.tar.gz').is_file(), \
  66. 'The expected sdist tarball was not generated'