xref: /aosp_15_r20/external/lz4/tests/unicode_lint.sh (revision 27162e4e17433d5aa7cb38e7b6a433a09405fc7f)
1#!/bin/bash
2
3# `unicode_lint.sh' determines whether source files under the ./lib/, ./tests/ and ./programs/ directories
4# contain Unicode characters, and fails if any do.
5#
6# See https://github.com/lz4/lz4/issues/1018
7
8echo "Ensure no unicode character is present in source files *.{c,h}"
9pass=true
10
11# Scan ./lib/ for Unicode in source (*.c, *.h) files
12echo "Scanning lib/"
13result=$(
14	find ./lib/ -regex '.*\.\(c\|h\)$' -exec grep -P -n "[^\x00-\x7F]" {} \; -exec echo "{}: FAIL" \;
15)
16if [[ $result ]]; then
17	echo "$result"
18	pass=false
19fi
20
21# Scan ./programs/ for Unicode in source (*.c, *.h) files
22echo "Scanning programs/"
23result=$(
24	find ./programs/ -regex '.*\.\(c\|h\)$' -exec grep -P -n "[^\x00-\x7F]" {} \; -exec echo "{}: FAIL" \;
25)
26if [[ $result ]]; then
27	echo "$result"
28	pass=false
29fi
30
31# Scan ./tests/ for Unicode in source (*.c, *.h) files
32echo "Scanning tests/"
33result=$(
34	find ./tests/ -regex '.*\.\(c\|h\)$' -exec grep -P -n "[^\x00-\x7F]" {} \; -exec echo "{}: FAIL" \;
35)
36if [[ $result ]]; then
37	echo "$result"
38	pass=false
39fi
40
41if [ "$pass" = true ]; then
42	echo "All tests successful: no unicode character detected"
43	echo "Result: PASS"
44	exit 0
45else
46	echo "Result: FAIL"
47	exit 1
48fi
49