appveyor.pm 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. #***************************************************************************
  2. # _ _ ____ _
  3. # Project ___| | | | _ \| |
  4. # / __| | | | |_) | |
  5. # | (__| |_| | _ <| |___
  6. # \___|\___/|_| \_\_____|
  7. #
  8. # Copyright (C) 2020-2022, Daniel Stenberg, <daniel@haxx.se>, et al.
  9. # Copyright (C) 2020-2022, Marc Hoersken, <info@marc-hoersken.de>
  10. #
  11. # This software is licensed as described in the file COPYING, which
  12. # you should have received as part of this distribution. The terms
  13. # are also available at https://curl.se/docs/copyright.html.
  14. #
  15. # You may opt to use, copy, modify, merge, publish, distribute and/or sell
  16. # copies of the Software, and permit persons to whom the Software is
  17. # furnished to do so, under the terms of the COPYING file.
  18. #
  19. # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  20. # KIND, either express or implied.
  21. #
  22. # SPDX-License-Identifier: curl
  23. #
  24. ###########################################################################
  25. use strict;
  26. use warnings;
  27. my %APPVEYOR_TEST_NAMES;
  28. sub appveyor_check_environment {
  29. if(defined $ENV{'APPVEYOR_API_URL'} && $ENV{'APPVEYOR_API_URL'}) {
  30. return 1;
  31. }
  32. return 0;
  33. }
  34. sub appveyor_create_test_result {
  35. my ($curl, $testnum, $testname)=@_;
  36. $testname =~ s/\\/\\\\/g;
  37. $testname =~ s/\'/\\\'/g;
  38. $testname =~ s/\"/\\\"/g;
  39. my $appveyor_baseurl="$ENV{'APPVEYOR_API_URL'}";
  40. my $appveyor_result=`$curl --silent --noproxy "*" \\
  41. --header "Content-Type: application/json" \\
  42. --data "
  43. {
  44. 'testName': '$testname',
  45. 'testFramework': 'runtests.pl',
  46. 'fileName': 'tests/data/test$testnum',
  47. 'outcome': 'Running'
  48. }
  49. " \\
  50. "$appveyor_baseurl/api/tests"`;
  51. print "AppVeyor API result: $appveyor_result\n" if ($appveyor_result);
  52. $APPVEYOR_TEST_NAMES{$testnum}=$testname;
  53. }
  54. sub appveyor_update_test_result {
  55. my ($curl, $testnum, $error, $start, $stop)=@_;
  56. my $testname=$APPVEYOR_TEST_NAMES{$testnum};
  57. if(!defined $testname) {
  58. return;
  59. }
  60. if(!defined $stop) {
  61. $stop = $start;
  62. }
  63. my $appveyor_duration = sprintf("%.0f", ($stop-$start)*1000);
  64. my $appveyor_outcome;
  65. my $appveyor_category;
  66. if($error == 2) {
  67. $appveyor_outcome = 'Ignored';
  68. $appveyor_category = 'Error';
  69. }
  70. elsif($error < 0) {
  71. $appveyor_outcome = 'NotRunnable';
  72. $appveyor_category = 'Warning';
  73. }
  74. elsif(!$error) {
  75. $appveyor_outcome = 'Passed';
  76. $appveyor_category = 'Information';
  77. }
  78. else {
  79. $appveyor_outcome = 'Failed';
  80. $appveyor_category = 'Error';
  81. }
  82. my $appveyor_baseurl="$ENV{'APPVEYOR_API_URL'}";
  83. my $appveyor_result=`$curl --silent --noproxy "*" --request PUT \\
  84. --header "Content-Type: application/json" \\
  85. --data "
  86. {
  87. 'testName': '$testname',
  88. 'testFramework': 'runtests.pl',
  89. 'fileName': 'tests/data/test$testnum',
  90. 'outcome': '$appveyor_outcome',
  91. 'durationMilliseconds': $appveyor_duration,
  92. 'ErrorMessage': 'Test $testnum $appveyor_outcome'
  93. }
  94. " \\
  95. "$appveyor_baseurl/api/tests"`;
  96. print "AppVeyor API result: $appveyor_result\n" if ($appveyor_result);
  97. if($appveyor_category eq 'Error') {
  98. $appveyor_result=`$curl --silent --noproxy "*" \\
  99. --header "Content-Type: application/json" \\
  100. --data "
  101. {
  102. 'message': '$appveyor_outcome: $testname',
  103. 'category': '$appveyor_category',
  104. 'details': 'Test $testnum $appveyor_outcome'
  105. }
  106. " \\
  107. "$appveyor_baseurl/api/build/messages"`;
  108. print "AppVeyor API result: $appveyor_result\n" if ($appveyor_result);
  109. }
  110. }
  111. 1;