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