Tengo un montón de funciones como: method1
, method2
, method3
. Para todos ellos hay HUnit
funciones de prueba como: testMethod1
, testMethod2
, testMethod3
.obtener el nombre de la función dentro de él
testMethod1 = TestCase $
assertEqual "testmethod1" ...
testMethod2 = TestCase $
assertEqual "testmethod2" ...
testMethod3 = TestCase $
assertEqual "testmethod3" ...
me gustaría evitar la copia repetida del nombre de la función como prefijo del mensaje de error y llamarlo algo así:
testMethod1 = TestCase $
assertEqual_ ...
¿Cómo puede lograrse (cualquier truco "mágica" se aprecia)?
Así que en realidad la pregunta es cómo se puede tomar el nombre de la función dentro de su definición?
actualización.
En realidad no es claro a partir de la pregunta original, en la que quiero manejar ese tipo de situación también:
tProcess = TestCase $ do
assertEqual "tProcess" testResult $ someTest
assertEqual "tProcess" anotherTestResult $ anotherTest
assertEqual "tProcess" resultAgain $ testAgain
Por último quiero escribir algo así:
tProcess = TestCase $ do
assertEqual_ testResult $ someTest
assertEqual_ anotherTestResult $ anotherTest
assertEqual_ resultAgain $ testAgain
plantilla haskell – pat
Mi vieja pregunta podría ser útil: http://stackoverflow.com/questions/7896928/how-to-get-variable-name-in-haskell –