Persimmonç¨ã¢ãµã¼ã·ã§ã³ã©ã¤ãã©ãªMuscleAssertãä½ã£ã
æ£ç¢ºã«ã¯ãä½ã£ã¦ããã©ã¤ãã©ãªãPersimmon.MuscleAssertã«renameãããã§ãã
注æ
ãã®è¨äºã¯ããã¾ã§ç§ã®èãã§ããpersimmon-projectsã®ç·æã§ããããã§ã¯ããã¾ããã
åæ
- Persimmonã¯F#ç¨ã®ãã¹ãã£ã³ã°ãã¬ã¼ã ã¯ã¼ã¯ã§ã https://github.com/persimmon-projects/Persimmon
ãããªã«F#å¯ãã®è©±ã¯ããªãã¯ããªã®ã§ãããããã®æ å ±éã§å¤§ä¸å¤«ãªã¯ãâ¦ï¼
Persimmonã¯power assertã®å¤¢ãè¦ããï¼
æ¨ä»ã¯power assertã®èªç¥åº¦ãæ ¼æ®µã«ä¸ãã£ã¦ããããã§ããã ããã¯JavaScriptåãã®power-assertã«ãããã®ã大ããã®ã§ã¯ãªããã¨æããã¾ãã
ã¡ãã£ã¨è±ç·ãã¤ã¤Persimmonã«power assertãå¿ è¦ãèãã¦ã¿ã¾ãããã
ã©ã®æå³ã§ã®powert assertï¼
assertã¨ããè¨èã¯äºã¤ã®ç¨éã§ä½¿ããããã¨æãã¾ãã
- DbCã¨ãã¦ã®è¡¨æ(assertion)
- checkingãç®çã¨ããasserté¢æ°
DbCåãã®ç¨éã§power assertãå©ç¨ããããã¨ã¯ã¾ã å°ãªãããã§ãã ãã¶ãGroovyã¨JavaScript*1ããããªã®ã§ã¯ã¨ããèªèã§ãã ç§ãç¥ããªãã ããããããªãã®ã§ããâ¦ã
ä¸æ¹ãã¦ããããã¹ããã¬ã¼ã ã¯ã¼ã¯ã®æèä¸ã§ç»å ´ããpower assertã¯æ§ã ãªè¨èªã«åå¨ãã¾ãã .NETã«ãhttps://github.com/PowerAssert/PowerAssert.Netãåå¨ãã¾ãã 使ãåæã¯è§¦ã£ããã¨ããªãã®ã§ããç¥ãã¾ããâ¦ã
ä»åã¯å¾è ã®ã»ãã§ã®power assertã«ã¤ãã¦ã®è¨åã§ãã
æã ã欲ããã£ããã®ã¯power assertãªã®ã
ãã¤ã¦ãä¸è¨ã®è¨äºãçéãã«ãããã¾ããã
そろそろPower Assertについてひとこと言っておくか - ぐるぐる~
ç¶æ³ãå°ãå¤ãã£ã¦ããã®ã¯
- Groovy(ãã£ã¡ã¯å½æããï¼)ãJavaScriptã®power assertã§ã¯æååã®æ¯è¼ã§å·®åã表示ãã
ãããã§ããããã ãã¨ã¯ä¸è¨ãåç §ããã¨è¯ãããããã¾ããã
https://github.com/persimmon-projects/Persimmon/issues/4#issuecomment-60347183
ããã«F#çãªè£è¶³ããã¦ããã¨
- ãªãã¸ã§ã¯ãã®ä¸è´ã確èªãããã¨ãå¤ã
- å¤å¥å ±ç¨ä½ãã¬ã³ã¼ããªã©åãä½ããããç°å¢ã«ãããããæååãæ°å¤ãªã©ã§ã¯ãªãããããã£ãæã£ããªãã¸ã§ã¯ããæ¯è¼ãããã¨ã«ãªãããã
- ãã¤ãã©ã¤ã³æ¼ç®åã§ã¤ãªããã¹ã¿ã¤ã«ã§çµæãasserté¢æ°ã«æ¸¡ãå ´åããã
- Elixirã®ããã«å¼·åãªãã¯ããããããã§ã¯ãªãã®ã§éä¸ã®å¼ã解æ対象ã«ã§ããªã
- power assertã®ããã«ã¹ã¿ã¤ã«ãå¤ããã®ãï¼çãª
ã¿ãããªè©±ããããããªãªããããªæãã§ãã
ããããã£ãå¹¾ã¤ãæã¤ãªãã¸ã§ã¯ãï¼ä¾ãã°JSONãªãã¸ã§ã¯ãããããã³ã°ããã¬ã³ã¼ãï¼ãpower assertã«ãããã¨ç¡é§ã«æ å ±éå¤ã«ãªããããããããinlineã«å¼ãæ¸ããªããã¨ã®ã»ããå¤ãããå¿ è¦ãªæ å ±ãå¢ãããã©ããã¯å¾®å¦ãªã¨ããã§ãã æ å ±ãå¢ããªãã®ã«ã°ã©ãã£ã«ã«ãªå¤±æçµæã表示ããã¦ãå¬ããã¨ã¯æãã¾ããã
ã¯ããã¦ãã®ç¶æ³ã§ãè¦å´ãã¦power assertãå®è£ ããå¿ è¦ãããã®ã§ããããï¼
å°ãªãã¨ãç§ã«ã¯æãåºãæ°åãããã¾ããã§ãã*2ã
åæã§ä¸è¦ãªæ å ±ãæ¡ãã¤ã¶ã
ãããããã¯ãåç´ãªasserté¢æ°ã¯åä¸è¶³ã§ãã
// https://github.com/persimmon-projects/Persimmon/blob/cdba2509e5d48e4cdd47f292f3578b00371c85fc/src/Persimmon/Assertions.fs#L9 let assertEquals expected actual = if expected = actual then pass () else fail (sprintf "Expect: %A\nActual: %A" expected actual)
ä¸è¨ã¯Persimmon 1.1.0ã®assertEquals
ã§ãããã¨ã«ãã貧弱ã§ãã
æ
å ±éãsprintf
ã§åºåå¯è½ãªç¯å²ã«çµãããããã§ãããããã¤ã®è¡¨ç¤ºã¯ãã¾ããã¦ã«ã§ããªãã¨æã£ãã»ããè¯ãã§ãã
ã²ã©ãã¨ãã«ã¯ååãã表示ããã¾ããï¼ããã§ãè¨èªçµã¿è¾¼ã¿ã®assertããã¯ãã·ã§ããï¼ã
ããã§ã¯ãããã«ã¤ããï¼ãããï¼ã®ã§ããã¡ãã£ã¨æ å ±éå¢ãããªãããã¨ãã話ã«ãªãã®ã¯å¿ ç¶ã§ãã ãããpower assertã«ã¯æççâ¦ã©ããããã¨ãã話ã«ãªãã¾ãã
ãã¦ãid:bleis-tiftããã®è¨äºã§ã¯ããè¿°ã¹ããã¦ãã¾ããã
ã¦ããããã¹ãã«ããã¦ãæã欲ããã®ã¯ãã©ããã©ããªã£ã¦ããããã§ã¯ãªãã ãã©ããã©ãéã£ã¦ãããããããªãã§ãããã
ãããPersimmonéçºãã¼ã ã§ããå°ãåè°ããçµæãããªãã¸ã§ã¯ãã®diffãã ãããã¨ããæµãã«ãªãã¾ããã ã¨ããããã§åºæ¥ä¸ãã£ã試ä½ã©ã¤ãã©ãªãPersimmon.MuscleAssertã§ãã
https://github.com/persimmon-projects/Persimmon.MuscleAssert
ãã®ã©ã¤ãã©ãªãã§ãããã¨ã¯ãçå¤æ¯è¼ããä¸ä¸è´ã ã£ãããªãã¸ã§ã¯ãã®å·®åãã²ããã表示ããããã ä¸ã¤ã§ãã ã¨ã¯ãããå®éã«ã¯ä»¥ä¸ã®å¶ç´ãã¤ãã¾ãã
System.Type
ã¯ã¢ã¯ã»ã¹ããç¬éã«ä¾å¤ãé£ã¶ããããã£ããªãã¬ã¯ã·ã§ã³ã§åãã¦ãã¾ãããFullName
ããããã£ã®ã¿å¯¾è±¡ã«ãã- IEnumerableã¯diffã®å¯¾è±¡ã«ããªãã§ãç¡è¦ããããã¨è¦åãã ã
- ç¡éãªã¹ãã®ã§ããå¯è½æ§ããiterateããéã«å¯ä½ç¨ãçºçããªãã¸ã§ã¯ããæä½ããã¦ãã¾ãå¯è½æ§ããããã
- stringãæªå å·¥ã§è¡¨ç¤º
- ä»å¾ã®æ¹é次第ã§ã¯diff-match-patchãå°å ¥ããããããã¾ãã
ã³ã¼ãä¾ã¨å®è¡çµæãè¦ã¦ã¿ã¾ãããã
open Persimmon open UseTestNameByReflection open Persimmon.MuscleAssert type TestRecord = { X: string list Y: int } type TestDU = | A | B of TestRecord | C let ``dump diff list includeing DU`` = parameterize { source [ ([A; A], [A; C]) ([A], [B { X = []; Y = 2 }]) ([B { X = []; Y = 1 }], [B {X = []; Y = 2 }]) ] run (fun (expected, actual) -> test { do! expected === actual }) }
ãã¹ãçµæã§ã¯ä»¥ä¸ã®ãããªè¡¨ç¤ºãå£éè¦ããã¯ãã§ãã
Assertion violated ... 1. .[1] left TestDU.A right TestDU.C Assertion violated ... 1. .[0] left TestDU.A right TestDU.B Assertion violated ... 1. .[0].Item.Y left 1 right 2
å¤ãç°ãªãé¨åã®ã¿ã«è¡¨ç¤ºãæ¡ãæ½°ããå®ã«è³çã§ããã
å½åçç±
ãæ®éã®ã¢ãµã¼ã·ã§ã³ã¨åºå¥ãã«ããããååãã¤ããããã¨ãã話ã«ãªã£ãéã«
Power Assertã¯æ代é ããä»ã¯Muscle Assertã ï¼çãªè©±ããªï¼
— ã¬ãããè (@gab_km) June 1, 2016
ããããªãããã®ã¾ã¾æ¡ç¨ããã¾ããã
power assertã¨å¯¾ç«ããåå¨ãªã®ãï¼
ä¸æã§ãã
æ£ç´ãªã¨ãããè¨èªã«ãã£ã¦ã¯power assertã®ã»ãã使ãåæãè¯ãå¯è½æ§ã¯ãããã¾ãããå種power assertã©ã¤ãã©ãªããªãã¸ã§ã¯ãdiffæ©è½ãåãè¾¼ãã°è©±ã¯å¤ãã£ã¦ããããããã¾ããã
ã¨ã¯ãããä¸ã¤ã ãæ確ã«è¨ããéããããã¾ãã ããã¯diffãåå¾ããã ãã§ããã°ASTã®æä½ã¯å¿ è¦ãªãã¨ããç¹ã§ãã ä¸ã®ä¸ã«ã¯ãã¹ãã§ASTãæä½ãããã¨ã«æççãªæ´¾é¥ããããããã§ããããããã£ãæ´¾é¥ã«ãåãå ¥ããããå¯è½æ§ã¯æ®ããã¦ãã¾ãã
ã©ããªè¨èªã§ãå®è£ ã§ããã®ã
ãªãã¸ã§ã¯ãç¨diffã©ã¤ãã©ãªã¯Javaãã移æ¤ãã¾ããã
ãã®ã©ã¤ãã©ãªã§ã¯get
ãã¬ãã£ãã¯ã¹ã®ã¤ããã¡ã½ããã対象ã¨ãã¦ããã®ã§ãä½ãããã®å¶ç´ï¼getterã®ãããªæ
£ç¿çãªãã®ï¼ãè¨ããã°å®è£
ã§ããã®ã§ã¯ãªãã§ããããã
ãããã«
ã¦ããããã¹ããã¬ã¼ã ã¯ã¼ã¯ã«ã¯ä»¥ä¸ã®æ¹éãçæ³ï¼ï¼ï¼ãããã¨æã£ã¦ãã¾ãã
- æåæã¯æ²é»ãã失ææã¯ããã¾ãã
- ããªã失æããã®ãããç確ã«ä¼ãã
- ãããã¯å®¹æã«æ¨è«å¯è½ãªå½¢ã§è¡¨ç¤ºãã
power assertããã®ã¾ã¾å¢ããå¢ãã®ããçèå¼assertã®æµããæ¥ãã®ãã第ä¸ã®æ¦å¿µããã£ãããã®ãã¯ãããã¾ããã ãã æ¥ã èããå®è£ ããè°è«ã交ãããªããã°åæ»ããã ãã ã¨æãã¾ãã
ãããæ©ä¼ã«ä¸åº¦ãããã¹ã失ææã«æ¬²ããã£ãæ å ±ã¨ã¯ä½ãããèãã¦ã¿ãã®ãè¯ãããããã¾ããã
*1:https://github.com/power-assert-js ã«ãããã¼ã«ç¾¤ãé§ä½¿ããã°å¯è½ã¨ãã話ãèãããã£ãã ããªã®ã§ã詳細ã¯ãã®æ¹é¢ã®æ¹ã«å°ãã¦ãã ãã
*2:ãã¹ãã±ã¼ã¹ã®æ§æèªä½ã解æ対象ã«ãããã¨è©¦ã¿ããã¨ã¯ããã¾ããããããæ å ±éå¤ã«ãªãããã ã£ãã®ã§ä¸æ¦éçºãæ¢ãã¦ãã¾ã https://github.com/persimmon-projects/Persimmon.Pudding