On Thursday, 3 November 2022 at 10:00:27 UTC, Bruno Pagis wrote:
Good morning,
I have the following class:
```
class A {
int[] array;
...
void print() {
writeln("array = ", this.array);
}
}
```
I would like to unit test the print function (yes, I know, not
very useful on the above example since print is merely a
duplicate of writeln...). Is there a way to use assert to test
the output of the print function to stdout? Something like:
```
A myClass= new A;
myClass.array = [1,2];
assert(myClass.print() == "array = [1,2]"); // I know that
print does not return anything so this is wrong, but you get
the idea :-)
```
Thanks.
Just so we understand, do you want to verify that the output is
indeed directed to stdout and not some other stream?