Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion scripts/presubmit-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ IS_DOCUMENTATION_PR=0
# Returns true if PR only contains the given file regexes.
# Parameters: $1 - file regexes, space separated.
function pr_only_contains() {
[[ -z "$(echo "${CHANGED_FILES}" | grep -v \(${1// /\\|}\)$))" ]]
[[ -z "$(echo "${CHANGED_FILES}" | grep -v "\(${1// /\\|}\)$")" ]]
}

# List changed files in the current PR.
Expand Down
56 changes: 56 additions & 0 deletions test/unit/presubmit-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,55 @@ function test_custom_runners_fail_fast() {
}
}

function test_exempt_md() {
source $(dirname $0)/../../scripts/presubmit-tests.sh

function list_changed_files() {
echo "README.md"
echo "OWNERS"
echo "foo.png"
}
initialize_environment
(( IS_DOCUMENTATION_PR )) || test_failed "README.md is documentation"
(( ! IS_PRESUBMIT_EXEMPT_PR )) || test_failed "README.md is not exempt"
}

function test_exempt_no_md() {
source $(dirname $0)/../../scripts/presubmit-tests.sh

function list_changed_files() {
echo "OWNERS"
echo "AUTHORS"
}
initialize_environment
(( IS_DOCUMENTATION_PR )) || test_failed "OWNERS is considered documentation"
(( IS_PRESUBMIT_EXEMPT_PR )) || test_failed "OWNERS is exempt"
}

function test_exempt_md_code() {
source $(dirname $0)/../../scripts/presubmit-tests.sh

function list_changed_files() {
echo "OWNERS"
echo "README.md"
echo "foo.go"
}
initialize_environment
(( ! IS_DOCUMENTATION_PR )) || test_failed "README.md is documentation"
(( ! IS_PRESUBMIT_EXEMPT_PR )) || test_failed "foo.go is not exempt"
}

function test_exempt_code() {
source $(dirname $0)/../../scripts/presubmit-tests.sh

function list_changed_files() {
echo "foo.go"
}
initialize_environment
(( ! IS_DOCUMENTATION_PR )) || test_failed "foo.go is not documentation"
(( ! IS_PRESUBMIT_EXEMPT_PR )) || test_failed "foo.go is not exempt"
}

function run_markdown_build_tests() {
function list_changed_files() {
echo "README.md"
Expand All @@ -190,6 +239,13 @@ function run_main() {
main
}

echo ">> Testing presubmit exempt flow"

test_function ${SUCCESS} "Changed files in commit" call_function_pre test_exempt_md
test_function ${SUCCESS} "Changed files in commit" call_function_pre test_exempt_no_md
test_function ${SUCCESS} "Changed files in commit" call_function_pre test_exempt_md_code
test_function ${SUCCESS} "Changed files in commit" call_function_pre test_exempt_code

echo ">> Testing custom test runners"

test_function ${SUCCESS} "Test passed" call_function_pre test_custom_runners_all run_main
Expand Down