Skip to content

Commit 9393f47

Browse files
authored
Update run_tests.sh
1 parent d25c135 commit 9393f47

File tree

1 file changed

+16
-20
lines changed

1 file changed

+16
-20
lines changed

run_tests.sh

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,29 @@
11
#!/bin/bash
2-
32
set -e
43

5-
# Determine which branch to compare against: master or main
4+
# Determine base branch by looking at the upstream. If no upstream is set, fall back to "master".
65
detect_base_branch() {
7-
if git rev-parse --verify master >/dev/null 2>&1; then
8-
echo "master"
9-
elif git rev-parse --verify main >/dev/null 2>&1; then
10-
echo "main"
6+
# Try to get the upstream name, e.g. "origin/master" or "origin/main"
7+
if base="$(git rev-parse --abbrev-ref --symbolic-full-name @{u} 2>/dev/null)"; then
8+
echo "$base"
119
else
12-
echo "Error: neither 'master' nor 'main' exists in this repository." >&2
13-
exit 1
10+
echo "master"
1411
fi
1512
}
1613

17-
# Find all directories (under start_dir) that contain a CMakeLists.txt
14+
# Find all directories under start_dir that contain a CMakeLists.txt
1815
find_cmake_subdirs() {
1916
local start_dir="$1"
20-
# print the parent directory of each CMakeLists.txt, remove duplicates, sort
2117
find "$start_dir" -type f -name 'CMakeLists.txt' -printf '%h\n' | sort -u
2218
}
2319

24-
# Find all directories (under start_dir) that contain a __init__.py (Python packages)
20+
# Find all directories under start_dir that contain a __init__.py
2521
find_python_subdirs() {
2622
local start_dir="$1"
2723
find "$start_dir" -type f -name '__init__.py' -printf '%h\n' | sort -u
2824
}
2925

30-
# Get list of files changed since last base-branch commit
26+
# Get the list of files changed since the last commit on base branch
3127
get_modified_files() {
3228
local base_branch
3329
base_branch="$(detect_base_branch)"
@@ -38,18 +34,18 @@ test_cpp_projects() {
3834
local current_dir
3935
current_dir=$(pwd)
4036

41-
# All C++ project directories (where CMakeLists.txt lives)
37+
# Find every directory that has a CMakeLists.txt
4238
local all_subdirs
4339
all_subdirs=$(find_cmake_subdirs .)
4440

45-
# Files modified in this PR relative to base branch
41+
# Which files changed in this PR (relative to base)
4642
local modified_files
4743
modified_files=$(get_modified_files)
4844

49-
# Filter to only those C++ subdirs in which at least one file was modified
45+
# Filter to only those C++ subdirs where at least one file was modified
5046
local modified_subdirs=""
5147
for subdir in $all_subdirs; do
52-
# strip leading ./ if present when comparing to git output
48+
# strip leading "./" for comparison against git output
5349
local sub="${subdir#./}"
5450
if echo "$modified_files" | grep -q "^$sub/"; then
5551
modified_subdirs="$modified_subdirs $subdir"
@@ -78,7 +74,7 @@ test_cpp_projects() {
7874
mkdir -p build && cd build
7975
trap cleanup EXIT
8076

81-
# hide cmake/make output
77+
# Hide cmake/make output
8278
cmake .. 1>/dev/null 2>&1 && make 1>/dev/null 2>&1
8379

8480
cpp_test_log="$current_dir/cpp_test_$(echo "$subdir" | tr '/' '_').log"
@@ -110,15 +106,15 @@ test_python_projects() {
110106
local current_dir
111107
current_dir=$(pwd)
112108

113-
# All Python project directories (where __init__.py lives)
109+
# Find every directory that has an __init__.py
114110
local all_subdirs
115111
all_subdirs=$(find_python_subdirs .)
116112

117-
# Files modified in this PR relative to base branch
113+
# Which files changed in this PR (relative to base)
118114
local modified_files
119115
modified_files=$(get_modified_files)
120116

121-
# Filter to only those Python subdirs in which at least one file was modified
117+
# Filter to only those Python subdirs where at least one file was modified
122118
local modified_subdirs=""
123119
for subdir in $all_subdirs; do
124120
local sub="${subdir#./}"

0 commit comments

Comments
 (0)