Skip to content

Commit

Permalink
fix test paths
Browse files Browse the repository at this point in the history
  • Loading branch information
bitwes committed Mar 16, 2018
1 parent d8a26a2 commit 974df1f
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 39 deletions.
6 changes: 3 additions & 3 deletions gut_tests_and_examples/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://scripts/main.gd" type="Script" id=1]
[ext_resource path="res://gut_tests_and_examples/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 Down Expand Up @@ -42,8 +42,8 @@ _disable_strict_datatype_checks = false
_test_prefix = "test_"
_file_prefix = "test_"
_file_extension = ".gd"
_directory1 = "res://test/unit"
_directory2 = "res://test/integration"
_directory1 = "res://gut_tests_and_examples/test/unit"
_directory2 = "res://gut_tests_and_examples/test/integration"
_directory3 = ""
_directory4 = ""
_directory5 = ""
Expand Down
14 changes: 7 additions & 7 deletions gut_tests_and_examples/scripts/main.gd
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func _on_tests_finished():
# 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://test/samples/test_sample_all_passed.gd')
load('res://addons/gut/gut.gd').new().test_script('res://gut_tests_and_examples/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://test/unit')
tester.add_directory('res://test/integration')
tester.add_directory('res://gut_tests_and_examples/test/unit')
tester.add_directory('res://gut_tests_and_examples/test/integration')

# Automatcially run all scripts when loaded.
tester.test_scripts(true)
Expand All @@ -97,10 +97,10 @@ func _run_all_tests():
# the resutls.
func _run_gut_tests(gut):
gut.set_should_print_to_console(false)
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.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.set_yield_between_tests(true)
# true says to run all the scripts, not just the first or
# the selected script.
Expand Down
50 changes: 26 additions & 24 deletions gut_tests_and_examples/test/unit/test_gut.gd
Original file line number Diff line number Diff line change
Expand Up @@ -229,18 +229,19 @@ func test_simulate_calls_physics_process():
# ------------------------------
# Setting test to run
# ------------------------------
const SAMPLES_DIR = 'res://gut_tests_and_examples/test/samples/'
func test_get_set_test_to_run():
gr.test.assert_get_set_methods(gr.test_gut, 'unit_test_name', '', 'hello')
assert_pass(4)

func test_setting_name_will_run_only_matching_tests():
gr.test_gut.add_script('res://test/samples/test_sample_all_passed.gd')
gr.test_gut.add_script(SAMPLES_DIR + 'test_sample_all_passed.gd')
gr.test_gut.set_unit_test_name('test_works')
gr.test_gut.test_scripts()
assert_eq(gr.test_gut.get_test_count(), 1)

func test_setting_name_matches_partial():
gr.test_gut.add_script('res://test/samples/test_sample_all_passed.gd')
gr.test_gut.add_script(SAMPLES_DIR + 'test_sample_all_passed.gd')
gr.test_gut.set_unit_test_name('two')
gr.test_gut.test_scripts()
assert_eq(gr.test_gut.get_test_count(), 1)
Expand Down Expand Up @@ -277,34 +278,35 @@ func test_asserts_on_test_object():
assert_file_not_empty(path)

func test_gut_clears_test_instances_between_runs():
gr.test_gut.add_script('res://test/samples/test_sample_all_passed.gd')
gr.test_gut.add_script(SAMPLES_DIR + 'test_sample_all_passed.gd')
gr.test_gut.test_scripts()
gr.test_gut.test_scripts()
assert_eq(gr.test_gut._test_script_objects.size(), 1, 'The should only be one test script after a second run')

# ------------------------------
# Loading diretories
# ------------------------------
const TEST_LOAD_DIR = 'res://gut_tests_and_examples/test/test_dir_load'
func test_adding_directory_loads_files():
gr.test_gut.add_directory('res://test/test_dir_load')
assert_has(gr.test_gut._test_scripts, 'res://test/test_dir_load/test_samples.gd')
gr.test_gut.add_directory(TEST_LOAD_DIR)
assert_has(gr.test_gut._test_scripts, TEST_LOAD_DIR + '/test_samples.gd')

func test_adding_directory_does_not_load_bad_prefixed_files():
gr.test_gut.add_directory('res://test/test_dir_load')
assert_does_not_have(gr.test_gut._test_scripts, 'res://test/test_dir_load/bad_prefix.gd')
gr.test_gut.add_directory(TEST_LOAD_DIR)
assert_does_not_have(gr.test_gut._test_scripts, TEST_LOAD_DIR + '/bad_prefix.gd')

func test_adding_directory_skips_files_with_wrong_extension():
gr.test_gut.add_directory('res://test/test_dir_load')
assert_does_not_have(gr.test_gut._test_scripts, 'res://test/test_dir_load/test_bad_extension.txt')
gr.test_gut.add_directory(TEST_LOAD_DIR)
assert_does_not_have(gr.test_gut._test_scripts, TEST_LOAD_DIR + '/test_bad_extension.txt')

func test_if_directory_does_not_exist_it_does_not_die():
gr.test_gut.add_directory('res://adsf')
assert_true(true, 'We should get here')

func test_adding_same_directory_does_not_add_duplicates():
gr.test_gut.add_directory('res://test/unit')
gr.test_gut.add_directory('res://gut_tests_and_examples/test/unit')
var orig = gr.test_gut._test_scripts.size()
gr.test_gut.add_directory('res://test/unit')
gr.test_gut.add_directory('res://gut_tests_and_examples/test/unit')
assert_eq(gr.test_gut._test_scripts.size(), orig)

# We only have 3 directories with tests in them so test 3
Expand All @@ -313,13 +315,13 @@ func test_directories123_defined_in_editor_are_loaded_on_ready():
var t = Test.new()
t.gut = g
g.set_yield_between_tests(false)
g._directory1 = 'res://test/test_dir_load'
g._directory2 = 'res://test/unit'
g._directory3 = 'res://test/integration'
g._directory1 = 'res://gut_tests_and_examples/test/test_dir_load'
g._directory2 = 'res://gut_tests_and_examples/test/unit'
g._directory3 = 'res://gut_tests_and_examples/test/integration'
add_child(g)
t.assert_has(g._test_scripts, 'res://test/test_dir_load/test_samples.gd', 'Should have dir1 script')
t.assert_has(g._test_scripts, 'res://test/unit/test_gut.gd', 'Should have dir2 script')
t.assert_has(g._test_scripts, 'res://test/integration/test_sample_all_passed_integration.gd', 'Should have dir3 script')
t.assert_has(g._test_scripts, 'res://gut_tests_and_examples/test/test_dir_load/test_samples.gd', 'Should have dir1 script')
t.assert_has(g._test_scripts, 'res://gut_tests_and_examples/test/unit/test_gut.gd', 'Should have dir2 script')
t.assert_has(g._test_scripts, 'res://gut_tests_and_examples/test/integration/test_sample_all_passed_integration.gd', 'Should have dir3 script')
assert_eq(t.get_pass_count(), 3, 'they should have passed')

# ^ aaaand then we test 2 more.
Expand All @@ -328,20 +330,20 @@ func test_directories456_defined_in_editor_are_loaded_on_ready():
var t = Test.new()
t.gut = g
g.set_yield_between_tests(false)
g._directory4 = 'res://test/test_dir_load'
g._directory5 = 'res://test/unit'
g._directory6 = 'res://test/integration'
g._directory4 = 'res://gut_tests_and_examples/test/test_dir_load'
g._directory5 = 'res://gut_tests_and_examples/test/unit'
g._directory6 = 'res://gut_tests_and_examples/test/integration'
add_child(g)
t.assert_has(g._test_scripts, 'res://test/test_dir_load/test_samples.gd', 'Should have dir4 script')
t.assert_has(g._test_scripts, 'res://test/unit/test_gut.gd', 'Should have dir5 script')
t.assert_has(g._test_scripts, 'res://test/integration/test_sample_all_passed_integration.gd', 'Should have dir6 script')
t.assert_has(g._test_scripts, 'res://gut_tests_and_examples/test/test_dir_load/test_samples.gd', 'Should have dir4 script')
t.assert_has(g._test_scripts, 'res://gut_tests_and_examples/test/unit/test_gut.gd', 'Should have dir5 script')
t.assert_has(g._test_scripts, 'res://gut_tests_and_examples/test/integration/test_sample_all_passed_integration.gd', 'Should have dir6 script')
assert_eq(t.get_pass_count(), 3, 'they should have passed')

# ------------------------------
# Signal tests
# ------------------------------
func test_when_moving_to_next_test_watched_signals_are_cleared():
gr.test_gut.add_script('res://test/unit/verify_signal_watches_are_cleared.gd')
gr.test_gut.add_script('res://gut_tests_and_examples/test/unit/verify_signal_watches_are_cleared.gd')
gr.test_gut.test_scripts()
assert_eq(gr.test_gut.get_pass_count(), 1, 'One test should have passed.')
assert_eq(gr.test_gut.get_fail_count(), 1, 'One failure for not watching anymore.')
Expand Down
6 changes: 1 addition & 5 deletions gut_tests_and_examples/project.godot → project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,8 @@ config/icon="res://icon.png"

[autoload]

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

[editor_plugins]

enabled=PoolStringArray( "gut" )

[rendering]

environment/default_environment="res://default_env.tres"

0 comments on commit 974df1f

Please sign in to comment.