Skip to content

Commit

Permalink
Merge branch 'cmfcmf-export-ignore'
Browse files Browse the repository at this point in the history
  • Loading branch information
bitwes committed Apr 8, 2018
2 parents c71d6b0 + b532b60 commit 022cf87
Show file tree
Hide file tree
Showing 31 changed files with 65 additions and 54 deletions.
9 changes: 7 additions & 2 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@
/.gitattributes export-ignore
/.gitignore export-ignore
/CHANGES.md export-ignore
/README.md export-ignore
/default_env.tres export-ignore
/icon.png export-ignore
/project.godot export-ignore
/README.md export-ignore

/gut_tests_and_examples export-ignore
/scenes export-ignore
/scripts export-ignore
/templates export-ignore
/test export-ignore
6 changes: 3 additions & 3 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ assert_has_method
* Missed changing `simulate` to call `_physics_process` instead of `_fixed_process` in the 3.0 conversion. Fixed that.
* Improved summary. It now lists all failures and pendings instead of just listing the scripts that have failures or pending tests.
* Fixed issue where the `signal_watcher` could try to disconnect from a freed object.
* Added `yield_to` which allows you to `yield` to a signal or a maximum amount of time. This keeps your tests moving along if you yield to a signal that never gets emitted. Now the test will fail after an amount of time instead of sitting in limbo forever. This will also watch the signals on the object so you can make asserts about signals after the `yield` and you can save a line of code.
* Added `yield_to` which allows you to `yield` to a signal or a maximum amount of time. This keeps your tests moving along if you yield to a signal that never gets emitted. Now the test will fail after an amount of time instead of sitting in limbo forever. This will also watch the signals on the object so you can make asserts about signals after the `yield` and you can save a line of code.
Example:
``` python
# wait for my_object to emit the signal 'my_signal'
# or 5 seconds, whichever comes first.
yield(yield_to(my_object, 'my_signal', 5), YIELD)
yield(yield_to(my_object, 'my_signal', 5), YIELD)
assert_signal_emitted(my_object, 'my_signal', \
'Maybe it did, maybe it didnt, but we still got here.')
```
Expand Down Expand Up @@ -54,7 +54,7 @@ Due to the restructuring I've completely moved the various `asserts` out of the

- New Methdos
- `assert_extends` Asserts that an instance of an object inherits from the class passed.
- Some changes to the log output.
- Some changes to the log output.
- Quick summary about each test script is included at the end of the run.
- Scripts that had a failing assert are listed together in the quick summary.
- Changed the GUI to have a fixed width font. It makes formatting the output easier and I like it more. Future changes should make customizing the GUI possible, so if you aren't fond of it you'll be able to change it sometime soon.
Expand Down
30 changes: 15 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ GUT (Godot Unit Test) is a utility for writing tests for your Godot Engine game.
Version 6.0.0 is Godot 3.0 compatible. These changes are not compatible with any of the 2.x versions of Godot. The godot_2x branch has been created to hold the old version of Gut that works with Godot 2.x. Barring any severe issues, there will not be any more development for Godot 2.x.

# License
Gut is provided under the MIT license. [The license is distributed with Gut so it is in the `addons/gut` folder](addons/gut/LICENSE.md). I also didn't want the Gut license to accidentally be copied into another project's root directory when installed through the Godot Asset Library.
Gut is provided under the MIT license.

# Method Links
<table><tr>
Expand Down Expand Up @@ -65,7 +65,7 @@ Gut is provided under the MIT license. [The license is distributed with Gut so

# <a name="install"> Install
## Installing from Download
Download and extract the zip from the [releases](https://github.com/bitwes/gut/releases) or from the [Godot Asset Library](https://godotengine.org/asset-library/asset/54).
Download and extract the zip from the [releases](https://github.com/bitwes/gut/releases) or from the [Godot Asset Library](https://godotengine.org/asset-library/asset/54).

Extract the zip and place the `gut` directory into your `addons` directory in your project. If you don't have an `addons` folder at the root of your project, then make one and THEN put the `gut` directory in there.

Expand Down Expand Up @@ -111,7 +111,7 @@ The following settings are accessible in the Editor under "Script Variables"
* <b>Disable Strict Datatype Checks</b>: Disables the verifying of datatypes before comparisons are done. You can disable this if you want. See the section on datatype checks for more details.
* <b>Test Prefix</b>: The prefix used on all test functions. This prefixed will be used by Gut to find tests inside your test scripts.
* <b>File Prefix</b>: The prefix used on all test files. This is used in conjunction with the Directory settings to find tests.
* <b>File Extension</b>: This is the suffix it will use to find test files.
* <b>File Extension</b>: This is the suffix it will use to find test files.
* <b>Directory(1-6)</b>: The path to the directories where your test scripts are located. Subdirectories are not included. If you need more than six directories you can use the `add_directory` method to add more.

# <a name="creating_tests"> Making Tests
Expand Down Expand Up @@ -167,7 +167,7 @@ Each test should perform at least one assert or call `pending` to indicate the t


# <a name="method_list"> Test Related Methods
These methods should be used in tests to make assertions. These methods are available to anything that inherits from the Test class (`extends "res://addons/gut/test.gd"`). All sample code listed for the methods can be found here in [test_readme_examples.gd](gut_tests_and_examples/test/samples/test_readme_examples.gd)
These methods should be used in tests to make assertions. These methods are available to anything that inherits from the Test class (`extends "res://addons/gut/test.gd"`). All sample code listed for the methods can be found here in [test_readme_examples.gd](test/samples/test_readme_examples.gd)
#### pending(text="")
flag a test as pending, the optional message is printed in the GUI
``` python
Expand Down Expand Up @@ -556,7 +556,7 @@ func test_assert_file_exists():

gut.p('-- failing --')
assert_file_exists('user://file_does_not.exist') # FAIL
assert_file_exists('res://some_dir/another_dir/file_does_not.exist') # FAIL
assert_file_exists('res://some_dir/another_dir/file_does_not.exist') # FAIL
```
#### <a name="assert_file_does_not_exist"> assert_file_does_not_exist(file_path)
asserts a file does not exist at the specified path
Expand Down Expand Up @@ -686,7 +686,7 @@ func test_assert_get_set_methods():

gut.p('-- failing --')
# 1 FAILING, 3 PASSING
assert_get_set_methods(some_class, 'count', 'not_default', 20)
assert_get_set_methods(some_class, 'count', 'not_default', 20)
# 2 FAILING, 2 PASSING
assert_get_set_methods(some_class, 'nothing', 'hello', 22)
# 2 FAILING
Expand Down Expand Up @@ -775,7 +775,7 @@ func test_illustrate_end_test():
end_test()
```
## <a name="gut_methods"> Methods for Configuring the Execution of Tests
These methods would be used inside the scene you created at `res://test/tests.tcn`. These methods can be called against the Gut node you created. Most of these are not necessary anymore since you can configure Gut in the editor but they are here if you want to use them. Simply put `get_node('Gut').` in front of any of them.
These methods would be used inside the scene you created at `res://test/tests.tcn`. These methods can be called against the Gut node you created. Most of these are not necessary anymore since you can configure Gut in the editor but they are here if you want to use them. Simply put `get_node('Gut').` in front of any of them.

<i>__**__ indicates the option can be set via the editor</i>
* `add_script(script, select_this_one=false)` add a script to be tetsted with test_scripts
Expand Down Expand Up @@ -821,7 +821,7 @@ The level of detail that is printed to the screen can be changed using the slide
* LOG_LEVEL_ALL_ASSERTS (2)

## <a name="printing"> Printing info
The `gut.p` method allows you to print information out indented under the test output. It has an optional 2nd parameter that sets which log level to display it at. Use one of the constants in the section above to set it. The default is `LOG_LEVEL_FAIL_ONLY` which means the output will always be visible.
The `gut.p` method allows you to print information out indented under the test output. It has an optional 2nd parameter that sets which log level to display it at. Use one of the constants in the section above to set it. The default is `LOG_LEVEL_FAIL_ONLY` which means the output will always be visible.


# <a name="advanced"> Advanced Testing
Expand Down Expand Up @@ -916,7 +916,7 @@ Sometimes you need to wait for a signal to be emitted, but you can never really
``` python
# wait for my_object to emit the signal 'my_signal'
# or 5 seconds, whichever comes first.
yield(yield_to(my_object, 'my_signal', 5), YIELD)
yield(yield_to(my_object, 'my_signal', 5), YIELD)
assert_signal_emitted(my_object, 'my_signal', \
'Maybe it did, maybe it didnt, but we still got here.')
```
Expand Down Expand Up @@ -957,16 +957,16 @@ The -d option tells Godot to run in debug mode which is helpful. The -s option
### Options
_Output from the command line help (-gh)_
```
---------------------------------------------------------
---------------------------------------------------------
This is the command line interface for the unit testing tool Gut. With this
interface you can run one or more test scripts from the command line. In order
for the Gut options to not clash with any other Godot options, each option
starts with a "g". Also, any option that requires a value will take the form of
"-g<name>=<value>". There cannot be any spaces between the option, the "=", or
inside a specified value or Godot will think you are trying to run a scene.
inside a specified value or Godot will think you are trying to run a scene.

Options
-------
Options
-------
-gtest Comma delimited list of tests to run
-gdir Comma delimited list of directories to add tests from.
-gprefix Prefix used to find tests when specifying -gdir. Default
Expand All @@ -984,7 +984,7 @@ Options
-gutloc Full path (including name) of the gut script. Default
res://addons/gut/gut.gd
-gh Print this help
---------------------------------------------------------
---------------------------------------------------------
```

### Examples
Expand Down Expand Up @@ -1018,7 +1018,7 @@ I got this one when I accidentally put a space instead of an "=" after -gselect.
# <a name="contributing"> Contributing
This testing tool has tests of course. All Gut related tests are found in the `test/unit` and `test/integration` directories. Any enhancements or bug fixes should have a corresponding pull request with new tests.

The bulk of the tests for Gut are in [test_gut.gd](gut_tests_and_examples/test/unit/test_gut.gd) and [test_test.gd](gut_tests_and_examples/test/unit/test_test.gd). [test_signal_watcher.gd](gut_tests_and_examples/test/unit/test_signal_watcher.gd) tests the class used to track the emitting of signals. The other test scripts in `unit` and `integration` should be run and their output spot checked since they test other parts of Gut that aren't easily testabled.
The bulk of the tests for Gut are in [test_gut.gd](test/unit/test_gut.gd) and [test_test.gd](test/unit/test_test.gd). [test_signal_watcher.gd](test/unit/test_signal_watcher.gd) tests the class used to track the emitting of signals. The other test scripts in `unit` and `integration` should be run and their output spot checked since they test other parts of Gut that aren't easily testabled.

For convenience, the `main.tscn` includes a handy "Run Gut Unit Tests" button that will kick off all the essential test scripts.

Expand Down
File renamed without changes.
File renamed without changes
6 changes: 5 additions & 1 deletion project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,12 @@ config/icon="res://icon.png"

[autoload]

global="*res://gut_tests_and_examples/scripts/global.gd"
global="*res://scripts/global.gd"

[editor_plugins]

enabled=PoolStringArray( "gut" )

[rendering]

environment/default_environment="res://default_env.tres"
10 changes: 6 additions & 4 deletions gut_tests_and_examples/scenes/main.tscn → scenes/main.tscn
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[gd_scene load_steps=4 format=2]

[ext_resource path="res://gut_tests_and_examples/scripts/main.gd" type="Script" id=1]
[ext_resource path="res://scripts/main.gd" type="Script" id=1]
[ext_resource path="res://addons/gut/gut.gd" type="Script" id=2]
[ext_resource path="res://addons/gut/icon.png" type="Texture" id=3]

Expand All @@ -21,6 +21,7 @@ anchor_bottom = 0.0
margin_right = 48.0
margin_bottom = 40.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
mouse_filter = 0
mouse_default_cursor_shape = 0
size_flags_horizontal = 1
Expand All @@ -42,9 +43,9 @@ _disable_strict_datatype_checks = false
_test_prefix = "test_"
_file_prefix = "test_"
_file_extension = ".gd"
_directory1 = "res://gut_tests_and_examples/test/unit"
_directory2 = "res://gut_tests_and_examples/test/integration"
_directory3 = "res://gut_tests_and_examples/test/samples"
_directory1 = "res://test/unit"
_directory2 = "res://test/integration"
_directory3 = "res://test/samples"
_directory4 = ""
_directory5 = ""
_directory6 = ""
Expand All @@ -60,6 +61,7 @@ margin_top = 18.0
margin_right = 908.0
margin_bottom = 93.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
focus_mode = 2
mouse_filter = 0
mouse_default_cursor_shape = 0
Expand Down
File renamed without changes.
24 changes: 12 additions & 12 deletions gut_tests_and_examples/scripts/main.gd → scripts/main.gd
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ func _on_tests_finished():
tester.p("Tests done callback called")

#------------------------------------
# This creates an instance of Gut and runs a single script. The output will
# This creates an instance of Gut and runs a single script. The output will
# be visible in the console, not the Gut instance on the screen.
#------------------------------------
func _run_test_one_line():
load('res://addons/gut/gut.gd').new().test_script('res://gut_tests_and_examples/test/samples/test_sample_all_passed.gd')
load('res://addons/gut/gut.gd').new().test_script('res://test/samples/test_sample_all_passed.gd')

#------------------------------------
# More lines, get result text out manually. Can also inspect the results further
Expand All @@ -82,8 +82,8 @@ func _run_all_tests():
# !! --------

# Add all scripts in two directories.
tester.add_directory('res://gut_tests_and_examples/test/unit')
tester.add_directory('res://gut_tests_and_examples/test/integration')
tester.add_directory('res://test/unit')
tester.add_directory('res://test/integration')

# Automatcially run all scripts when loaded.
tester.test_scripts(true)
Expand All @@ -92,21 +92,21 @@ func _run_all_tests():
if(tester.get_fail_count() > 0):
tester.p("SOMEBODY BROKE SOMETHIN'!!\n")

# These are all the tests that MUST be run to verify Gut is working as expected.
# These are all the tests that MUST be run to verify Gut is working as expected.
# Some methods may include tests that are expected to fail. Closely inspect
# the resutls.
func _run_gut_tests(gut):
gut.set_should_print_to_console(false)
gut.add_script('res://gut_tests_and_examples/test/unit/test_gut.gd')
gut.add_script('res://gut_tests_and_examples/test/unit/test_gut_yielding.gd')
gut.add_script('res://gut_tests_and_examples/test/unit/test_test.gd')
gut.add_script('res://gut_tests_and_examples/test/unit/test_signal_watcher.gd')
gut.add_script('res://test/unit/test_gut.gd')
gut.add_script('res://test/unit/test_gut_yielding.gd')
gut.add_script('res://test/unit/test_test.gd')
gut.add_script('res://test/unit/test_signal_watcher.gd')
gut.set_yield_between_tests(true)
# true says to run all the scripts, not just the first or
# true says to run all the scripts, not just the first or
# the selected script.
gut.test_scripts(true)
gut.test_scripts(true)

# Make a new Gut and run all the Gut specific tests.
# Make a new Gut and run all the Gut specific tests.
func _on_RunGutTestsButton_pressed():
var gut = load('res://addons/gut/gut.gd').new()
add_child(gut)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 022cf87

Please sign in to comment.