Skip to content

Instantly share code, notes, and snippets.

@crazymonkyyy
Last active January 22, 2025 18:09
Show Gist options
  • Save crazymonkyyy/2afa7ae1402cd246fb98bdb86dd19605 to your computer and use it in GitHub Desktop.
Save crazymonkyyy/2afa7ae1402cd246fb98bdb86dd19605 to your computer and use it in GitHub Desktop.

Statement Unittest

Field Value
DIP: (number/id -- assigned by DIP Manager)
Author: monkyyy, [email protected]
Implementation: (links to implementation PR if any)
Status: Draft

Abstract

Shortened unittest syntax

Contents

Rationale

One-liner functions should at least have one line of tests.

Prior Work

Shortened function syntax.

Shortened contract syntax.

Description

A module-level unittest statement( uses () instead of {}) for single asserts , with an optional string message

unittest(1==1);
unittest(1==1,"math broke");

TODO: Detailed technical description of the new semantics. Language grammar changes (per https://dlang.org/spec/grammar.html) needed to support the new syntax (or change) must be listed.

Breaking Changes and Deprecations

On-going debate if it effects future unittest syntax

Reference

https://forum.dlang.org/thread/[email protected]

https://forum.dlang.org/thread/[email protected]

Copyright & License

Copyright (c) 2024 by the D Language Foundation

Licensed under Creative Commons Zero 1.0

History

The DIP Manager will supplement this section with links to forum discsusionss and a summary of the formal assessment.

@crazymonkyyy
Copy link
Author

adr is in favor of unittest=>1==1;

walters suggestion about "argument unittests" being blocked still seems wrong to me and he never responded to my code block about template unittests; I believe that all unittests must be compile time and therefore probably templated

@crazymonkyyy
Copy link
Author

updated for snars comment

@Bolpat
Copy link

Bolpat commented Jan 18, 2025

unittest => 1 == 1; cannot have an assert message in a way that feels natural. Your unittest(1 == 1, "math broke"); is quite intuitive. ADR is wrong.

@crazymonkyyy
Copy link
Author

unittest => 1 == 1; cannot have an assert message in a way that feels natural. Your unittest(1 == 1, "math broke"); is quite intuitive. ADR is wrong.

I believe adr could trivailly be convinced if someone else wrote the code, if upstream annoies you consider the other option

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