Skip to content

Commit f7e172d

Browse files
authored
[ItaniumDemangle][test] Factor demangler test-cases into file and sync into LLVM (#137947)
This patch turns the `libcxxabi/test/test_demangle.pass.cpp` into gtest unit-tests in `llvm/unittests/Demangle`. The main motivation for this is #137793, where we want to re-use the test-cases from the ItaniumDemangler to test our OutputBuffer implementation. `libcxxabi/test/test_demangle.pass.cpp` now only tests the `__cxa_demangle` API surface, not the underlying ItaniumDemangle implementation.
1 parent 46b3892 commit f7e172d

File tree

5 files changed

+60553
-30288
lines changed

5 files changed

+60553
-30288
lines changed

libcxxabi/src/demangle/cp-to-llvm.sh

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,30 +7,52 @@ set -e
77

88
cd $(dirname $0)
99
HDRS="ItaniumDemangle.h ItaniumNodes.def StringViewExtras.h Utility.h"
10+
TEST_HDRS="DemangleTestCases.inc"
1011
LLVM_DEMANGLE_DIR=$1
12+
LLVM_TESTING_DIR=
1113

1214
if [[ -z "$LLVM_DEMANGLE_DIR" ]]; then
1315
LLVM_DEMANGLE_DIR="../../../llvm/include/llvm/Demangle"
16+
LLVM_TESTING_DIR=$LLVM_DEMANGLE_DIR/../Testing/Demangle
1417
fi
1518

1619
if [[ ! -d "$LLVM_DEMANGLE_DIR" ]]; then
1720
echo "No such directory: $LLVM_DEMANGLE_DIR" >&2
1821
exit 1
1922
fi
2023

21-
read -p "This will overwrite the copies of $HDRS in $LLVM_DEMANGLE_DIR; are you sure? [y/N]" -n 1 -r ANSWER
24+
if [[ ! -d "$LLVM_TESTING_DIR" ]]; then
25+
LLVM_TESTING_DIR="../../../llvm/include/llvm/Testing/Demangle"
26+
fi
27+
28+
if [[ ! -d "$LLVM_TESTING_DIR" ]]; then
29+
echo "No such directory: $LLVM_TESTING_DIR" >&2
30+
exit 1
31+
fi
32+
33+
read -p "This will overwrite the copies of $HDRS in $LLVM_DEMANGLE_DIR and $TEST_HDRS in $LLVM_TESTING_DIR; are you sure? [y/N]" -n 1 -r ANSWER
2234
echo
2335

24-
if [[ $ANSWER =~ ^[Yy]$ ]]; then
25-
cp -f README.txt $LLVM_DEMANGLE_DIR
26-
chmod -w $LLVM_DEMANGLE_DIR/README.txt
27-
for I in $HDRS ; do
28-
rm -f $LLVM_DEMANGLE_DIR/$I
29-
dash=$(echo "$I---------------------------" | cut -c -27 |\
30-
sed 's|[^-]*||')
31-
sed -e '1s|^//=*-* .*\..* -*.*=*// *$|//===--- '"$I $dash"'-*- mode:c++;eval:(read-only-mode) -*-===//|' \
32-
-e '2s|^// *$|// Do not edit! See README.txt.|' \
33-
$I >$LLVM_DEMANGLE_DIR/$I
34-
chmod -w $LLVM_DEMANGLE_DIR/$I
36+
copy_files() {
37+
local src=$1
38+
local dst=$2
39+
local hdrs=$3
40+
41+
cp -f README.txt $dst
42+
chmod -w $dst/README.txt
43+
44+
for I in $hdrs ; do
45+
rm -f $dst/$I
46+
dash=$(echo "$I---------------------------" | cut -c -27 |\
47+
sed 's|[^-]*||')
48+
sed -e '1s|^//=*-* .*\..* -*.*=*// *$|//===--- '"$I $dash"'-*- mode:c++;eval:(read-only-mode) -*-===//|' \
49+
-e '2s|^// *$|// Do not edit! See README.txt.|' \
50+
$src/$I >$dst/$I
51+
chmod -w $dst/$I
3552
done
53+
}
54+
55+
if [[ $ANSWER =~ ^[Yy]$ ]]; then
56+
copy_files . $LLVM_DEMANGLE_DIR $HDRS
57+
copy_files ../../test $LLVM_TESTING_DIR $TEST_HDRS
3658
fi

0 commit comments

Comments
 (0)