Skip to content

grep用テスト#6

Closed
hpmy-dev wants to merge 1 commit into
masterfrom
improvement/grep_test
Closed

grep用テスト#6
hpmy-dev wants to merge 1 commit into
masterfrom
improvement/grep_test

Conversation

@hpmy-dev

Copy link
Copy Markdown
Owner

grep 関連の機能リファクタリングとテスト強化

概要

CGrepAgent / CDlgGrep に対するリファクタリングと、Grep 機能の回帰テストを追加

変更規模: 11 ファイル / テストコード約 2,500 行・138 テスト追加

関連

sakura-editor#2439
sakura-editor#2459
sakura-editor#1689

主な変更内容

  1. 並列 Grep 実装: Producer-Consumer パターンによるサブフォルダー単位バッチ処理(CGrepAgent::DoGrep
  2. static ヘルパ切り出し: FormatGrepResultLine / BuildGrepHeader / BuildGrepFooter(テスト容易化)
  3. CDlgGrep API 整理: DetermineDefaultExcludePatterns / BuildHwndFileToken / IsHwndFileToken / GetPackedGFileString*.* 補完 / 自テキスト検索時の履歴非汚染
  4. テスト 5 ファイル: 新規 3 + 既存改修 2

リファクタリングの目的とテスト実行方法

プロダクトコードから HWND 非依存の純粋ロジックを static 関数として切り出すことで、エディタ全体を起動せずにユニットテストから直接検証可能にした。以下のコマンドで機能単位の確認ができる。

CGrepAgent 切り出し関数

FormatGrepResultLine / BuildGrepHeader / BuildGrepFooter / CreateFolders / ChopYen / AddTail / OnBeforeClose

tests1.exe --gtest_filter=CGrepAgentTest.*:CGrepAgent.*:GrepAgentFlowTest.*

CDlgGrep 切り出し関数

DetermineDefaultExcludePatterns / BuildHwndFileToken / IsHwndFileToken / GetPackedGFileString

tests1.exe --gtest_filter=CDlgGrepTest.*

DoGrepFileWorker(既存 + 異常系)

tests1.exe --gtest_filter=GrepRealFileTest.*:GrepIrregularTest.*

全件

tests1.exe

継続課題

test-grep-irregular.cpp ソース

IRR-16: 長大コマンドライン引数テスト(コメントアウト中)

DEBUG_TRACEDebugOutW(バッファサイズ 16,000 文字)でバッファ溢れが発生し、Debug ビルドで ::DebugBreak() によるクラッシュが起きる。-GKEY 以外の全オプション引数(-GREPR-GFILE-GFOLDER 等)に対しても CCommandLine::CheckCommandLine で文字数制限をかけた後に復活
テストで発覚したので動確は出来てそう。


変更ファイル一覧

# ファイル 種別 変更内容
1 sakura_core/agent/CGrepAgent.h 改修 SGrepFileTask、static ヘルパ 3 関数、DoGrepFileWorker / DoGrepTreeEnumerate 宣言
2 sakura_core/agent/CGrepAgent.cpp 改修 並列 Grep 本体、static ヘルパ実装、DoGrepFileWorker / DoGrepTreeEnumerate 実装
3 sakura_core/dlg/CDlgGrep.h 改修 DetermineDefaultExcludePatterns / BuildHwndFileToken / IsHwndFileToken 宣言
4 sakura_core/dlg/CDlgGrep.cpp 改修 上記 3 関数実装、GetPackedGFileString *.* 補完、履歴汚染防止
5 sakura_core/tests1.vcxproj 改修 テスト 4 ファイル追加
6 sakura_core/tests1.vcxproj.filters 改修 テスト 4 ファイル追加
7 src/test/cpp/tests1/test-ccommandline.cpp 改修 既存コメント体裁統一 + Phase 2-A 25 テスト追加
8 src/test/cpp/tests1/test-cdlggrep.cpp 新規 26 テスト
9 src/test/cpp/tests1/test-cgrepagent-flow.cpp 新規 20 テスト
10 src/test/cpp/tests1/test-grep-irregular.cpp 新規 46 テスト(+ IRR-16 コメントアウト 1)
11 src/test/cpp/tests1/test-grep.cpp 新規 41 テスト

テスト一覧(ソース出現順)

📂 test-grep.cpp(41 テスト)

既存相当(20 テスト)

# スイート テスト名
1 GrepSearchEngine LiteralSearchCaseSensitivity
2 GrepRealFileTest JapaneseLiteralSearchAcrossMixedEncodings
3 GrepRealFileTest RegexCompileAndMatch
4 CGrepEnumKeys ParseRegexExcludePattern
5 CGrepEnumKeys ParseFileAndFolderKeysWithDefaults
6 CGrepEnumKeys AbsolutePathInSearchKeyIsRejected
7 CCodeMediator AutoDetectBomAndDefaultCode
8 GrepRealFileTest EnumerateFiles_FiltersByExtensionAndExcludeKey
9 GrepRealFileTest EnumerateFolders_ExcludesByHashKey
10 GrepRealFileTest EnumerateFiles_SubfolderRecursion
11 GrepRealFileTest FileWorker_BasicLiteralHitsInUtf8File
12 GrepRealFileTest FileWorker_CaseSensitivityIsRespected
13 GrepRealFileTest FileWorker_RegexHitsInUtf8File
14 GrepRealFileTest FileWorker_JapaneseAcrossEncodings
15 GrepRealFileTest FileWorker_32000LinesIsSearchable
16 GrepRealFileTest FileWorker_CancelTerminatesScan
17 GrepRealFileTest MultiThread_HitCountMatchesSingleThread
18 GrepRealFileTest MultiThread_StressNoDeadlockAcrossRepeats
19 GrepRealFileTest RegexExclude_AppliedToEnumeratedFiles
20 GrepRealFileTest RegexExclude_InvalidPatternFailsToCompile

Phase 2-B 追加(21 テスト)

# テスト名 検証観点
21 SplitPattern_SemicolonSeparator ; 区切り
22 SplitPattern_SpaceSeparator スペース区切り
23 SplitPattern_CommaSeparator , 区切り
24 SplitPattern_MixedSeparators 3 種混在
25 SplitPattern_ConsecutiveSeparators 連続区切り
26 SplitPattern_TrailingSeparator 末尾区切り
27 SplitPattern_QuotesRemoved クォート除去
28 SplitPattern_QuotesInMiddle 途中クォート
29 SetFileKeys_EmptyInputFallsBackToWildcard 空入力 → *.*
30 SetFileKeys_WildcardInPathReturns1 パス中ワイルドカード
31 SetFileKeys_AbsolutePathInSearchReturns2 絶対パス
32 SetFileKeys_ExcludeFolderHashRelative # 相対除外
33 SetFileKeys_ExcludeFolderHashAbsolute # 絶対除外
34 SetFileKeys_RegexExcludeNoValidation ! バリデーションスキップ
35 SetFileKeys_DuplicateKeyDeduplicated 重複排除
36 AddExceptFile_RelativePath 相対除外ファイル
37 AddExceptFile_AbsolutePath 絶対除外ファイル
38 AddExceptFolder_DefaultPattern 既定除外フォルダー
39 AddExceptFile_HashIsNotSpecial # 非特殊
40 GetExcludeFiles_MergesAllThreeArrays 3 配列集約
41 GetExcludeFolders_MergesRelAndAbs 相対+絶対集約

📂 test-cgrepagent-flow.cpp(20 テスト)

ID テスト名 検証観点
GA-01 FormatGrepResultLine_NormalStyle1_ProducesPathLineColContent Normal + 該当行
GA-02 FormatGrepResultLine_WzStyle2_FileGrouped WZ 風
GA-03 FormatGrepResultLine_ResultOnlyStyle3_NoPath 結果のみ
GA-04 FormatGrepResultLine_OutputLineType0_OnlyMatchPart 該当部分のみ
GA-05 FormatGrepResultLine_OutputLineType1_FullLine 行全体
GA-06 FormatGrepResultLine_OutputLineType2_NegativeLine 否該当行
GA-07 BuildGrepHeader_BasicShape 基本要素
GA-08 BuildGrepHeader_WithRegexOption_IncludesMarker 正規表現マーカー
GA-09 BuildGrepHeader_WithCaseSensitive_IncludesMarker 大文字小文字マーカー
GA-10 BuildGrepFooter_ZeroHits_HasZeroMessage 0 件
GA-11 BuildGrepFooter_PositiveHits_HasCount 42 件(通常/置換)
GA-12 CreateFolders_SemicolonSeparated_SplitsCorrectly ; 分割
GA-13 CreateFolders_QuotedSemicolon_PreservesAsOne クォート内 ;
GA-14 CreateFolders_LongFileName_Resolved 8.3 → ロングパス
GA-15 ChopYen_LastBackslashRemoved 末尾 \ 除去
GA-16 ChopYen_NoTrailingYen_Unchanged 無変更
GA-17 ChopYen_RootPath_AlsoTrimmed C:\C:
GA-18 AddTail_StdoutMode_WritesToStdout stdout 書き込み
GA-19 OnBeforeClose_DuringGrepReturnsInterrupt Grep 中割り込み
GA-20 OnBeforeClose_NotRunningReturnsContinue 停止中継続

📂 test-cdlggrep.cpp(26 テスト / DG-19 欠番)

ID テスト名 検証観点
DG-01 DefaultMemberValues_Constructor 初期値
DG-02 DefaultExcludePatterns_Constants 定数値
DG-03 GetPackedGFileString_NoExclusions 除外なし
DG-04 GetPackedGFileString_WithExcludeFolders # 付加
DG-05 GetPackedGFileString_WithExcludeFiles ! 付加・*.* 補完
DG-06 GetPackedGFileString_EscapeBangInExcludeFolder ! エスケープ
DG-07 GetPackedGFileString_EscapeHashInExcludeFolder # エスケープ
DG-08 GetPackedGFileString_EscapeSpaceInExcludeFolder スペース分割
DG-09 GetPackedGFileString_EscapeSemicolonInExcludeFolder セミコロン分割
DG-10 GetPackedGFileString_CombinedAllExclusions 複合
DG-11 RoundTrip_GuiToCliToEnumKeys Pack→Parse 往復
DG-12 DetermineDefaultExcludePatterns_EmptyHistorySetsDefaults 履歴空
DG-13 DetermineDefaultExcludePatterns_NonEmptyHistoryUsesHistoryTop 履歴先頭
DG-14 DetermineDefaultExcludePatterns_AlreadySetSkipped 設定済みスキップ
DG-15 BuildHwndFileToken_Format HWND 文字列化
DG-16 BuildHwndFileToken_NullHwnd NULL ゼロ埋め
DG-17 IsHwndFileToken_PositiveCases 正常 → true
DG-18 IsHwndFileToken_NegativeCases 異常 → false
DG-20 DoModalCancelImmediately_NoException IDCANCEL → rc=0
DG-21 DoModalOK_WithValidInputs_ReturnsOK 有効入力 → rc=1
DG-22 DoModalOK_EmptyFolder_FallsBackToCurrentDir 空フォルダー
DG-23 DoModalOK_InvalidRegex_StillReturnsOK 不正正規表現
DG-24 DoModalOK_FolderWithSemicolon_IsSplitBySeparator セミコロン区切り
DG-25 DoModalOK_MultipleFolders_AllResolved 複数絶対パス
DG-26 DoModalOK_HistoryRecordedExceptFromThisText 履歴追加
DG-27 DoModalOK_FromThisText_DoesNotPolluteHistory 履歴非汚染

📂 test-grep-irregular.cpp(46 テスト + IRR-16 コメントアウト 1)

CGrepEnumKeys 境界(IRR-01〜IRR-08 + IRR-07b)

ID テスト名
IRR-01 SetFileKeys_EmptyString_DefaultsApplied
IRR-02 SetFileKeys_OnlyWhitespace_DefaultsApplied
IRR-03 SetFileKeys_OnlyExcludePatterns_DefaultSearchApplied
IRR-04 SetFileKeys_VeryLongPattern_4096Chars
IRR-05 SetFileKeys_ManyDuplicates_DeduplicatedTo1
IRR-06 SetFileKeys_NullByteInMiddle_TruncatesAtNull
IRR-07 SetFileKeys_BangPrefixWithInvalidRegex_RegisteredButFailsLater
IRR-07b Regex_InvalidExcludePatternFailsToCompile
IRR-08 SetFileKeys_PathWithDriveLetterInMiddle_TreatedAsRelative

CCommandLine 境界(IRR-09〜IRR-19)

ID テスト名
IRR-09 CommandLine_GKEY_EmptyValue_Ignored
IRR-10 CommandLine_GREPR_EmptyValue_AcceptedAsEmpty
IRR-11 CommandLine_GFOLDER_NonExistentPath_StoredAsIs
IRR-12 CommandLine_GCODE_OutOfRange_StoredAsIs
IRR-13 CommandLine_GCODE_Negative_StoredAsIs
IRR-14 CommandLine_GKEY_WithControlChars_Stored
IRR-15 CommandLine_GKEY_WithSurrogatePair
IRR-16 CommandLine_TotalLength_NearWindowsLimit_32767Chars(コメントアウト・継続課題)
IRR-17 CommandLine_ResponseFileWithGrepArgs_Parsed
IRR-18 CommandLine_DoubleDashStopsOptionParsing
IRR-19 CommandLine_ColonSeparatorEquivalentToEqual

除外正規表現コンパイル検証(IRR-20〜IRR-25)

ID テスト名
IRR-20 ExcludeFile_ValidRegex_CompilesSuccessfully
IRR-21 ExcludeFile_GlobPattern_CompileFails
IRR-22 ExcludeFile_EmptyPattern_NoCompileNoError
IRR-23 ExcludeFile_MixedRegexAndGlob_FirstSucceedsSecondFails
IRR-24 ExcludeFile_MixedGlobAndRegex_OrderReversed
IRR-25 ExcludeFile_AllValidRegex_AllCompileSuccessfully

DoGrepFileWorker 境界(IRR-26〜IRR-34)

ID テスト名
IRR-26 FileWorker_ZeroByteFile_NoHit
IRR-27 FileWorker_OnlyBomFile_NoHit
IRR-28 FileWorker_InvalidUtf8Sequence_DoesNotCrash
IRR-29 FileWorker_FileWithoutFinalNewline_LastLineSearched
IRR-30 FileWorker_MixedLineEndings_LineNumbersConsistent
IRR-31 FileWorker_VeryLongSingleLine_64KChars
IRR-32 FileWorker_LockedFile_ReturnsError
IRR-33 FileWorker_ReadOnlyAttribute_Searched
IRR-34 FileWorker_HiddenSystemFile_Searched

CCodeMediator 境界(IRR-35〜IRR-38)

ID テスト名
IRR-35 CodeMediator_ShortFile_FallbackToDefault
IRR-36 CodeMediator_SjisSecondByteInAsciiRange_NotMisdetected
IRR-37 CodeMediator_PriorCesu8Flag_TogglesDetection
IRR-38 CodeMediator_Utf32LeBom_NotMisdetectedAsUtf16

正規表現・並列処理(IRR-39〜IRR-46)

ID テスト名
IRR-39 Regex_EmptyPattern_CompileFailsOrEmptyMatch
IRR-40 Regex_DotStar_DoesNotHang
IRR-41 Regex_CatastrophicBacktracking_TimeoutGuarded
IRR-42 MultiThread_CancelImmediatelyAfterStart
IRR-43 MultiThread_FileDeletedMidScan
IRR-44 MultiThread_ZeroExcludeRegexes_Equivalent
IRR-45 MultiThread_100ExcludeRegexes_AllApplied
IRR-46 MultiThread_RepeatedStartCancel_50Iterations

📂 test-ccommandline.cpp Phase 2-A(25 テスト追加)

-GOPT 複合・境界値(9 テスト)

# テスト名
1 ParseGrepOpt_MultipleFlagsCombined
2 ParseGrepOpt_AllKnownFlagsOn
3 ParseGrepOpt_DuplicateSameFlag
4 ParseGrepOpt_StyleLastWins
5 ParseGrepOpt_OutputLineTypeLastWins
6 ParseGrepOpt_UnknownCharIgnored
7 ParseGrepOpt_EmptyValueRejected
8 ParseGrepOpt_MixedDigitsAndLetters

-GREPR / -GKEY 連動(4 テスト)

# テスト名
9 ParseGrepReplace_GREPRSetsReplaceFlag
10 ParseGrepReplace_OnlyGKEYDoesNotSetReplaceFlag
11 ParseGrepReplace_GREPREmptyAllowed
12 ParseGrepReplace_ClipboardPasteFlag

Case-insensitive・引数順序(5 テスト)

# テスト名
13 ParseGrep_OptionNameLowerCase
14 ParseGrep_OptionNameMixedCase
15 ParseGrep_ArgumentOrderInvariant
16 ParseGrep_GrepModeAndGrepDlgBothSpecified
17 ParseGrep_GKeyDuplicate_LaterWins

-GKEY / -GFILE / -GFOLDER 値境界(8 テスト)

# テスト名
18 ParseGrepKey_SingleChar_Boundary
19 ParseGrepKey_VeryLongValue_4096Chars
20 ParseGrepKey_JapaneseCharsAndEmoji
21 ParseGrepKey_ContainsEqualsInValue
22 ParseGrepKey_EscapedDoubleQuotes
23 ParseGrepFile_RegexExcludePatternFromPR2449
24 ParseGrepFolder_RelativePath
25 ParseGrepFolder_UncPath

テスト数サマリー

ファイル テスト数
test-grep.cpp 41
test-cgrepagent-flow.cpp 20
test-cdlggrep.cpp 26
test-grep-irregular.cpp 46(+ IRR-16 コメントアウト 1)
test-ccommandline.cpp Phase 2-A 25
合計 158 定義 / 138 新規追加

ライセンス

Zlib License (SPDX-License-Identifier: Zlib)

@hpmy-dev hpmy-dev force-pushed the improvement/grep_test branch from 9a0fd2c to 1fbad90 Compare May 22, 2026 07:20
@hpmy-dev hpmy-dev force-pushed the improvement/grep_test branch from 1fbad90 to bea6726 Compare June 11, 2026 07:28
@hpmy-dev

Copy link
Copy Markdown
Owner Author

#5 に取り込んだのでclose

@hpmy-dev hpmy-dev closed this Jun 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant