मेरे पास फ़ंक्शन का एक गुच्छा है: method1
, method2
, method3
। उनमें से सभी के लिए HUnit
परीक्षण कार्य हैं: testMethod1
, testMethod2
, testMethod3
।इसके अंदर फ़ंक्शन नाम प्राप्त करें
testMethod1 = TestCase $
assertEqual "testmethod1" ...
testMethod2 = TestCase $
assertEqual "testmethod2" ...
testMethod3 = TestCase $
assertEqual "testmethod3" ...
मैं त्रुटि संदेश का उपसर्ग के रूप में समारोह के नाम का अनावश्यक नकल से बचने और यह ऐसा ही कुछ कॉल करना चाहते हैं:
testMethod1 = TestCase $
assertEqual_ ...
यह कैसे प्राप्त किया जा सकता है (किसी भी "जादू" चाल की सराहना की)?
तो वास्तव में सवाल यह है कि इसकी परिभाषा के अंदर कार्य नाम कैसे लिया जा सकता है?
अद्यतन।
यह वास्तव में मूल प्रश्न से स्पष्ट नहीं है, कि मैं भी स्थिति में उस प्रकार संभाल करना चाहते हैं:
tProcess = TestCase $ do
assertEqual_ testResult $ someTest
assertEqual_ anotherTestResult $ anotherTest
assertEqual_ resultAgain $ testAgain
टेम्पलेट Haskell – pat
मेरा पुराना सवाल उपयोगी हो सकता है: http://stackoverflow.com/questions/7896928/how-to-get-variable-name-in-haskell –