forked from vesoft-inc/nebula
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcxx-compiler-usability-test.sh
executable file
·90 lines (78 loc) · 2.4 KB
/
cxx-compiler-usability-test.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#! /usr/bin/env bash
# Copyright (c) 2019 vesoft inc. All rights reserved.
#
# This source code is licensed under Apache 2.0 License,
# attached with Common Clause Condition 1.0, found in the LICENSES directory.
cxx_cmd=${CXX:-g++}
link_flags="-std=c++14 -static-libstdc++ -static-libgcc"
# Compile source from stdin and run.
# input envs:
# $output, which is the expected output.
# $exit_code, which is the exit status of the compiled program.
function compile-and-run {
local tmpdir=$(mktemp -q -d /tmp/nebula-compiler-test.XXXX 2>/dev/null)
[[ -z $tmpdir ]] && {
echo "Failed"
echo "Create directory /tmp/nebula-compiler-test.XXXX failed."
exit 1;
}
local exe=$tmpdir/a.out
local logfile=$tmpdir/testing.log
$cxx_cmd $link_flags $extra_flags -g0 -x c++ - -o $exe &> $logfile
[[ $? -eq 0 ]] || {
echo "Failed"
echo "See $logfile for details." 1>&2;
exit 1;
}
true_output=$($exe 2>&1)
true_exit_code=$?
# Convert non-zero to 1
[[ $true_exit_code -ne 0 ]] && true_exit_code=1
if [[ -n "$output" ]] && [[ ! "$true_output" = "$output" ]]
then
echo "expected: $output" >> $logfile
echo "actual: $true_output" >> $logfile
echo "Failed"
echo "See $logfile for details." 1>&2;
exit 1;
fi
if [[ -n "$exit_code" ]] && [[ $true_exit_code -ne $exit_code ]]
then
echo "expected: $exit_code" >> $logfile
echo "actual: $true_exit_code" >> $logfile
echo "Failed"
echo "See $logfile for details." 1>&2;
exit 1;
fi
rm -rf $tmpdir
}
# make_unique, regex, (templated)lambda, move capture
echo -n "Performing regular C++14 tests..."
output="Nebula" exit_code=0 compile-and-run <<EOF
#include <iostream>
#include <string>
#include <regex>
#include <memory>
int main() {
auto hello = std::make_unique<std::string>("Hello");
auto _666_ = [hello = std::move(hello)] (auto bravo) {
return *hello + " " + *bravo;
} (std::make_unique<std::string>("Nebula Graph"));
std::smatch sm;
if (std::regex_match(_666_, sm,
std::regex(R"(^(Hello) (Nebula) (Graph)$)"))) {
std::cout << sm[2].str() << std::endl;
}
return 0;
}
EOF
echo "OK"
echo -n "Performing LeakSanitizer tests..."
exit_code=1 extra_flags="-fsanitize=address -g" compile-and-run <<EOF
int main() {
new int;
return 0;
}
EOF
echo "OK"
exit 0