1#!/bin/bash
2
3
4# Copyright (c) 2024 Huawei Device Co., Ltd.
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8
9#     http://www.apache.org/licenses/LICENSE-2.0
10
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17# Description: output test results
18
19set -e
20
21function usage() {
22    echo "Usage: $0 [--mode <debug|release>]"
23    exit 1
24}
25
26modes=("debug" "release")
27clean_command="hvigorw clean"
28debug_compile_command="hvigorw assembleHap"
29release_compile_command="hvigorw assembleApp"
30
31while [[ $# -gt 0 ]]; do
32    case "$1" in
33        --mode)
34            modes=("$2")
35            shift 2
36            ;;
37        *)
38            usage
39            ;;
40    esac
41done
42
43file="./entry/src/main/ets/pages/Index.ets"
44if [ ! -f "$file" ]; then
45    echo "Error: File $file does not exist in the current directory."
46    exit 1
47fi
48
49function compile_and_collect_result() {
50    local compile_command=$1
51    compile_output=$($compile_command 2>&1)
52    if [ $? -eq 0 ]; then
53        echo "Pass"
54    else
55        echo "Fail"
56    fi
57}
58
59function compile_and_display() {
60    local mode=$1
61    local compile_command=$2
62
63    $clean_command
64    full_result=$(compile_and_collect_result "$compile_command")
65
66    echo "\nconsole.log('$mode')" >> "$file"
67
68    increment_result=$(compile_and_collect_result "$compile_command")
69
70    printf "%-20s %-10s\n" "cases" "result ($mode)"
71    printf "%-20s %-10s\n" "full build" "$full_result"
72    printf "%-20s %-10s\n" "incremental build" "$increment_result"
73}
74
75function get_compile_command() {
76    local mode=$1
77    if [ "$mode" == "debug" ]; then
78        echo $debug_compile_command
79    elif [ "$mode" == "release" ]; then
80        echo $release_compile_command
81    else
82        echo ""
83    fi
84}
85
86for mode in "${modes[@]}"; do
87    compile_command=$(get_compile_command "$mode")
88    if [ -n "$compile_command" ]; then
89        compile_and_display "$mode" "$compile_command"
90    else
91        echo "Invalid mode. Use 'debug' or 'release'."
92        usage
93    fi
94done
95