Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add method checkpoint to trait Checkpoints for easy use of Checkpoint #2305

Merged
merged 7 commits into from
Jun 10, 2024

Conversation

ndy2
Copy link
Contributor

@ndy2 ndy2 commented Jan 1, 2024

I added a method checkpoint to trait Checkpoints for easy use of Checkpoint.

I have some experience of other test frameworks of JVM familiy like Junit/assertj & kotest.
I thought that create Checkpoint & report it is quite verbose and tedious.

Thus, I introduce a checkpoint!
I found that like the trait Checkpoint is right place to place this method like other dsl helper traits in scalatest. (Inside, Matchers ...)

Full Usage Example :

class FourBasicOperationSpec extends AnyFlatSpec with Matchers with Checkpoints {

  it("four basic operation") {
    checkpoint { cp =>
      cp { 1 + 1 should equal(2) }
      cp { 2 + 2 should equal(4) }
    }

    checkpoint { cp =>
      cp { 1 - 1 should equal(0) }
      cp { 2 - 2 should equal(0) }
    }

   ...
  }
}

Inspired by

Copy link

cla-bot bot commented Jan 1, 2024

Hi @ndy2, we require contributors to sign our Contributor License Agreement, and we don't have yours on file. In order for us to review and merge your code, please access https://www.artima.com/cla/choose-type to sign our Contributor License Agreement. Your effort is highly appreciated. Thank you.

@artimasites
Copy link

@cla-bot[bot] check

@cla-bot cla-bot bot added the cla-signed label Jan 1, 2024
Copy link

cla-bot bot commented Jan 1, 2024

The cla-bot has been summoned, and re-checked this pull request!

@ndy2 ndy2 changed the base branch from main to 3.2.x-new January 4, 2024 14:18
@ndy2 ndy2 changed the base branch from 3.2.x-new to main January 4, 2024 14:19
@ndy2
Copy link
Contributor Author

ndy2 commented Jan 5, 2024

Hello, @cheeseng !
I have no idea why the compilation fail in scala 2.13,2.11, 3, js even the unit tests are all passed.
Can you give me some suggestion or comment on this PR?

@cheeseng
Copy link
Contributor

@ndy2 Sorry for the late response, I'll take a look today and what's going on.

Cheers.

@cheeseng
Copy link
Contributor

@ndy2 I managed to fix the compile errors:

cheeseng@4d2fcc5

But the unit tests are failing because of wrong line number check, I'll try to look into it further when possible.

@cheeseng
Copy link
Contributor

@ndy2 I managed to fix the problem, I submitted the following PR to your fork:

ndy2#1

Hopefully after merging it should get your PR pass the CI here.

Cheers.

@ndy2
Copy link
Contributor Author

ndy2 commented Feb 13, 2024

I merged the PR in my fork.
Can I get approval for check the CI pass?

Copy link
Contributor

@bvenners bvenners left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like a nice addition. But I would probably call the method withCheckpoint rather than checkpoint. And the signature should be:

def withCheckpoint(f: Checkpoint => Assertion)(implicit pos: source.Position): Assertion

Instead of:

def checkpoint(f: Checkpoint => Unit)(implicit pos: source.Position): Unit

@ndy2
Copy link
Contributor Author

ndy2 commented May 28, 2024

@bvenners Hi.

The suggested signature looks good. I agree that withCheckpoint is a better method name.

But how can we use Assertion as the Return type of both parameter f and withCheckPoint ?
Do you mean org.scalatest.compatible.Assertion in Assertion above?

I found that org.scalatest.compatible.Assertion (call Assertion) do nothing and is a simple marker interface, but to apply suggested method with below usage, it requries to update the signature of Checkpoints.apply also (to return Assertion).

below usage

    withCheckpoint { cp =>
       cp { x should be < 0 }
       cp { y should be > 9 }
    }

or to write as below which is quite not awesome.

below

    withCheckpoint { cp =>
       cp { x should be < 0 }
       cp { y should be > 9 }
       Succeeded
    }

Can you explain what do you want to achieve by use Assertion instead of Unit in the signature, and how can handle above situation?

@bvenners
Copy link
Contributor

Can you explain what do you want to achieve by use Assertion instead of Unit in the signature, and how can handle above situation?

You're right. The problem is that Checkpoint's apply method returns Unit. It should probably return Assertion, but we did not change that when we added Assertion. Please leave it as Unit in your PR and we can use that for now. Perhaps later we can think about migrating to Assertion.

@cheeseng cheeseng merged commit fced376 into scalatest:main Jun 10, 2024
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants