Re: Unit testing a function returning void

2022-11-03 Thread Imperatorn via Digitalmars-d-learn
On Thursday, 3 November 2022 at 10:26:04 UTC, Imperatorn wrote: 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 t

Re: Unit testing a function returning void

2022-11-03 Thread Sergey via Digitalmars-d-learn
On Thursday, 3 November 2022 at 10:00:27 UTC, Bruno Pagis wrote: Good morning, 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 functio

Re: Unit testing a function returning void

2022-11-03 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Nov 03, 2022 at 08:51:52AM -0700, Ali Çehreli via Digitalmars-d-learn wrote: > On 11/3/22 03:00, Bruno Pagis wrote: > > >void print() { > > writeln("array = ", this.array); > >} > > Similar to Paul Backus's program but I would try to avoid the file system > for unit tests wh

Re: Unit testing a function returning void

2022-11-03 Thread Ali Çehreli via Digitalmars-d-learn
On 11/3/22 03:00, Bruno Pagis wrote: >void print() { > writeln("array = ", this.array); >} Similar to Paul Backus's program but I would try to avoid the file system for unit tests when possible. In this case, you can print into a sink, which can be useful in other ways as well:

Re: Unit testing a function returning void

2022-11-03 Thread Paul Backus via Digitalmars-d-learn
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 abov

Re: Unit testing a function returning void

2022-11-03 Thread Imperatorn via Digitalmars-d-learn
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 abov

Re: Unit testing a function returning void

2022-11-03 Thread rikki cattermole via Digitalmars-d-learn
You could redirect stdout to a file of your choosing and test against that. Although ideally you would instead take as an argument to print some sort of output range or Appender. Then you could test against that instead.

Unit testing a function returning void

2022-11-03 Thread Bruno Pagis via Digitalmars-d-learn
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 th