Files
Bubberstation/code/modules/unit_tests
Gandalf 1e5b71836e Port of several PRs from NOVA (#25926)
* Fixes confetti shotgun shells (#174)

* initial

* fix confetti shell

* donkpocket sprites and more

* this is for a different PR

* forgot these

* ..()

* reviews

* // instead of /// for overrides

---------

Co-Authored-By: Bloop <13398309+vinylspiders@users.noreply.github.com>

* New Quirk: Appendicitis Survivor (#77)

## About The Pull Request
Title.

## How This Contributes To The Nova Sector Roleplay Experience
Spontaneous appendicitis is.. an event!

This adds the Appendicitis Survivor quirk from my server,
[TaleStation](https://github.com/TaleStation/TaleStation).

Its a positive (-2) quirk, while low impact, some people may appreciate.
Its also another low cost quirk, so people could pick it up if so
desired.

## Proof of Testing

<details>
<summary>Screenshots/Videos</summary>


![image](https://github.com/GalacticStation/GalaxiaStation/assets/70232195/1f807368-f811-4d1d-b2c5-34f8508e6fcb)

  
</details>

## Changelog

🆑 Jolly
add: New quirk for those who hate their appendix: Appendicitis Survivor!
A positive (-2) quirk.
/🆑

* Improves the names, descriptions, and extended descriptions of nearly all my firearms (#90)

<!-- Write **BELOW** The Headers and **ABOVE** The comments else it may
not be viewable. -->
<!-- You can view Contributing.MD for a detailed description of the pull
request process. -->

Three steps

1. Guns no longer list their company in their name, this made some gun
names too long to refer to or just look weird.
2. Every gun now tells you what it fires in its examine if it didn't
before.
3. Every gun's examine text now hints that you can double examine for
more info on the weapon.

<!-- Describe The Pull Request. Please be sure every change is
documented or this can delay review and even discourage maintainers from
merging your PR! -->

Makes a lot of information about these weapons more convenient or more
apparent than they were before, and removes some unneeded information
(like we didnt really have to have the guys that made the gun displayed
straight in the name, you can see the company that makes them in the
examine text already).

<!-- Please add a short description of why you think these changes would
benefit the game and the roleplay atmosphere of the server. If you can't
justify it in words, it might not be worth adding. -->

<!-- Include any screenshots/videos/debugging steps of the code
functioning successfully, between the </summary> and </details> code
blocks. -->
<!-- To our mappers and spriters: Posting screenshots of content INSIDE
EDITORS (aseprite, PDN, SDMM, ect) is NOT valid proof of testing. Please
make sure that you COMPILE the game and provide PROOF you tested your
edits. -->

<details>
<summary>Screenshots/Videos</summary>

![image](https://github.com/GalacticStation/GalaxiaStation/assets/82386923/cd4976fe-c641-4464-82ee-935aff63f159)

![image](https://github.com/GalacticStation/GalaxiaStation/assets/82386923/b1dc1edc-72fd-4235-a47d-84c36cae0679)

</details>

<!-- If your PR modifies aspects of the game that can be concretely
observed by players or admins you should add a changelog. If your change
does NOT meet this description, remove this section. Be sure to properly
mark your PRs to prevent unnecessary GBP loss. You can read up on GBP
and it's effects on PRs in the tgstation guides for contributors. Please
note that maintainers freely reserve the right to remove and add tags
should they deem it appropriate. You can attempt to finagle the system
all you want, but it's best to shoot for clear communication right off
the bat. -->

🆑
qol: The names and descriptions of every paxilmaniac weapon have been
improved to be shorter (names) and mention at least what bullet the
weapon fires (description)
qol: Every weapon with an extended description has a hint in its normal
examine telling you that you can look further to get more info on the
weapon
code: Two instances of now-deleted weapons paths (which i found out
about through someone getting one in a christmas tree) existing due to
manufacturer examines of all things have been cleaned up, players wont
notice this one i think
/🆑

<!-- Both 🆑's are required for the changelog to work! You can put
your name to the right of the first 🆑 if you want to overwrite your
GitHub username as author ingame. -->
<!-- You can use multiple of the same prefix (they're only used for the
icon ingame) and delete the unneeded ones. Despite some of the tags,
changelogs should generally represent how a player might be affected by
the changes rather than a summary of the PR's contents. -->

* Re-adding Cat Scream (Normalized) (#123)

* Re-adding Cat Scream (Normalized)

* Update modular_nova/modules/emotes/code/scream_datums.dm

Renamed the file from cat.ogg to cat_scream.ogg

Co-authored-by: GoldenAlpharex <58045821+GoldenAlpharex@users.noreply.github.com>

* Renamed cat.ogg to cat_scream.ogg

* removed cat.ogg and replaced with cat_scream.ogg

* Removes old scream sounds, renames it properly

---------

Co-authored-by: GoldenAlpharex <58045821+GoldenAlpharex@users.noreply.github.com>
Co-authored-by: GoldenAlpharex <jerego1234@hotmail.com>

* [MODULAR] Fixes clockcult slab ui, some runtimes (#122)

Fixes slab ui, some runtimes

* [MODULAR] Fixes colonial cloaks not being able to hold any suit storage items (#129)

* Fixes imperial police cloak not being able to hold any suit storage items

* Moves this to the NRI police cloak

* Moves this to the NRI police cloak

* Update clothing.dm

* Update modular_nova/modules/novaya_ert/code/police_outfit.dm

---------

Co-authored-by: GoldenAlpharex <58045821+GoldenAlpharex@users.noreply.github.com>

* Resprited Vox Clothing (Nova Station Edition) (#97)

* Resprited Vox Clothing

* Update screenshot_humanoids__datum_species_vox_primalis.png

---------

Co-authored-by: Bloop <13398309+vinylspiders@users.noreply.github.com>

* Chitter emote is the TG chitter sound unless you're a moth (#111)

<!-- Write **BELOW** The Headers and **ABOVE** The comments else it may
not be viewable. -->
<!-- You can view Contributing.MD for a detailed description of the pull
request process. -->

Changes the *chitter emote to play the standard TG chitter sfx, unless
you're a moth, then it plays the moth chitter.

TG chitter is cute.

<!-- Include any screenshots/videos/debugging steps of the code
functioning successfully, between the </summary> and </details> code
blocks. -->
<!-- To our mappers and spriters: Posting screenshots of content INSIDE
EDITORS (aseprite, PDN, SDMM, ect) is NOT valid proof of testing. Please
make sure that you COMPILE the game and provide PROOF you tested your
edits. -->

<details>
<summary>Screenshots/Videos</summary>

https://github.com/NovaSector/NovaSector/assets/77534246/eae4fc45-d104-4588-8537-394da9304151

</details>

<!-- If your PR modifies aspects of the game that can be concretely
observed by players or admins you should add a changelog. If your change
does NOT meet this description, remove this section. Be sure to properly
mark your PRs to prevent unnecessary GBP loss. You can read up on GBP
and it's effects on PRs in the tgstation guides for contributors. Please
note that maintainers freely reserve the right to remove and add tags
should they deem it appropriate. You can attempt to finagle the system
all you want, but it's best to shoot for clear communication right off
the bat. -->

🆑
add: Chitter emote has a different sound effect, unless you're a moth
/🆑

* Adds fancy masquerade masks (#180)

* Adds masquerade masks, making them available in the AutoDrobe

Thanks to Crumpaloo for the sprites!

* Early mirror of https://github.com/tgstation/tgstation/pull/80663

They're not properly usable otherwise

* Updates the sprites so they've got transparent eyes

* Adds the masks to the loadout

* Fixes variation flags and muzzled GAGS config, makes it act as internals

* Adjust some of the sprites a bit more, making snouted ones have smaller eyeholes, and vox ones looking more like masquerade masks

* Updates the sprites for the Vox Primalis!

---------

* Update greyscale_configs.dm

* Fixes Niftsoft Settings Panel (#208)

Fixes Niftsoft Settings

* 0

---------

Co-authored-by: Bloop <13398309+vinylspiders@users.noreply.github.com>
Co-authored-by: Kyogon <30851775+Kyogon@users.noreply.github.com>
Co-authored-by: GoldenAlpharex <58045821+GoldenAlpharex@users.noreply.github.com>
Co-authored-by: GoldenAlpharex <jerego1234@hotmail.com>
Co-authored-by: HalcyonicWolf <mmeade362@gmail.com>
Co-authored-by: SomeRandomOwl <2568378+SomeRandomOwl@users.noreply.github.com>
2023-12-31 17:24:47 +00:00
..

Unit Tests

What is unit testing?

Unit tests are automated code to verify that parts of the game work exactly as they should. For example, a test to make sure that the amputation surgery actually amputates the limb. These are ran every time a PR is made, and thus are very helpful for preventing bugs from cropping up in your code that would've otherwise gone unnoticed. For example, would you have thought to check that beach boys would still work the same after editing pizza? If you value your time, probably not.

On their most basic level, when UNIT_TESTS is defined, all subtypes of /datum/unit_test will have their Run proc executed. From here, if Fail is called at any point, then the tests will report as failed.

How do I write one?

  1. Find a relevant file.

All unit test related code is in code/modules/unit_tests. If you are adding a new test for a surgery, for example, then you'd open surgeries.dm. If a relevant file does not exist, simply create one in this folder, then #include it in _unit_tests.dm.

  1. Create the unit test.

To make a new unit test, you simply need to define a /datum/unit_test.

For example, let's suppose that we are creating a test to make sure a proc square correctly raises inputs to the power of two. We'd start with first:

/datum/unit_test/square/Run()

This defines our new unit test, /datum/unit_test/square. Inside this function, we're then going to run through whatever we want to check. Tests provide a few assertion functions to make this easy. For now, we're going to use TEST_ASSERT_EQUAL.

/datum/unit_test/square/Run()
    TEST_ASSERT_EQUAL(square(3), 9, "square(3) did not return 9")
    TEST_ASSERT_EQUAL(square(4), 16, "square(4) did not return 16")

As you can hopefully tell, we're simply checking if the output of square matches the output we are expecting. If the test fails, it'll report the error message given as well as whatever the actual output was.

  1. Run the unit test

Open code/_compile_options.dm and uncomment the following line.

//#define UNIT_TESTS			//If this is uncommented, we do a single run though of the game setup and tear down process with unit tests in between

Then, run tgstation.dmb in Dream Daemon. Don't bother trying to connect, you won't need to. You'll be able to see the outputs of all the tests. You'll get to see which tests failed and for what reason. If they all pass, you're set!

How to think about tests

Unit tests exist to prevent bugs that would happen in a real game. Thus, they should attempt to emulate the game world wherever possible. For example, the quick swap sanity test emulates a real scenario of the bug it fixed occurring by creating a character and giving it real items. The unrecommended alternative would be to create special test-only items. This isn't a hard rule, the reagent method exposure tests create a test-only reagent for example, but do keep it in mind.

Unit tests should also be just that--testing units of code. For example, instead of having one massive test for reagents, there are instead several smaller tests for testing exposure, metabolization, etc.

The unit testing API

You can find more information about all of these from their respective doc comments, but for a brief overview:

/datum/unit_test - The base for all tests to be ran. Subtypes must override Run(). New() and Destroy() can be used for setup and teardown. To fail, use TEST_FAIL(reason).

/datum/unit_test/proc/allocate(type, ...) - Allocates an instance of the provided type with the given arguments. Is automatically destroyed when the test is over. Commonly seen in the form of var/mob/living/carbon/human/human = allocate(/mob/living/carbon/human/consistent).

TEST_FAIL(reason) - Marks a failure at this location, but does not stop the test.

TEST_ASSERT(assertion, reason) - Stops the unit test and fails if the assertion is not met. For example: TEST_ASSERT(powered(), "Machine is not powered").

TEST_ASSERT_NOTNULL(a, message) - Same as TEST_ASSERT, but checks if !isnull(a). For example: TEST_ASSERT_NOTNULL(myatom, "My atom was never set!").

TEST_ASSERT_NULL(a, message) - Same as TEST_ASSERT, but checks if isnull(a). If not, gives a helpful message showing what a was. For example: TEST_ASSERT_NULL(delme, "Delme was never cleaned up!").

TEST_ASSERT_EQUAL(a, b, message) - Same as TEST_ASSERT, but checks if a == b. If not, gives a helpful message showing what both a and b were. For example: TEST_ASSERT_EQUAL(2 + 2, 4, "The universe is falling apart before our eyes!").

TEST_ASSERT_NOTEQUAL(a, b, message) - Same as TEST_ASSERT_EQUAL, but reversed.

TEST_FOCUS(test_path) - Only run the test provided within the parameters. Useful for reducing noise. For example, if we only want to run our example square test, we can add TEST_FOCUS(/datum/unit_test/square). Should never be pushed in a pull request--you will be laughed at.

Final Notes

  • Writing tests before you attempt to fix the bug can actually speed up development a lot! It means you don't have to go in game and folllow the same exact steps manually every time. This process is known as "TDD" (test driven development). Write the test first, make sure it fails, then start work on the fix/feature, and you'll know you're done when your tests pass. If you do try this, do make sure to confirm in a non-testing environment just to double check.
  • Make sure that your tests don't accidentally call RNG functions like prob. Since RNG is seeded during tests, you may not realize you have until someone else makes a PR and the tests fail!
  • Do your best not to change the behavior of non-testing code during tests. While it may sometimes be necessary in the case of situations such as the above, it is still a slippery slope that can lead to the code you're testing being too different from the production environment to be useful.