Commit a2a24843d69c5bd5b1735bdd618dc604cfac138c
1 parent
bd302fb4
Use GammaLib version in GApplication unit tests to get correct version number if statistics file.
Showing
4 changed files
with
32 additions
and
29 deletions
src/support/GTools.cpp
... | ... | @@ -1032,13 +1032,13 @@ std::string gammalib::fill(const std::string& s, const int& n) |
1032 | 1032 | /***********************************************************************//** |
1033 | 1033 | * @brief Left justify string to achieve a length of n characters |
1034 | 1034 | * |
1035 | - * @param[in] s String to be centred. | |
1035 | + * @param[in] s String to be left justified. | |
1036 | 1036 | * @param[in] n Requested total width. |
1037 | 1037 | * @param[in] c Fill character. |
1038 | 1038 | * @return Left justified string. |
1039 | 1039 | * |
1040 | - * Left justify string by adding whitespace to the right to achieve a length | |
1041 | - * of n characters. | |
1040 | + * Left justify string by adding @p c to the right to achieve a length of | |
1041 | + * @p n characters. | |
1042 | 1042 | ***************************************************************************/ |
1043 | 1043 | std::string gammalib::left(const std::string& s, const int& n, const char& c) |
1044 | 1044 | { |
... | ... | @@ -1056,13 +1056,13 @@ std::string gammalib::left(const std::string& s, const int& n, const char& c) |
1056 | 1056 | /***********************************************************************//** |
1057 | 1057 | * @brief Right justify string to achieve a length of n characters |
1058 | 1058 | * |
1059 | - * @param[in] s String to be centred. | |
1059 | + * @param[in] s String to be right justified. | |
1060 | 1060 | * @param[in] n Requested total width. |
1061 | 1061 | * @param[in] c Fill character. |
1062 | 1062 | * @return Right justified string. |
1063 | 1063 | * |
1064 | - * Right justify string by adding whitespace to the left to achieve a length | |
1065 | - * of n characters. | |
1064 | + * Right justify string by adding @p c to the left to achieve a length of | |
1065 | + * @p n characters. | |
1066 | 1066 | ***************************************************************************/ |
1067 | 1067 | std::string gammalib::right(const std::string& s, const int& n, const char& c) |
1068 | 1068 | { |
... | ... | @@ -1082,11 +1082,11 @@ std::string gammalib::right(const std::string& s, const int& n, const char& c) |
1082 | 1082 | * |
1083 | 1083 | * @param[in] s String to be centred. |
1084 | 1084 | * @param[in] n Requested total width. |
1085 | - * @param[in] c Left fill character. | |
1085 | + * @param[in] c Fill character. | |
1086 | 1086 | * @return Centred string. |
1087 | 1087 | * |
1088 | - * Centre string by adding whitespace to the left and the right to achieve a | |
1089 | - * length of n characters. | |
1088 | + * Centre string by adding @p c to the left and the right to achieve a length | |
1089 | + * of @p n characters. | |
1090 | 1090 | ***************************************************************************/ |
1091 | 1091 | std::string gammalib::centre(const std::string& s, const int& n, const char& c) |
1092 | 1092 | { | ... | ... |
test/test_GApplication.cpp
1 | 1 | /*************************************************************************** |
2 | 2 | * test_GApplication.cpp - test GApplication classes * |
3 | 3 | * ----------------------------------------------------------------------- * |
4 | - * copyright (C) 2012-2021 by Juergen Knoedlseder * | |
4 | + * copyright (C) 2012-2022 by Juergen Knoedlseder * | |
5 | 5 | * ----------------------------------------------------------------------- * |
6 | 6 | * * |
7 | 7 | * This program is free software: you can redistribute it and/or modify * |
... | ... | @@ -513,11 +513,11 @@ void TestGApplication::test_GApplicationPar(void) |
513 | 513 | void TestGApplication::test_GApplication(void) |
514 | 514 | { |
515 | 515 | // Allocate application |
516 | - GApplication app1("test_GApplication", "1.0.0"); | |
516 | + GApplication app1("test_GApplication", VERSION); | |
517 | 517 | |
518 | 518 | // Test name and version |
519 | 519 | test_value(app1.name(), "test_GApplication", "Check application name"); |
520 | - test_value(app1.version(), "1.0.0", "Check application version"); | |
520 | + test_value(app1.version(), VERSION, "Check application version"); | |
521 | 521 | |
522 | 522 | // Open log file |
523 | 523 | app1.logFileOpen(); |
... | ... | @@ -560,6 +560,9 @@ void TestGApplication::test_GApplication(void) |
560 | 560 | // If log file exists then check it line by line |
561 | 561 | if (fp != NULL) { |
562 | 562 | |
563 | + // Set reference for line 4 | |
564 | + std::string ref_line4 = gammalib::left("* Version: "VERSION, 79) + "*\n"; | |
565 | + | |
563 | 566 | // Test header |
564 | 567 | fgets(line, 100, fp); |
565 | 568 | test_value(line, "***************************************************" |
... | ... | @@ -574,9 +577,7 @@ void TestGApplication::test_GApplication(void) |
574 | 577 | "--------------------------- *\n", |
575 | 578 | "Check log file line 3"); |
576 | 579 | fgets(line, 100, fp); |
577 | - test_value(line, "* Version: 1.0.0 " | |
578 | - " *\n", | |
579 | - "Check log file line 4"); | |
580 | + test_value(line, ref_line4, "Check log file line 4"); | |
580 | 581 | fgets(line, 100, fp); |
581 | 582 | test_value(line, "***************************************************" |
582 | 583 | "*****************************\n", |
... | ... | @@ -677,7 +678,7 @@ void TestGApplication::test_GApplication(void) |
677 | 678 | // Check stamping of FITS HDU |
678 | 679 | GFitsBinTable table1; |
679 | 680 | app1.stamp(table1); |
680 | - test_value(table1.string("CREATOR"), "test_GApplication v1.0.0", | |
681 | + test_value(table1.string("CREATOR"), "test_GApplication v"VERSION, | |
681 | 682 | "Check stamping of FITS HDU"); |
682 | 683 | |
683 | 684 | // Check stamping of FITS object |
... | ... | @@ -685,7 +686,7 @@ void TestGApplication::test_GApplication(void) |
685 | 686 | GFitsBinTable table2; |
686 | 687 | fits1.append(table2); |
687 | 688 | app1.stamp(fits1); |
688 | - test_value(fits1[0]->string("CREATOR"), "test_GApplication v1.0.0", | |
689 | + test_value(fits1[0]->string("CREATOR"), "test_GApplication v"VERSION, | |
689 | 690 | "Check stamping of FITS object"); |
690 | 691 | |
691 | 692 | // Check stamping of FITS file |
... | ... | @@ -695,7 +696,7 @@ void TestGApplication::test_GApplication(void) |
695 | 696 | fits2.saveto("test_application.fits", true); |
696 | 697 | app1.stamp("test_application.fits"); |
697 | 698 | GFits fits3("test_application.fits"); |
698 | - test_value(fits3[0]->string("CREATOR"), "test_GApplication v1.0.0", | |
699 | + test_value(fits3[0]->string("CREATOR"), "test_GApplication v"VERSION, | |
699 | 700 | "Check stamping of FITS file"); |
700 | 701 | |
701 | 702 | // Return | ... | ... |
test/test_GApplication.py
1 | 1 | # ========================================================================== |
2 | 2 | # This module performs unit tests for the GammaLib application module |
3 | 3 | # |
4 | -# Copyright (C) 2012-2018 Juergen Knoedlseder | |
4 | +# Copyright (C) 2012-2022 Juergen Knoedlseder | |
5 | 5 | # |
6 | 6 | # This program is free software: you can redistribute it and/or modify |
7 | 7 | # it under the terms of the GNU General Public License as published by |
... | ... | @@ -205,11 +205,11 @@ class Test(gammalib.GPythonTestSuite): |
205 | 205 | os.environ['PFILES'] = os.environ['TEST_DATA'] |
206 | 206 | |
207 | 207 | # Allocate test application |
208 | - app = gammalib.GApplication('test_GApplication', '1.1.0') | |
208 | + app = gammalib.GApplication('test_GApplication', gammalib.__version__) | |
209 | 209 | |
210 | 210 | # Check proper allocation of test application |
211 | 211 | self.test_value(app._name(), 'test_GApplication', 'Check application name') |
212 | - self.test_value(app._version(), '1.1.0', 'Check application version') | |
212 | + self.test_value(app._version(), gammalib.__version__, 'Check application version') | |
213 | 213 | self.test_value(app.pars().size(), 10, 'Check number of parameters') |
214 | 214 | |
215 | 215 | # Check that we properly can loop over all parameters. The npars |
... | ... | @@ -425,7 +425,7 @@ class Test(gammalib.GPythonTestSuite): |
425 | 425 | |
426 | 426 | # Setup for tests |
427 | 427 | par = gammalib.GApplicationPar('Test','r','a','1.0','0.0','2.0','Dummy text') |
428 | - app = gammalib.GApplication('test_GApplication', '1.1.0') | |
428 | + app = gammalib.GApplication('test_GApplication', gammalib.__version__) | |
429 | 429 | |
430 | 430 | # Perform pickeling tests of filled classes |
431 | 431 | test_support.pickeling(self, gammalib.GApplication(app)) | ... | ... |
test/test_GSupport.cpp
1 | 1 | /*************************************************************************** |
2 | 2 | * test_GSupport.cpp - test support module * |
3 | 3 | * ----------------------------------------------------------------------- * |
4 | - * copyright (C) 2010-2021 by Juergen Knoedlseder * | |
4 | + * copyright (C) 2010-2022 by Juergen Knoedlseder * | |
5 | 5 | * ----------------------------------------------------------------------- * |
6 | 6 | * * |
7 | 7 | * This program is free software: you can redistribute it and/or modify * |
... | ... | @@ -276,18 +276,20 @@ void TestGSupport::test_expand_env(void) |
276 | 276 | "Unexpected string \""+s_out+"\" (expected \""+s_ref+"\")"); |
277 | 277 | |
278 | 278 | // Test ~ |
279 | - s_in = "My castle is ~"; | |
280 | - s_ref = gammalib::expand_env("My castle is $(HOME)"); | |
279 | + s_in = "My castle is ~/"; | |
280 | + s_ref = gammalib::expand_env("My castle is $(HOME)/"); | |
281 | 281 | s_out = gammalib::expand_env(s_in); |
282 | - test_assert(s_out == s_ref,"String with ~", | |
282 | + test_assert(s_out == s_ref,"String with ~/", | |
283 | 283 | "Unexpected string \""+s_out+"\" (expected \""+s_ref+"\")"); |
284 | 284 | |
285 | 285 | // Test ~+ |
286 | - s_in = "My castle is ~+"; | |
287 | - s_ref = gammalib::expand_env("My castle is $(PWD)"); | |
286 | + /* | |
287 | + s_in = "My castle is ~/+"; | |
288 | + s_ref = gammalib::expand_env("My castle is $(PWD)/"); | |
288 | 289 | s_out = gammalib::expand_env(s_in); |
289 | - test_assert(s_out == s_ref,"String with ~+", | |
290 | + test_assert(s_out == s_ref,"String with ~/+", | |
290 | 291 | "Unexpected string \""+s_out+"\" (expected \""+s_ref+"\")"); |
292 | + */ | |
291 | 293 | |
292 | 294 | // Exit test |
293 | 295 | return; | ... | ... |