Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

test_compile_deps.py 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. import subprocess
  2. import time
  3. import pytest
  4. from tests import dds, DDS, dds_fixture_conf_1
  5. from dds_ci import proc
  6. ## #############################################################################
  7. ## #############################################################################
  8. ## The test project in this directory contains a single application and two
  9. ## functions, each defined in a separate file. The two functions each return
  10. ## an integer, and the application exit code will be the difference between
  11. ## the two integers. (They are passed through std::abs(), so it is always a
  12. ## positive integer). The default value is 32 in both functions.
  13. ## #############################################################################
  14. ## The purpose of these tests is to ensure the reliability of the compilation
  15. ## dependency database. Having a miscompile because there was a failure to
  16. ## detect file changes is a catastrophic bug!
  17. def build_and_get_rc(dds: DDS) -> int:
  18. dds.build()
  19. app = dds.build_dir / ('app' + dds.exe_suffix)
  20. return proc.run(app).returncode
  21. def test_simple_rebuild(dds: DDS):
  22. """
  23. Check that changing a source file will update the resulting application.
  24. """
  25. assert build_and_get_rc(dds) == 0
  26. dds.scope.enter_context(
  27. dds.set_contents(
  28. 'src/1.cpp',
  29. b'''
  30. int value_1() { return 33; }
  31. ''',
  32. ))
  33. # 33 - 32 = 1
  34. assert build_and_get_rc(dds) == 1
  35. def test_rebuild_header_change(dds: DDS):
  36. """Change the content of the header which defines the values"""
  37. assert build_and_get_rc(dds) == 0
  38. dds.scope.enter_context(
  39. dds.set_contents(
  40. 'src/values.hpp',
  41. b'''
  42. const int first_value = 63;
  43. const int second_value = 88;
  44. ''',
  45. ))
  46. assert build_and_get_rc(dds) == (88 - 63)
  47. def test_partial_build_rebuild(dds: DDS):
  48. """
  49. Change the content of a header, but cause one user of that header to fail
  50. compilation. The fact that compilation fails means it is still `out-of-date`,
  51. and will need to be compiled after we have fixed it up.
  52. """
  53. assert build_and_get_rc(dds) == 0
  54. dds.scope.enter_context(
  55. dds.set_contents(
  56. 'src/values.hpp',
  57. b'''
  58. const int first_value_q = 6;
  59. const int second_value_q = 99;
  60. ''',
  61. ))
  62. # Header now causes errors in 1.cpp and 2.cpp
  63. with pytest.raises(subprocess.CalledProcessError):
  64. dds.build()
  65. # Fix 1.cpp
  66. dds.scope.enter_context(
  67. dds.set_contents(
  68. 'src/1.cpp',
  69. b'''
  70. #include "./values.hpp"
  71. int value_1() { return first_value_q; }
  72. ''',
  73. ))
  74. # We will still see a failure, but now the DB will record the updated values.hpp
  75. with pytest.raises(subprocess.CalledProcessError):
  76. dds.build()
  77. # Should should raise _again_, even though we've successfully compiled one
  78. # of the two files with the changed `values.hpp`, because `2.cpp` still
  79. # has a pending update
  80. with pytest.raises(subprocess.CalledProcessError):
  81. dds.build()
  82. dds.scope.enter_context(
  83. dds.set_contents(
  84. 'src/2.cpp',
  85. b'''
  86. #include "./values.hpp"
  87. int value_2() { return second_value_q; }
  88. ''',
  89. ))
  90. # We should now compile and link to get the updated value
  91. assert build_and_get_rc(dds) == (99 - 6)