xref: /curl/tests/libtest/test1022.pl (revision 2bc1d775)
1#!/usr/bin/env perl
2#***************************************************************************
3#                                  _   _ ____  _
4#  Project                     ___| | | |  _ \| |
5#                             / __| | | | |_) | |
6#                            | (__| |_| |  _ <| |___
7#                             \___|\___/|_| \_\_____|
8#
9# Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
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# Determine if curl-config --version matches the curl --version
26if ( $#ARGV != 2 )
27{
28    print "Usage: $0 curl-config-script curl-version-output-file version|vernum\n";
29    exit 3;
30}
31
32my $what=$ARGV[2];
33
34# Read the output of curl --version
35open(CURL, "$ARGV[1]") || die "Can't open curl --version list in $ARGV[1]\n";
36$_ = <CURL>;
37chomp;
38/libcurl\/([\.\d]+((-DEV)|(-\d+))?)/;
39my $version = $1;
40close CURL;
41
42my $curlconfigversion;
43
44# Read the output of curl-config --version/--vernum
45open(CURLCONFIG, "sh $ARGV[0] --$what|") || die "Can't get curl-config --$what list\n";
46$_ = <CURLCONFIG>;
47chomp;
48my $filever=$_;
49if ( $what eq "version" ) {
50    if($filever =~ /^libcurl ([\.\d]+((-DEV)|(-\d+))?)$/) {
51        $curlconfigversion = $1;
52    }
53    else {
54        $curlconfigversion = "illegal value";
55    }
56}
57else { # "vernum" case
58    # Convert hex version to decimal for comparison's sake
59    if($filever =~ /^(..)(..)(..)$/) {
60        $curlconfigversion = hex($1) . "." . hex($2) . "." . hex($3);
61    }
62    else {
63        $curlconfigversion = "illegal value";
64    }
65
66    # Strip off the -DEV from the curl version if it's there
67    $version =~ s/-\w*$//;
68}
69close CURLCONFIG;
70
71my $different = $version ne $curlconfigversion;
72if ($different || !$version) {
73    print "Mismatch in --version:\n";
74    print "curl:        $version\n";
75    print "curl-config: $curlconfigversion\n";
76    exit 1;
77}
78