2
0

appveyor.pm 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. #***************************************************************************
  2. # _ _ ____ _
  3. # Project ___| | | | _ \| |
  4. # / __| | | | |_) | |
  5. # | (__| |_| | _ <| |___
  6. # \___|\___/|_| \_\_____|
  7. #
  8. # Copyright (C) 2020, Daniel Stenberg, <daniel@haxx.se>, et al.
  9. # Copyright (C) 2020, 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. ###########################################################################
  23. use strict;
  24. use warnings;
  25. my %APPVEYOR_TEST_NAMES;
  26. sub appveyor_check_environment {
  27. if(defined $ENV{'APPVEYOR_API_URL'} && $ENV{'APPVEYOR_API_URL'}) {
  28. return 1;
  29. }
  30. return 0;
  31. }
  32. sub appveyor_create_test_result {
  33. my ($curl, $testnum, $testname)=@_;
  34. $testname =~ s/\\/\\\\/g;
  35. $testname =~ s/\'/\\\'/g;
  36. $testname =~ s/\"/\\\"/g;
  37. my $appveyor_baseurl="$ENV{'APPVEYOR_API_URL'}";
  38. my $appveyor_result=`$curl --silent --noproxy "*" \\
  39. --header "Content-Type: application/json" \\
  40. --data "
  41. {
  42. 'testName': '$testname',
  43. 'testFramework': 'runtests.pl',
  44. 'fileName': 'tests/data/test$testnum',
  45. 'outcome': 'Running'
  46. }
  47. " \\
  48. "$appveyor_baseurl/api/tests"`;
  49. print "AppVeyor API result: $appveyor_result\n" if ($appveyor_result);
  50. $APPVEYOR_TEST_NAMES{$testnum}=$testname;
  51. }
  52. sub appveyor_update_test_result {
  53. my ($curl, $testnum, $error, $start, $stop)=@_;
  54. my $testname=$APPVEYOR_TEST_NAMES{$testnum};
  55. if(!defined $testname) {
  56. return;
  57. }
  58. if(!defined $stop) {
  59. $stop = $start;
  60. }
  61. my $appveyor_duration = sprintf("%.0f", ($stop-$start)*1000);
  62. my $appveyor_outcome;
  63. my $appveyor_category;
  64. if($error == 2) {
  65. $appveyor_outcome = 'Ignored';
  66. $appveyor_category = 'Error';
  67. }
  68. elsif($error < 0) {
  69. $appveyor_outcome = 'NotRunnable';
  70. $appveyor_category = 'Warning';
  71. }
  72. elsif(!$error) {
  73. $appveyor_outcome = 'Passed';
  74. $appveyor_category = 'Information';
  75. }
  76. else {
  77. $appveyor_outcome = 'Failed';
  78. $appveyor_category = 'Error';
  79. }
  80. my $appveyor_baseurl="$ENV{'APPVEYOR_API_URL'}";
  81. my $appveyor_result=`$curl --silent --noproxy "*" --request PUT \\
  82. --header "Content-Type: application/json" \\
  83. --data "
  84. {
  85. 'testName': '$testname',
  86. 'testFramework': 'runtests.pl',
  87. 'fileName': 'tests/data/test$testnum',
  88. 'outcome': '$appveyor_outcome',
  89. 'durationMilliseconds': $appveyor_duration,
  90. 'ErrorMessage': 'Test $testnum $appveyor_outcome'
  91. }
  92. " \\
  93. "$appveyor_baseurl/api/tests"`;
  94. print "AppVeyor API result: $appveyor_result\n" if ($appveyor_result);
  95. if($appveyor_category eq 'Error') {
  96. $appveyor_result=`$curl --silent --noproxy "*" \\
  97. --header "Content-Type: application/json" \\
  98. --data "
  99. {
  100. 'message': '$appveyor_outcome: $testname',
  101. 'category': '$appveyor_category',
  102. 'details': 'Test $testnum $appveyor_outcome'
  103. }
  104. " \\
  105. "$appveyor_baseurl/api/build/messages"`;
  106. print "AppVeyor API result: $appveyor_result\n" if ($appveyor_result);
  107. }
  108. }
  109. 1;