0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

GoogleTest+カバレッジMemo

Posted at

GoogleTestの実行ファイルを
1ケースごとフィルタかけてカバレッジ出力(lcov)するBashのメモ

google_lcov.sh
#!/bin/bash

# 引数チェック
if [ $# -ne 1 ]; then
	echo "引数を設定してください"
	exit
fi

# google test リスト取得
list_test=$(./"$1" --gtest_list_tests)

count=1
for el in $list_test; do

	if [[ $el =~ .*\. ]]; then
		case_name=$el
	else
		# 検査実行
		"./$1" --gtest_filter="$case_name$el"

		# フォルダ作成
		mkdir_name=$(printf %02d $count)."$case_name$el"
		mkdir "$mkdir_name"

		find_path=$(find ./ -name "*.gcda")
		declare -A tmp_map

		# 一意の*gcda格納ディレクトリを取得
		for el2 in $find_path; do
			tmp_map[$(dirname "$el2")]=''
		done
		
		# lcovオプション作成
		uniq_dir_name=${!tmp_map[@]}
		for el2 in $uniq_dir_name; do
			lcov_d_options+="-d .""$el2"" "
		done

		# ディレクトリ移動
		cd "./$mkdir_name" || exit

		# カバレッジ出力
		lcov -c $lcov_d_options -o lcov.info
		genhtml lcov.info -o ./info

		# 元のディレクトリに戻る
		cd ../

		# 前の出力の削除
		# ちょっと微妙だけど
		find ./ -name "*.gcda" -exec rm {} \;

		((count++)) || true
	fi
done

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?