Skip to content

Commit 0061a86

Browse files
committed
print in color and allows to pass the seed has an argument for the test scripts
1 parent 264875e commit 0061a86

1 file changed

Lines changed: 47 additions & 63 deletions

File tree

test/diff/diff_source.sh

Lines changed: 47 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,84 +1,68 @@
1-
seed=$(date +%s)
2-
# seed=${SEED:-$EPOCHSECONDS}
3-
4-
# setup_output() {
5-
6-
# # already initialized? -> do nothing
7-
# [ -n "${_msolve_test_output:-}" ] && return
8-
# _msolve_test_output=1
9-
10-
# # defaults (safe for logs / CI / pipes)
11-
# isatty=0
12-
# use_color=0
13-
# use_cr=0
14-
15-
# # No colored output (default)
16-
# colseed=""
17-
# colexit=""
18-
# std=""
19-
20-
# # Last character after normal exit
21-
# lastcharexit="\n"
22-
23-
# # Detect terminal on stderr (diagnostics channel)
24-
# if [ -t 2 ] && [ -n "$TERM" ] && [ "$TERM" != dumb ]; then
25-
# isatty=1
26-
# use_color=1
27-
# use_cr=1
28-
# fi
29-
30-
# # Colored output
31-
# if [ "$use_color" -eq 1 ]; then
32-
# # colseed='\033[0;96m' # High Intensity Light blue.
33-
# colseed=$(tput setaf 14) # High Intensity Light blue.
34-
# # colexit='\033[0;93m' # High Intensity Yellow.
35-
# colexit=$(tput setaf 11) # High Intensity Yellow.
36-
# # std='\033[0m'
37-
# std=$(tput sgr0)
38-
# fi
39-
40-
# # Carriage return afer normal exit
41-
# if [ "$use_cr" -eq 1 ]; then
42-
# lastcharexit="\r"
43-
# fi
44-
# }
1+
seed=${SEED:-$(date +%s)}
2+
3+
setup_output() {
4+
5+
# already initialized? -> do nothing
6+
[ -n "${_msolve_test_output:-}" ] && return
7+
_msolve_test_output=1
8+
9+
# defaults (safe for logs / CI / pipes)
10+
isatty=0
11+
use_color=0
12+
use_cr=0
13+
14+
# No colored output (default)
15+
colseed=""
16+
colexit=""
17+
std=""
18+
19+
# Last character after normal exit
20+
lastcharexit="\n"
21+
22+
# Detect terminal on stderr (diagnostics channel)
23+
if [ -t 2 ] && [ -n "$TERM" ] && [ "$TERM" != dumb ]; then
24+
isatty=1
25+
use_color=1
26+
use_cr=1
27+
fi
28+
29+
# Colored output
30+
if [ "$use_color" -eq 1 ]; then
31+
# colseed='\033[0;96m' # High Intensity Light blue.
32+
colseed=$(tput setaf 14) # High Intensity Light blue.
33+
# colexit='\033[0;93m' # High Intensity Yellow.
34+
colexit=$(tput setaf 11) # High Intensity Yellow.
35+
# std='\033[0m'
36+
std=$(tput sgr0)
37+
fi
38+
39+
# Carriage return afer normal exit
40+
if [ "$use_cr" -eq 1 ]; then
41+
lastcharexit="\r"
42+
fi
43+
}
4544

4645
# print the seed in color
4746
print_seed() {
48-
printf "SEED $seed\n" >&2
47+
setup_output
48+
printf "${beforeseed}${colseed}SEED${std}: %-10d " $seed >&2
4949
}
5050

51-
52-
# print_seed() {
53-
# setup_output
54-
# printf "${beforeseed}${colseed}SEED${std}: %-10d " $seed >&2
55-
# }
56-
5751
print_seed
5852

5953
# print a last character depending on the output stream
6054
normal_exit() {
61-
:
55+
printf "$lastcharexit" >&2
6256
}
6357

64-
# normal_exit() {
65-
# printf "$lastcharexit" >&2
66-
# }
67-
6858

6959
# print the exit code in color
7060
print_exit() {
7161
local excode=$1
72-
printf "EXIT: $excode\n" >&2
62+
printf "${colexit}EXIT${std}: $excode\n" >&2
7363
exit "$excode"
7464
}
7565

76-
# print_exit() {
77-
# local excode=$1
78-
# printf "${colexit}EXIT${std}: $excode\n" >&2
79-
# exit "$excode"
80-
# }
81-
8266
# each diff_example.sh is built by running msolve on $file.ms
8367
# with options -L 0 -l 2 -t 1
8468
# if the execution fails, print_exit 1

0 commit comments

Comments
 (0)