appveyor.pm 4.0 KB

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