Skip to content

Instantly share code, notes, and snippets.

@krishnadey30
Last active May 22, 2019 21:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save krishnadey30/c4bad0ab03cb69cc9b0f1937ed1e0e2e to your computer and use it in GitHub Desktop.
Save krishnadey30/c4bad0ab03cb69cc9b0f1937ed1e0e2e to your computer and use it in GitHub Desktop.
This gist holds a draft of the feature request for the Unit Test Framework CHAPEL-LANG.

Proposed support for Reflection functions that get name of method of a class.

Issue #13068

I believe it will be very useful if, especially for the unit test framework if it were possible to get the name of method present in a class as a string. This will be helpful to check if the method is a test method or not.

/* Get the type of the ith method in a class.
   Causes a compilation error if `i` is not in 1..numMethods(t).
   :arg t: a class type
   :arg i: which method to get the name of
   :returns: the name of the method, as a string
 */
proc getMethodName(type t, var i:int) string
  return __primitive("method num to name", t, i);

Proposed support for Reflection functions that get # of methods of a class.

Issue #13069

I believe it will be very useful if, especially for the unit test framework if it were possible to get the number of methods present in a class. This will be helpful to get the name or reference of method.

// Return the number of methods in a class.
proc numMethods(type t) param : int
  return __primitive("num method", t);

Proposed support for Reflection functions that call a method of a class from its name.

Already an issue chapel-lang/chapel#8326 if present for it.

Support to store Classes in a list

Note: I don't think we need it.

I believe it will be very useful if, especially for the unit test framework if it were possible to store classes in list/LinkedList. This will be useful when user write tests in multiple classes and want to test all them in a suite. So we need to store the Classes.

use LinkedLists;
var classNames : LinkedList(type);
class a{
	// do something
}
class b{
	// do something
}
classNames.push_back(a);
classNames.push_back(b);

Get Instance of a class from its name

Issue #13070

I believe it will be very useful especially for the unit test framework if it were possible to get the instance of a class given its name as a string. This will help in calling the test methods of all classes in a suite.

// Return the instance of methods in a class.
proc classInstance(string fname) var
  return __primitive("class instance", fname);
@krishnadey30
Copy link
Author

For the 4th one, I think we can have another alternative but won't be that friendly for the users. We can store objects of each class and then write a function which can return the class from the object. Currently, we have a function that returns the name of the class from the obj.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment