1 // RUN: %check_clang_tidy %s cata-tests-must-restore-global-state %t -- -plugins=%cata_plugin -- -isystem %cata_include 2 3 bool fov_3d; 4 int fov_3d_z_range; 5 6 namespace N 7 { 8 bool another_option; 9 } 10 11 // The check identifies test files as being those which define the TEST_CASE 12 // macro. 13 #define TEST_CASE(name) 14 15 template<typename T> 16 class restore_on_out_of_scope 17 { 18 public: 19 explicit restore_on_out_of_scope( T &t_in ); 20 }; 21 f0()22void f0() 23 { 24 fov_3d = true; 25 // CHECK-MESSAGES: warning: Test alters global variable 'fov_3d'. You must ensure it is restored using 'restore_on_out_of_scope'. [cata-tests-must-restore-global-state] 26 } 27 f1()28void f1() 29 { 30 restore_on_out_of_scope<int> restore( fov_3d_z_range ); 31 fov_3d_z_range = 1; 32 } 33 f1b()34void f1b() 35 { 36 fov_3d_z_range = 1; 37 // CHECK-MESSAGES: warning: Test alters global variable 'fov_3d_z_range'. You must ensure it is restored using 'restore_on_out_of_scope'. [cata-tests-must-restore-global-state] 38 } 39 f2()40void f2() 41 { 42 int local_var; 43 local_var = 1; 44 } 45 f3()46void f3() 47 { 48 N::another_option = true; 49 // CHECK-MESSAGES: warning: Test alters global variable 'another_option'. You must ensure it is restored using 'restore_on_out_of_scope'. [cata-tests-must-restore-global-state] 50 } 51 52 struct weather_type_id {}; 53 54 struct weather_manager { 55 weather_type_id weather_override; 56 }; 57 58 weather_manager &get_weather(); 59 f4()60void f4() 61 { 62 get_weather().weather_override = {}; 63 // CHECK-MESSAGES: warning: Test assigns to weather_override. It should instead use scoped_weather_override. [cata-tests-must-restore-global-state] 64 } 65