This PR replace the name heuristics used by nitunit by nice and tidy annotations.
Before:
~~~nit
module test_my_test is test_suite
import test_suite
class TestMyTest
super TestSuite
redef fun before do # something
fun test_my_test do
assert true
end
end
~~~
After:
~~~nit
module my_test is test
class MyTest
test
fun setup is before do # something
fun my_test is test do
assert true
end
end
~~~
Motivations:
* cleaner API / naming policy
* [BDD](https://en.wikipedia.org/wiki/Behavior-driven_development) friendly
* more flexibility as one can define a `after` method in the lib that will only be executed on children module tagged with `test`
* more extensible as one can improve nitunit to support `test(timeout = 150)` or `test(res= "res/test_file.res")`
Used annotations:
* `test` on modules, classes and properties to indicate that nitunit must run this module/class/method
* `before`, `after` on properties from all classes but `Sys` for the before/after each case hooks
* `before_all`, `after_all` on properties from `Sys` for the before/after all cases hooks
This also removes the need of the `lib/test_suite` module.
I also migrated the existing test suites to the new annotations system. Let's see what Jenkins has to say about it.
Should fix #2165
Pull-Request: #2474
Reviewed-by: Jean Privat <jean@pryen.org>
# limitations under the License.
# Test module for `achievements.nit`
-module test_achievements is test_suite
+module test_achievements is test
import test_helper
import achievements
class TestGame
super NitrpgTestHelper
+ test
- fun test_add_achievement do
+ fun test_add_achievement is test do
var db = gen_test_db
var game = load_game("Morriar/nit", db)
var a1 = new Achievement(game, "test_id1", "test_name", "test_desc", 15)
assert game.load_achievements.length == 2
end
- fun test_load_achievement do
+ fun test_load_achievement is test do
var db = gen_test_db
var game = load_game("Morriar/nit", db)
var a1 = new Achievement(game, "test_id1", "test_name", "test_desc", 15)
assert game.load_achievement(a2.id) == null
end
- fun test_load_achievements do
+ fun test_load_achievements is test do
var db = gen_test_db
var game = load_game("Morriar/nit", db)
var a1 = new Achievement(game, "test_id1", "test_name", "test_desc", 15)
class TestPlayer
super NitrpgTestHelper
+ test
- fun test_add_achievement do
+ fun test_add_achievement is test do
var db = gen_test_db
var game = load_game("Morriar/nit", db)
var player1 = new Player(game, "Morriar")
assert player1.load_achievements.length == 2
end
- fun test_load_achievement do
+ fun test_load_achievement is test do
var db = gen_test_db
var game = load_game("Morriar/nit", db)
var player1 = new Player(game, "Morriar")
assert player2.load_achievement(a1.id) == null
end
- fun test_load_achievements do
+ fun test_load_achievements is test do
var db = gen_test_db
var game = load_game("Morriar/nit", db)
var player1 = new Player(game, "Morriar")
class TestAchievement
super NitrpgTestHelper
+ test
- fun test_init do
+ fun test_init is test do
var db = gen_test_db
var game = load_game("Morriar/nit", db)
var a = new Achievement(game, "test_id", "test_name", "test_desc", 15)
assert a.reward == 15
end
- fun test_init_from_json do
+ fun test_init_from_json is test do
var db = gen_test_db
var game = load_game("Morriar/nit", db)
var json = """{
# limitations under the License.
# Test module for `events.nit`
-module test_events is test_suite
+module test_events is test
import test_helper
import events
class TestGame
super NitrpgTestHelper
+ test
- fun test_add_event do
+ fun test_add_event is test do
var db = gen_test_db
var game = load_game("Morriar/nit", db)
var event1 = new GameEvent(game, "test_kind", new JsonObject)
assert game.load_events.length == 2
end
- fun test_load_event do
+ fun test_load_event is test do
var db = gen_test_db
var game = load_game("Morriar/nit", db)
var event1 = new GameEvent(game, "test_kind", new JsonObject)
assert game.load_event(event2.internal_id) == null
end
- fun test_load_events do
+ fun test_load_events is test do
var db = gen_test_db
var game = load_game("Morriar/nit", db)
var event1 = new GameEvent(game, "test_kind", new JsonObject)
class TestPlayer
super NitrpgTestHelper
+ test
- fun test_add_event do
+ fun test_add_event is test do
var db = gen_test_db
var game = load_game("Morriar/nit", db)
var player1 = new Player(game, "Morriar")
assert player2.load_events.length == 0
end
- fun test_load_event do
+ fun test_load_event is test do
var db = gen_test_db
var game = load_game("Morriar/nit", db)
var player1 = new Player(game, "Morriar")
assert player2.load_event(event1.internal_id) == null
end
- fun test_load_events do
+ fun test_load_events is test do
var db = gen_test_db
var game = load_game("Morriar/nit", db)
var player1 = new Player(game, "Morriar")
class TestGameEvent
super NitrpgTestHelper
+ test
- fun test_init do
+ fun test_init is test do
var db = gen_test_db
var game = load_game("Morriar/nit", db)
var event = new GameEvent(game, "test_kind", new JsonObject)
assert event.to_json_object["kind"] == "test_kind"
end
- fun test_init_from_json do
+ fun test_init_from_json is test do
var db = gen_test_db
var game = load_game("Morriar/nit", db)
var json = """{
# limitations under the License.
# Test module for `game.nit`.
-module test_game is test_suite
+module test_game is test
import test_helper
class TestGame
super NitrpgTestHelper
+ test
- fun test_add_player do
+ fun test_add_player is test do
var db = gen_test_db
var game = load_game("privat/nit", db)
var users = ["Morriar", "xymus"]
end
end
- fun test_load_player do
+ fun test_load_player is test do
var db = gen_test_db
var game = load_game("privat/nit", db)
var ogame = load_game("Morriar/nit", db)
assert ogame.load_player("Morriar") == null
end
- fun test_load_players do
+ fun test_load_players is test do
var db = gen_test_db
var game = load_game("privat/nit", db)
var ogame = load_game("Morriar/nit", db)
class TestPlayer
super NitrpgTestHelper
+ test
- fun test_init do
+ fun test_init is test do
var db = gen_test_db
var game = load_game("privat/nit", db)
var player = new Player(game, "Morriar")
assert player.nitcoins == 0
end
- fun test_init_from_json do
+ fun test_init_from_json is test do
var db = gen_test_db
var game = load_game("privat/nit", db)
var json = """{"name": "Morriar", "nitcoins": 10}""".parse_json
assert player.nitcoins == 10
end
- fun test_save do
+ fun test_save is test do
var db = gen_test_db
var game = load_game("privat/nit", db)
var json = """{"name": "Morriar", "nitcoins": 10}""".parse_json.as(JsonObject)
assert game.db.collection("players").find(json) != null
end
- fun test_game_add_player do
+ fun test_game_add_player is test do
var db = gen_test_db
var game = load_game("privat/nit", db)
game.add_player(game.api.load_user("Morriar").as(not null))
assert game.db.collection("players").find(json) != null
end
- fun test_game_load_player do
+ fun test_game_load_player is test do
var db = gen_test_db
var game = load_game("privat/nit", db)
var json = """{"name": "Morriar", "nitcoins": 10}""".parse_json.as(JsonObject)
class TestUser
super NitrpgTestHelper
+ test
- fun test_player do
+ fun test_player is test do
var db = gen_test_db
var api = new GithubAPI(get_github_oauth)
var game = load_game("privat/nit", db)
# Test tools for NitRPG.
module test_helper
-import test_suite
import game
import github::cache
# Used to factorize test treatments.
abstract class NitrpgTestHelper
- super TestSuite
# Github API client
var api: GithubAPI do
db.drop
end
- redef fun after_test do drop_test_db
+ # Drop the databse after each test
+ fun after_test is after do drop_test_db
end
# limitations under the License.
# Test module for `listener.nit`
-module test_listener is test_suite
+module test_listener is test
import test_helper
import reactors
private class DummyListener
super NitrpgTestHelper
+ test
var reactors = new Array[GameReactor]
class TestListener
super NitrpgTestHelper
+ test
var generator = new EventsGenerator(api)
var repo: Repo is lazy do return load_repo("Morriar/nit")
- fun test_game_issue_stats do
+ fun test_game_issue_stats is test do
var db = gen_test_db
var l = new DummyListener
l.add_reactor(new StatisticsReactor)
assert game.stats.overall["issues_open"] == 1
end
- fun test_player_issue_stats do
+ fun test_player_issue_stats is test do
var db = gen_test_db
var game = load_game("Morriar/nit", db)
var l = new DummyListener
assert player.stats.overall["issues_open"] == 1
end
- fun test_game_pr_stats do
+ fun test_game_pr_stats is test do
var db = gen_test_db
var l = new DummyListener
l.add_reactor(new StatisticsReactor)
assert game.stats.overall["commits"] == 2
end
- fun test_game_issue_comment_stats do
+ fun test_game_issue_comment_stats is test do
var db = gen_test_db
var l = new DummyListener
l.add_reactor(new StatisticsReactor)
assert game.stats.overall["reviews"] == 1
end
- fun test_player_pull_reactor do
+ fun test_player_pull_reactor is test do
var db = gen_test_db
var game = load_game("Morriar/nit", db)
var l = new DummyListener
assert player.stats.overall["nitcoins"] == 12
end
- fun test_player_review_reactor do
+ fun test_player_review_reactor is test do
var db = gen_test_db
var game = load_game("Morriar/nit", db)
var l = new DummyListener
assert player.stats.overall["nitcoins"] == 4
end
- fun test_X_issues_achievements do
+ fun test_X_issues_achievements is test do
var db = gen_test_db
var game = load_game("Morriar/nit", db)
var l = new DummyListener
assert player.stats.overall["nitcoins"] == 1110
end
- fun test_X_pulls_achievements do
+ fun test_X_pulls_achievements is test do
var db = gen_test_db
var game = load_game("Morriar/nit", db)
var l = new DummyListener
assert player.stats.overall["nitcoins"] == 1110
end
- fun test_X_commits_achievements do
+ fun test_X_commits_achievements is test do
var db = gen_test_db
var game = load_game("Morriar/nit", db)
var l = new DummyListener
assert player.stats.overall["nitcoins"] == 11110
end
- fun test_X_comments_achievements do
+ fun test_X_comments_achievements is test do
var db = gen_test_db
var game = load_game("Morriar/nit", db)
var l = new DummyListener
assert player.stats.overall["nitcoins"] == 1110
end
- fun test_issues_achievements do
+ fun test_issues_achievements is test do
var db = gen_test_db
var game = load_game("Morriar/nit", db)
var l = new DummyListener
assert player.stats.overall["nitcoins"] == 20
end
- fun test_comments_reactor do
+ fun test_comments_reactor is test do
var db = gen_test_db
var game = load_game("Morriar/nit", db)
var l = new DummyListener
# limitations under the License.
# Test module for `stats.nit`
-module test_statistics is test_suite
+module test_statistics is test
import test_helper
import statistics
class TestGame
super NitrpgTestHelper
+ test
- fun test_game_stats do
+ fun test_game_stats is test do
var db = gen_test_db
var game = load_game("privat/nit", db)
var stats = game.stats
class TestPlayer
super NitrpgTestHelper
+ test
- fun test_player_stats do
+ fun test_player_stats is test do
var db = gen_test_db
var game = load_game("privat/nit", db)
var player = new Player(game, "Morriar")
class TestGameStats
super NitrpgTestHelper
+ test
- fun test_init_from_json do
+ fun test_init_from_json is test do
var db = gen_test_db
var game = load_game("privat/nit", db)
var owner = new Player(game, "Morriar")
#
#
# A module for testing the classes in the bitmap module
-module test_bitmap is test_suite
+module test_bitmap is test
import bitmap
-import test_suite
class TestBitmap
- super TestSuite
+ test
- fun test_grayscale do
+ fun test_grayscale is test do
var bitmap = new Bitmap.with_size(400, 300)
for y in [0..300] do
for x in [0..200] do bitmap.set_pixel(x, y, 0x0077AAAA)
# Standard classes and methods used by default by Nit programs and libraries.
# This module is implicitly imported by every module.
-module core
+module core is
+ new_annotation test
+ new_annotation before
+ new_annotation before_all
+ new_annotation after
+ new_annotation after_all
+end
import posix
import environ
# You are allowed to redistribute it and sell it, alone or is a part of
# another product.
-module test_abstract_text is test_suite
+module test_abstract_text is test
-import test_suite
import text
intrude import ropes
class TestText
- super TestSuite
+ test
private var factories: Collection[TextFactory] = [
new ConcatFactory,
new FlatBufferFactory
: TextFactory]
- fun test_escape_to_c do
+ fun test_escape_to_c is test do
for f in factories do
assert f.create("abAB12<>&").escape_to_c == "abAB12<>&"
assert f.create("\n\"'\\").escape_to_c == "\\n\\\"\\'\\\\"
# See the License for the specific language governing permissions and
# limitations under the License.
-module test_github_curl is test_suite
+module test_github_curl is test
import github::github_curl
-import test_suite
class TestGithubCurl
- super TestSuite
+ test
var auth: String = get_github_oauth
var user_agent: String = "nit"
var testee: GithubCurl is noinit
- redef fun before_test do
+ fun before_test is before do
testee = new GithubCurl(auth, user_agent)
end
- fun test_get_repo do
+ fun test_get_repo is test do
var uri = "https://api.github.com/repos/nitlang/nit"
var res = testee.get_and_check(uri)
assert res["owner"] isa JsonObject
end
- fun test_get_user do
+ fun test_get_user is test do
var uri = "https://api.github.com/users/Morriar"
var res = testee.get_and_check(uri)
# See the License for the specific language governing permissions and
# limitations under the License.
-module test_native_gmp is test_suite
+module test_native_gmp is test
-import test_suite
import native_gmp
class TestNativeMPZ
- super TestSuite
+ test
var op1: NativeMPZ
var op2: NativeMPZ
var r: NativeMPQ
var res: NativeMPZ
- init do end
-
- redef fun before_test do
+ fun before_test is before do
op1 = new NativeMPZ
op2 = new NativeMPZ
ui = new UInt64
res = new NativeMPZ
end
- redef fun after_test do
+ fun after_test is after do
op1.finalize
op2.finalize
ui.free
end
class TestNativeMPQ
- super TestSuite
+ test
var op1: NativeMPQ
var op2: NativeMPQ
var l: NativeMPZ
var res: NativeMPQ
- init do end
-
- redef fun before_test do
+ fun before_test is before do
op1 = new NativeMPQ
op2 = new NativeMPQ
l = new NativeMPZ
res = new NativeMPQ
end
- redef fun after_test do
+ fun after_test is after do
op1.finalize
op2.finalize
l.finalize
# limitations under the License.
# Test suites for module `markdown`
-module test_markdown is test_suite
+module test_markdown is test
-import test_suite
intrude import markdown
class TestMarkdownProcessor
- super TestSuite
+ test
- fun test_process_empty do
+ fun test_process_empty is test do
var test = ""
var exp = ""
var res = test.md_to_html.write_to_string
assert res == exp
end
- fun test_process_tabs do
+ fun test_process_tabs is test do
var test = """
some code
"""
end
- fun test_process_par1 do
+ fun test_process_par1 is test do
var test = "test"
var exp = "<p>test</p>\n"
var res = test.md_to_html.write_to_string
assert res == exp
end
- fun test_process_par2 do
+ fun test_process_par2 is test do
var test = """
line1
line2
assert res == exp
end
- fun test_process_par3 do
+ fun test_process_par3 is test do
var test = """
Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
Aliquam hendrerit mi posuere lectus.
assert res == exp
end
- fun test_process_headings_1 do
+ fun test_process_headings_1 is test do
var test = """
This is a H1
=============
assert res == exp
end
- fun test_process_headings_2 do
+ fun test_process_headings_2 is test do
var test = """
# This is a H1
assert res == exp
end
- fun test_process_headings_3 do
+ fun test_process_headings_3 is test do
var test = """
# This is a H1 #
assert res == exp
end
- fun test_process_hr do
+ fun test_process_hr is test do
var test = """
* * *
assert res == exp
end
- fun test_process_bquote1 do
+ fun test_process_bquote1 is test do
var test = """
> This is a blockquote with two paragraphs. Lorem ipsum dolor sit amet,
> consectetuer adipiscing elit. Aliquam hendrerit mi posuere lectus.
assert res == exp
end
- fun test_process_bquote2 do
+ fun test_process_bquote2 is test do
var test = """
> This is a blockquote with two paragraphs. Lorem ipsum dolor sit amet,
consectetuer adipiscing elit. Aliquam hendrerit mi posuere lectus.
assert res == exp
end
- fun test_process_bquote3 do
+ fun test_process_bquote3 is test do
var test = """
> This is the first level of quoting.
>
assert res == exp
end
- fun test_process_list1 do
+ fun test_process_list1 is test do
var test = """
* Red
* Green
assert res == exp
end
- fun test_process_list2 do
+ fun test_process_list2 is test do
var test = """
+ Red
+ Green
assert res == exp
end
- fun test_process_list3 do
+ fun test_process_list3 is test do
var test = """
- Red
- Green
assert res == exp
end
- fun test_process_list4 do
+ fun test_process_list4 is test do
var test = """
1. Bird
2. McHale
assert res == exp
end
- fun test_process_list5 do
+ fun test_process_list5 is test do
var test = """
3. Bird
1. McHale
assert res == exp
end
- fun test_process_list6 do
+ fun test_process_list6 is test do
var test = """
* Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
Aliquam hendrerit mi posuere lectus. Vestibulum enim wisi,
assert res == exp
end
- fun test_process_list7 do
+ fun test_process_list7 is test do
var test = """
* Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
Aliquam hendrerit mi posuere lectus. Vestibulum enim wisi,
assert res == exp
end
- fun test_process_list8 do
+ fun test_process_list8 is test do
var test = """
* Bird
assert res == exp
end
- fun test_process_list9 do
+ fun test_process_list9 is test do
var test = """
1. This is a list item with two paragraphs. Lorem ipsum dolor
sit amet, consectetuer adipiscing elit. Aliquam hendrerit
assert res == exp
end
- fun test_process_list10 do
+ fun test_process_list10 is test do
var test = """
* This is a list item with two paragraphs.
assert res == exp
end
- fun test_process_list11 do
+ fun test_process_list11 is test do
var test = """
This is a paragraph
* and this is not a list
assert res == exp
end
- fun test_process_list_ext do
+ fun test_process_list_ext is test do
var test = """
This is a paragraph
* and this is not a list
assert res == exp
end
- fun test_process_code1 do
+ fun test_process_code1 is test do
var test = """
This is a normal paragraph:
assert res == exp
end
- fun test_process_code2 do
+ fun test_process_code2 is test do
var test = """
Here is an example of AppleScript:
assert res == exp
end
- fun test_process_code_ext1 do
+ fun test_process_code_ext1 is test do
var test = """
Here is an example of AppleScript:
~~~
assert res == exp
end
- fun test_process_code_ext2 do
+ fun test_process_code_ext2 is test do
var test = """
Here is an example of AppleScript:
```
assert res == exp
end
- fun test_process_code_ext3 do
+ fun test_process_code_ext3 is test do
var proc = new MarkdownProcessor
proc.ext_mode = false
assert res == exp
end
- fun test_process_code_ext4 do
+ fun test_process_code_ext4 is test do
var test = """
Here is an example of AppleScript:
beep
assert res == exp
end
- fun test_process_code_ext5 do
+ fun test_process_code_ext5 is test do
var test = """
```nit
print "Hello World!"
assert res == exp
end
- fun test_process_code_ext6 do
+ fun test_process_code_ext6 is test do
var test = """
~~~
print "Hello"
assert res == exp
end
- fun test_process_code_ext7 do
+ fun test_process_code_ext7 is test do
var test = """
~~~
print "Hello"
assert res == exp
end
- fun test_process_nesting1 do
+ fun test_process_nesting1 is test do
var test = """
> ## This is a header.
>
assert res == exp
end
- fun test_process_nesting2 do
+ fun test_process_nesting2 is test do
var test = """
* A list item with a blockquote:
assert res == exp
end
- fun test_process_nesting3 do
+ fun test_process_nesting3 is test do
var test = """
* A list item with a code block:
assert res == exp
end
- fun test_process_nesting4 do
+ fun test_process_nesting4 is test do
var test = """
* Tab
* Tab
end
# TODO
- # fun test_process_nesting5 do
+ # fun test_process_nesting5 is test do
# var test = """
# * this
#
# assert res == exp
# end
- fun test_process_emph1 do
+ fun test_process_emph1 is test do
var test = """
*single asterisks*
assert res == exp
end
- fun test_process_emph2 do
+ fun test_process_emph2 is test do
var test = "un*frigging*believable"
var exp = "<p>un<em>frigging</em>believable</p>\n"
var res = test.md_to_html.write_to_string
assert res == exp
end
- fun test_process_emph3 do
+ fun test_process_emph3 is test do
var proc = new MarkdownProcessor
proc.ext_mode = false
var test = "Con_cat_this"
assert res == exp
end
- fun test_process_emph_ext do
+ fun test_process_emph_ext is test do
var test = "Con_cat_this"
var exp = "<p>Con_cat_this</p>\n"
var res = test.md_to_html.write_to_string
assert res == exp
end
- fun test_process_xml1 do
+ fun test_process_xml1 is test do
var test = """
This is a regular paragraph.
assert res == exp
end
- fun test_process_xml2 do
+ fun test_process_xml2 is test do
var test = """
This is an image <img src="foo/bar" alt="baz"/> in a regular paragraph.
"""
assert res == exp
end
- fun test_process_xml3 do
+ fun test_process_xml3 is test do
var test = """
<div style=">"/>
"""
assert res == exp
end
- fun test_process_xml4 do
+ fun test_process_xml4 is test do
var test = """
<p>This is an example of a block element that should be escaped.</p>
<p>Idem for the second paragraph.</p>
assert res == exp
end
- fun test_process_xml5 do
+ fun test_process_xml5 is test do
var test = """
# Some more XML tests
assert res == exp
end
- fun test_process_span_code1 do
+ fun test_process_span_code1 is test do
var test = "Use the `printf()` function."
var exp = "<p>Use the <code>printf()</code> function.</p>\n"
var res = test.md_to_html.write_to_string
assert res == exp
end
- fun test_process_span_code2 do
+ fun test_process_span_code2 is test do
var test = "``There is a literal backtick (`) here.``"
var exp = "<p><code>There is a literal backtick (`) here.</code></p>\n"
var res = test.md_to_html.write_to_string
assert res == exp
end
- fun test_process_span_code3 do
+ fun test_process_span_code3 is test do
var test = """
A single backtick in a code span: `` ` ``
assert res == exp
end
- fun test_process_span_code4 do
+ fun test_process_span_code4 is test do
var test = "Please don't use any `<blink>` tags."
var exp = "<p>Please don't use any <code><blink></code> tags.</p>\n"
var res = test.md_to_html.write_to_string
assert res == exp
end
- fun test_process_span_code5 do
+ fun test_process_span_code5 is test do
var test = "`—` is the decimal-encoded equivalent of `—`."
var exp = "<p><code>&#8212;</code> is the decimal-encoded equivalent of <code>&mdash;</code>.</p>\n"
var res = test.md_to_html.write_to_string
assert res == exp
end
- fun test_process_escape1 do
+ fun test_process_escape1 is test do
var test = "\\*this text is surrounded by literal asterisks\\*"
var exp = "<p>*this text is surrounded by literal asterisks*</p>\n"
var res = test.md_to_html.write_to_string
assert res == exp
end
- fun test_process_escape2 do
+ fun test_process_escape2 is test do
var test = "1986\\. What a great season."
var exp = "<p>1986. What a great season.</p>\n"
var res = test.md_to_html.write_to_string
assert res == exp
end
- fun test_process_escape3 do
+ fun test_process_escape3 is test do
var test = "Ben & Lux"
var exp = "<p>Ben & Lux</p>\n"
var res = test.md_to_html.write_to_string
assert res == exp
end
- fun test_process_link1 do
+ fun test_process_link1 is test do
var test = """
This is [an example](http://example.com/ "Title") inline link.
assert res == exp
end
- fun test_process_link2 do
+ fun test_process_link2 is test do
var test = "See my [About](/about/) page for details."
var exp = "<p>See my <a href=\"/about/\">About</a> page for details.</p>\n"
var res = test.md_to_html.write_to_string
assert res == exp
end
- fun test_process_link3 do
+ fun test_process_link3 is test do
var test = """
This is [an example][id] reference-style link.
assert res == exp
end
- fun test_process_link4 do
+ fun test_process_link4 is test do
var test = """
This is multiple examples: [foo][1], [bar][2], [baz][3].
assert res == exp
end
- fun test_process_link5 do
+ fun test_process_link5 is test do
var test = """
This is multiple examples: [foo][a], [bar][A], [a].
assert res == exp
end
- fun test_process_link6 do
+ fun test_process_link6 is test do
var test = """
I get 10 times more traffic from [Google][] than from [Yahoo][] or [MSN][].
assert res == exp
end
- fun test_process_link7 do
+ fun test_process_link7 is test do
var test = """
Visit [Daring Fireball][] for more information.
assert res == exp
end
- fun test_process_link8 do
+ fun test_process_link8 is test do
var test = """
This one has a [line
break].
end
# FIXME unignore test once escape strings fixed
- # fun test_process_link9 do
+ # fun test_process_link9 is test do
# var test = """
# Foo [bar][].
#
# assert res == exp
# end
- fun test_process_img1 do
+ fun test_process_img1 is test do
var test = """
![Alt text](/path/to/img.jpg)
assert res == exp
end
- fun test_process_img2 do
+ fun test_process_img2 is test do
var test = """
![Alt text][id]
assert res == exp
end
- fun test_process_strike do
+ fun test_process_strike is test do
var proc = new MarkdownProcessor
proc.ext_mode = false
var test = "This is how you ~~strike text~~"
assert exp == res
end
- fun test_process_strike_ext do
+ fun test_process_strike_ext is test do
var test = "This is how you ~~strike text~~"
var exp = "<p>This is how you <del>strike text</del></p>\n"
var res = test.md_to_html.write_to_string
assert exp == res
end
- fun test_escape_bad_html do
+ fun test_escape_bad_html is test do
var test = "-1 if < , +1 if > and 0 otherwise"
var exp = "<p>-1 if < , +1 if > and 0 otherwise</p>\n"
var res = test.md_to_html.write_to_string
assert exp == res
end
- fun test_daring_encoding do
+ fun test_daring_encoding is test do
var test = """
AT&T has an ampersand in their name.
end
- fun test_daring_autolinks do
+ fun test_daring_autolinks is test do
var test = """
Link: <http://example.com/>.
assert res == exp
end
- fun test_daring_escape do
+ fun test_daring_escape is test do
var test = """
These should all get escaped:
assert res == exp
end
- fun test_daring_blockquotes do
+ fun test_daring_blockquotes is test do
var test = """
> Example:
>
assert res == exp
end
- fun test_daring_code_blocks do
+ fun test_daring_code_blocks is test do
var test = """
code block on the first line
assert res == exp
end
- fun test_daring_code_spans do
+ fun test_daring_code_spans is test do
var test = """
`<test a="` content of attribute `">`
assert res == exp
end
- fun test_daring_pars do
+ fun test_daring_pars is test do
var proc = new MarkdownProcessor
proc.ext_mode = false
assert res == exp
end
- fun test_daring_rules do
+ fun test_daring_rules is test do
var test = """
Dashes:
assert res == exp
end
- fun test_daring_images do
+ fun test_daring_images is test do
var test = """
![Alt text](/path/to/img.jpg)
assert res == exp
end
- fun test_daring_inline_html1 do
+ fun test_daring_inline_html1 is test do
var test = """
Here's a simple block:
assert res == exp
end
- fun test_daring_inline_html2 do
+ fun test_daring_inline_html2 is test do
var test = """
Simple block on one line:
assert res == exp
end
- fun test_daring_inline_html3 do
+ fun test_daring_inline_html3 is test do
var test = """
Paragraph one.
assert res == exp
end
- fun test_daring_links1 do
+ fun test_daring_links1 is test do
var test = """
Just a [URL](/url/).
assert res == exp
end
- fun test_daring_links2 do
+ fun test_daring_links2 is test do
var test = """
Foo [bar] [1].
assert res == exp
end
- fun test_daring_links3 do
+ fun test_daring_links3 is test do
var test = """
This is the [simple case].
assert res == exp
end
- fun test_daring_nested do
+ fun test_daring_nested is test do
var test = """
> foo
>
assert res == exp
end
- fun test_daring_list do
+ fun test_daring_list is test do
var test = """
## Unordered
assert res == exp
end
- fun test_daring_strong_em do
+ fun test_daring_strong_em is test do
var test = """
***This is strong and em.***
assert res == exp
end
- fun test_daring_tabs do
+ fun test_daring_tabs is test do
var test = """
+ this is a list item
indented with tabs
assert res == exp
end
- fun test_daring_tidyness do
+ fun test_daring_tidyness is test do
var test = """
> A list within a blockquote:
>
end
class TestBlock
- super TestSuite
+ test
# A dummy location for testing purposes.
var loc = new MDLocation(0, 0, 0, 0)
- fun test_has_blocks do
+ fun test_has_blocks is test do
var subject = new MDBlock(loc)
assert not subject.has_blocks
subject.first_block = new MDBlock(loc)
assert subject.has_blocks
end
- fun test_count_blocks do
+ fun test_count_blocks is test do
var subject = new MDBlock(loc)
assert subject.count_blocks == 0
subject.first_block = new MDBlock(loc)
assert subject.count_blocks == 2
end
- fun test_has_lines do
+ fun test_has_lines is test do
var subject = new MDBlock(loc)
assert not subject.has_lines
subject.first_line = new MDLine(loc, "")
assert subject.has_lines
end
- fun test_count_lines do
+ fun test_count_lines is test do
var subject = new MDBlock(loc)
assert subject.count_lines == 0
subject.first_line = new MDLine(loc, "")
assert subject.count_lines == 2
end
- fun test_split do
+ fun test_split is test do
var line1 = new MDLine(loc, "line1")
var line2 = new MDLine(loc, "line2")
var line3 = new MDLine(loc, "line3")
assert block.last_line == line2
end
- fun test_add_line do
+ fun test_add_line is test do
var subject = new MDBlock(loc)
assert subject.count_lines == 0
subject.add_line new MDLine(loc, "")
assert subject.count_lines == 2
end
- fun test_remove_line do
+ fun test_remove_line is test do
var line1 = new MDLine(loc, "line1")
var line2 = new MDLine(loc, "line2")
var line3 = new MDLine(loc, "line3")
assert subject.last_line == line3
end
- fun test_transform_headline1 do
+ fun test_transform_headline1 is test do
var subject = new MDBlock(loc)
var kind = new BlockHeadline(subject)
subject.add_line new MDLine(loc, " # Title 1 ")
assert subject.first_line.value == "Title 1"
end
- fun test_transform_headline2 do
+ fun test_transform_headline2 is test do
var subject = new MDBlock(loc)
var kind = new BlockHeadline(subject)
subject.add_line new MDLine(loc, " #####Title 5 ")
assert subject.first_line.value == "Title 5"
end
- fun test_remove_quote_prefix do
+ fun test_remove_quote_prefix is test do
var subject = new MDBlock(loc)
var kind = new BlockQuote(subject)
subject.add_line new MDLine(loc, " > line 1")
assert subject.first_line.next.next.value == "line 3"
end
- fun test_remove_leading_empty_lines_1 do
+ fun test_remove_leading_empty_lines_1 is test do
var block = new MDBlock(loc)
block.add_line new MDLine(loc, "")
block.add_line new MDLine(loc, "")
assert block.first_line.value == " text"
end
- fun test_remove_leading_empty_lines_2 do
+ fun test_remove_leading_empty_lines_2 is test do
var block = new MDBlock(loc)
block.add_line new MDLine(loc, " text")
block.remove_leading_empty_lines
assert block.first_line.value == " text"
end
- fun test_remove_trailing_empty_lines_1 do
+ fun test_remove_trailing_empty_lines_1 is test do
var block = new MDBlock(loc)
block.add_line new MDLine(loc, "")
block.add_line new MDLine(loc, "text")
assert block.last_line.value == "text"
end
- fun test_remove_trailing_empty_lines_2 do
+ fun test_remove_trailing_empty_lines_2 is test do
var block = new MDBlock(loc)
block.add_line new MDLine(loc, "text ")
assert not block.remove_trailing_empty_lines
assert block.last_line.value == "text "
end
- fun test_remove_surrounding_empty_lines do
+ fun test_remove_surrounding_empty_lines is test do
var block = new MDBlock(loc)
block.add_line new MDLine(loc, "")
block.add_line new MDLine(loc, "text")
end
class TestLine
- super TestSuite
+ test
# A dummy location for testing purposes.
var loc = new MDLocation(0, 0, 0, 0)
var subject: MDLine
- fun test_is_empty do
+ fun test_is_empty is test do
subject = new MDLine(loc, "")
assert subject.is_empty
subject = new MDLine(loc, " ")
assert not subject.is_empty
end
- fun test_leading do
+ fun test_leading is test do
subject = new MDLine(loc, "")
assert subject.leading == 0
subject = new MDLine(loc, " ")
assert subject.leading == 4
end
- fun test_trailing do
+ fun test_trailing is test do
subject = new MDLine(loc, "")
assert subject.trailing == 0
subject = new MDLine(loc, " ")
assert subject.trailing == 1
end
- fun test_line_type do
+ fun test_line_type is test do
var v = new MarkdownProcessor
subject = new MDLine(loc, "")
assert v.line_kind(subject) isa LineEmpty
assert v.line_kind(subject) isa LineOList
end
- fun test_line_type_ext do
+ fun test_line_type_ext is test do
var v = new MarkdownProcessor
subject = new MDLine(loc, " ~~~")
assert v.line_kind(subject) isa LineFence
assert v.line_kind(subject) isa LineFence
end
- fun test_count_chars do
+ fun test_count_chars is test do
subject = new MDLine(loc, "")
assert subject.count_chars('*') == 0
subject = new MDLine(loc, "* ")
assert subject.count_chars('*') == 0
end
- fun test_count_chars_start do
+ fun test_count_chars_start is test do
subject = new MDLine(loc, "")
assert subject.count_chars_start('*') == 0
subject = new MDLine(loc, "* ")
end
class TestHTMLDecorator
- super TestSuite
+ test
- fun test_headlines do
+ fun test_headlines is test do
var test = """
# **a**
## a.a
end
class TestTokenLocation
- super TestSuite
+ test
- fun test_token_location1 do
+ fun test_token_location1 is test do
var string = "**Hello** `World`"
var stack = [
"TokenStrongStar at 1,1--1,1",
(new TestTokenProcessor(stack)).process(string)
end
- fun test_token_location2 do
+ fun test_token_location2 is test do
var string = "**Hello**\n`World`\n*Bonjour*\n[le monde]()"
var stack = [
"TokenStrongStar at 1,1--1,1",
(new TestTokenProcessor(stack)).process(string)
end
- fun test_token_location3 do
+ fun test_token_location3 is test do
var string = """**Hello**
`World`
*Bonjour*
(new TestTokenProcessor(stack)).process(string)
end
- fun test_token_location4 do
+ fun test_token_location4 is test do
var string = "**Hello**\n\n`World`"
var stack = [
"TokenStrongStar at 1,1--1,1",
(new TestTokenProcessor(stack)).process(string)
end
- fun test_token_location5 do
+ fun test_token_location5 is test do
var string = "# *Title1*\n\n# *Title2*"
var stack = [
"TokenEmStar at 1,3--1,3",
end
class TestBlockLocation
- super TestSuite
+ test
var proc = new MarkdownProcessor
- fun test_block_location1 do
+ fun test_block_location1 is test do
var stack = [
"BlockHeadline: 1,1--1,8",
"BlockListItem: 2,1--2,6",
proc.process(string)
end
- fun test_block_location2 do
+ fun test_block_location2 is test do
var stack = [
"BlockHeadline: 1,1--1,11",
"BlockFence: 3,1--5,4",
proc.process(string)
end
- fun test_block_location3 do
+ fun test_block_location3 is test do
var stack = [
"BlockHeadline: 1,1--1,8",
"BlockHeadline: 3,1--3,10"]
# limitations under the License.
# Test suites for module `markdown`
-module test_wikilinks is test_suite
+module test_wikilinks is test
import test_markdown
import wikilinks
class TestTokenWikilink
- super TestSuite
+ test
- fun test_token_location1 do
+ fun test_token_location1 is test do
var string = "[[wikilink]]"
var stack = ["TokenWikiLink at 1,1--1,1"]
(new TestTokenProcessor(stack)).process(string)
end
- fun test_token_location2 do
+ fun test_token_location2 is test do
var string = "Hello [[World]]"
var stack = ["TokenWikiLink at 1,7--1,7"]
(new TestTokenProcessor(stack)).process(string)
end
- fun test_token_location3 do
+ fun test_token_location3 is test do
var string = "\nHello\nworld [[wikilink]] !"
var stack = ["TokenWikiLink at 3,7--3,7"]
(new TestTokenProcessor(stack)).process(string)
end
- fun test_token_location4 do
+ fun test_token_location4 is test do
var string = "[[link1]]\n\n[[link2]]"
var stack = [
"TokenWikiLink at 1,1--1,1",
(new TestTokenProcessor(stack)).process(string)
end
- fun test_token_location5 do
+ fun test_token_location5 is test do
var string = "[[link1]]\n[[link2]]"
var stack = [
"TokenWikiLink at 1,1--1,1",
(new TestTokenProcessor(stack)).process(string)
end
- fun test_token_location6 do
+ fun test_token_location6 is test do
var string = """
[[doc: github]]
# See the License for the specific language governing permissions and
# limitations under the License.
-module test_example_angular is test_suite
+module test_example_angular is test
import pop_tests
import example_angular
class TestExampleAngular
super TestPopcorn
+ test
redef fun client_test do
system "curl -s {host}:{port}/counter"
system "curl -s {host}:{port}/not_found" # handled by angular controller
end
- fun test_example_angular do
+ fun test_example_angular is test do
var app = new App
app.use("/counter", new CounterAPI)
app.use("/*", new StaticHandler(test_path / "../www/", "index.html"))
# See the License for the specific language governing permissions and
# limitations under the License.
-module test_example_post_handler is test_suite
+module test_example_post_handler is test
import pop_tests
import example_post_handler
class TestExamplePostHandler
super TestPopcorn
+ test
redef fun client_test do
system "curl -s {host}:{port}/ -X POST"
system "curl -s {host}:{port}/"
end
- fun test_example_post_handler do
+ fun test_example_post_handler is test do
var app = new App
app.use("/", new PostHandler)
run_test(app)
# See the License for the specific language governing permissions and
# limitations under the License.
-module test_example_query_string is test_suite
+module test_example_query_string is test
import pop_tests
import example_query_string
class TestExampleQueryString
super TestPopcorn
+ test
redef fun client_test do
system "curl -s {host}:{port}/"
system "curl -s {host}:{port}/?items=10\\&order=asc"
end
- fun test_example_query_string do
+ fun test_example_query_string is test do
var app = new App
app.use("/", new QueryStringHandler)
run_test(app)
# See the License for the specific language governing permissions and
# limitations under the License.
-module test_example_hello is test_suite
+module test_example_hello is test
import pop_tests
import example_hello
class TestExampleHello
super TestPopcorn
+ test
redef fun client_test do
system "curl -s {host}:{port}"
system "curl -s {host}:{port}/not_found/not_found"
end
- fun test_example_hello do
+ fun test_example_hello is test do
var app = new App
app.use("/", new HelloHandler)
run_test(app)
# See the License for the specific language governing permissions and
# limitations under the License.
-module test_example_advanced_logger is test_suite
+module test_example_advanced_logger is test
import pop_tests
import example_advanced_logger
class TestExampleAdvancedLogger
super TestPopcorn
+ test
redef fun client_test do
system "curl -s {host}:{port}/"
system "curl -s {host}:{port}/about"
end
- fun test_example_advanced_logger do
+ fun test_example_advanced_logger is test do
var app = new App
app.use_before("/*", new RequestTimeHandler)
app.use("/", new AnotherHandler)
# See the License for the specific language governing permissions and
# limitations under the License.
-module test_example_html_error_handler is test_suite
+module test_example_html_error_handler is test
import pop_tests
import example_html_error_handler
class TestExampleHtmlErrorHandler
super TestPopcorn
+ test
redef fun client_test do
system "curl -s {host}:{port}/"
system "curl -s {host}:{port}/about"
end
- fun test_example_html_error_handler do
+ fun test_example_html_error_handler is test do
var app = new App
app.use("/*", new HtmlErrorHandler)
run_test(app)
# See the License for the specific language governing permissions and
# limitations under the License.
-module test_example_simple_error_handler is test_suite
+module test_example_simple_error_handler is test
import pop_tests
import example_simple_error_handler
class TestExampleSimpleErrorHandler
super TestPopcorn
+ test
redef fun client_test do
system "curl -s {host}:{port}/"
system "curl -s {host}:{port}/about"
end
- fun test_example_simple_error_handler do
+ fun test_example_simple_error_handler is test do
var app = new App
app.use("/", new SomeHandler)
app.use("/*", new SimpleErrorHandler)
# See the License for the specific language governing permissions and
# limitations under the License.
-module test_example_simple_logger is test_suite
+module test_example_simple_logger is test
import pop_tests
import example_simple_logger
class TestExampleSimpleLogger
super TestPopcorn
+ test
redef fun client_test do
system "curl -s {host}:{port}/"
system "curl -s {host}:{port}/about"
end
- fun test_example_simple_logger do
+ fun test_example_simple_logger is test do
var app = new App
app.use_before("/*", new SimpleLoggerHandler)
app.use("/", new MyOtherHandler)
# See the License for the specific language governing permissions and
# limitations under the License.
-module test_example_glob_route is test_suite
+module test_example_glob_route is test
import pop_tests
import example_glob_route
class TestExampleGlobRoute
super TestPopcorn
+ test
redef fun client_test do
system "curl -s {host}:{port}/user/Morriar/item/10"
system "curl -s {host}:{port}/not_found/not_found"
end
- fun test_example_glob_route do
+ fun test_example_glob_route is test do
var app = new App
app.use("/user/:user/item/:item/*", new UserItem)
run_test(app)
# See the License for the specific language governing permissions and
# limitations under the License.
-module test_example_param_route is test_suite
+module test_example_param_route is test
import pop_tests
import example_param_route
class TestExampleParamRoute
super TestPopcorn
+ test
redef fun client_test do
system "curl -s {host}:{port}/Morriar"
system "curl -s {host}:{port}/not_found/not_found"
end
- fun test_example_param_route do
+ fun test_example_param_route is test do
var app = new App
app.use("/:user", new UserHome)
run_test(app)
# See the License for the specific language governing permissions and
# limitations under the License.
-module test_example_router is test_suite
+module test_example_router is test
import pop_tests
import example_router
class TestExampleRouter
super TestPopcorn
+ test
redef fun client_test do
system "curl -s {host}:{port}"
system "curl -s {host}:{port}/products/not_found"
end
- fun test_example_router do
+ fun test_example_router is test do
var user_router = new Router
user_router.use("/*", new UserLogger)
user_router.use("/", new UserHomepage)
# See the License for the specific language governing permissions and
# limitations under the License.
-module test_example_session is test_suite
+module test_example_session is test
import pop_tests
import example_session
class TestExampleSession
super TestPopcorn
+ test
redef fun client_test do
system "curl -s {host}:{port}/"
system "curl -s {host}:{port}/products/not_found"
end
- fun test_example_session do
+ fun test_example_session is test do
var app = new App
app.use("/*", new SessionInit)
app.use("/", new AppLogin)
# See the License for the specific language governing permissions and
# limitations under the License.
-module test_example_static is test_suite
+module test_example_static is test
import pop_tests
import example_static
class TestExampleStatic
super TestPopcorn
+ test
redef fun client_test do
system "curl -s {host}:{port}/css/style.css"
system "curl -s {host}:{port}/not_found.nit"
end
- fun test_example_static do
+ fun test_example_static is test do
var app = new App
app.use("/", new StaticHandler(test_path / "../public/"))
run_test(app)
# See the License for the specific language governing permissions and
# limitations under the License.
-module test_example_static_default is test_suite
+module test_example_static_default is test
import pop_tests
import example_static_default
class TestExampleStaticDefault
super TestPopcorn
+ test
redef fun client_test do
system "curl -s {host}:{port}/css/style.css"
system "curl -s {host}:{port}/not_found.nit"
end
- fun test_example_static_default do
+ fun test_example_static_default is test do
var app = new App
app.use("/", new StaticHandler(test_path / "../public/", "default.html"))
run_test(app)
# See the License for the specific language governing permissions and
# limitations under the License.
-module test_example_static_multiple is test_suite
+module test_example_static_multiple is test
import pop_tests
import example_static_multiple
class TestExampleStaticMultiple
super TestPopcorn
+ test
redef fun client_test do
system "curl -s {host}:{port}/css/style.css"
system "curl -s {host}:{port}/not_found.nit"
end
- fun test_example_static_multiple do
+ fun test_example_static_multiple is test do
var app = new App
app.use("/", new StaticHandler(test_path / "../public/"))
app.use("/", new StaticHandler(test_path / "../files/"))
# See the License for the specific language governing permissions and
# limitations under the License.
-module test_example_templates is test_suite
+module test_example_templates is test
import pop_tests
intrude import example_templates
class TestExampleTemplate
super TestPopcorn
+ test
redef fun client_test do
system "curl -s {host}:{port}/"
end
- fun test_example_template do
+ fun test_example_template is test do
var app = new App
app.use("/", new MyTemplateHandler)
run_test(app)
class TestExampleTemplateString
super TestPopcorn
+ test
redef fun client_test do
system "curl -s {host}:{port}/"
end
- fun test_example_template_string do
+ fun test_example_template_string is test do
var app = new App
app.use("/", new MyTemplateStringHandler)
run_test(app)
class TestExampleTemplateFile
super TestPopcorn
+ test
redef fun client_test do
system "curl -s {host}:{port}/"
end
- fun test_example_template_file do
+ fun test_example_template_file is test do
var app = new App
var handler = new MyTemplateFileHandler
handler.tpl_file = test_path / "../example_template.tpl"
class TestExampleTemplatePug
super TestPopcorn
+ test
redef fun client_test do
system "curl -s {host}:{port}/"
end
- fun test_example_template_pug do
+ fun test_example_template_pug is test do
var app = new App
app.use("/", new MyTemplatePugHandler)
run_test(app)
class TestExampleTemplatePugFile
super TestPopcorn
+ test
redef fun client_test do
system "curl -s {host}:{port}/"
end
- fun test_example_template_pug_file do
+ fun test_example_template_pug_file is test do
var app = new App
var handler = new MyTemplatePugFileHandler
handler.pug_file = test_path / "../example_template.pug"
# Here we use `curl` to access some URI on the app.
#
# ~~~nitish
-# module test_example_hello is test_suite
+# module test_example_hello is test
#
# import pop_tests
# import example_hello
#
# class TestExampleHello
# super TestPopcorn
+# test
#
-# fun test_example_hello do
+# fun example_hello is test do
# var app = new App
# app.use("/", new HelloHandler)
# run_test(app)
# See `examples/hello_world` for the complete example.
module pop_tests
-import test_suite
import popcorn
import pthreads
# TestSuite for Popcorn blackbox testing.
class TestPopcorn
- super TestSuite
# Host used to run App.
var host: String = test_host
# See the License for the specific language governing permissions and
# limitations under the License.
-module test_pop_routes is test_suite
+module test_pop_routes is test
import pop_routes
-import test_suite
class TestAppRoute
- super TestSuite
+ test
- fun test_root_match_only_one_uri do
+ fun test_root_match_only_one_uri is test do
var r = new AppRoute("/")
assert r.match("")
assert r.match("/")
assert not r.match("/user")
end
- fun test_strict_route_match_only_one_uri do
+ fun test_strict_route_match_only_one_uri is test do
var r = new AppRoute("/user")
assert not r.match("/")
assert r.match("/user")
end
class TestAppParamRoute
- super TestSuite
+ test
- fun test_param_route_match_good_uri_params_1 do
+ fun test_param_route_match_good_uri_params_1 is test do
var r = new AppParamRoute("/:id")
assert not r.match("/")
assert r.match("/user")
assert not r.match("/user/10")
end
- fun test_param_route_match_good_uri_params_2 do
+ fun test_param_route_match_good_uri_params_2 is test do
var r = new AppParamRoute("/user/:id")
assert not r.match("/")
assert not r.match("/user")
assert not r.match("/user/10/profile")
end
- fun test_param_route_match_good_uri_params_3 do
+ fun test_param_route_match_good_uri_params_3 is test do
var r = new AppParamRoute("/user/:id/profile")
assert not r.match("/")
assert not r.match("/user")
assert not r.match("/user/10/foo")
end
- fun test_param_route_match_good_uri_params_4 do
+ fun test_param_route_match_good_uri_params_4 is test do
var r = new AppParamRoute("/:id/:foo")
assert not r.match("/")
assert not r.match("/user")
assert not r.match("/user/10/10")
end
- fun test_param_route_match_good_uri_params_5 do
+ fun test_param_route_match_good_uri_params_5 is test do
var r = new AppParamRoute("/user/:id/:foo")
assert not r.match("/")
assert not r.match("/user")
assert not r.match("/user/10/10/profile")
end
- fun test_param_route_match_good_uri_params_6 do
+ fun test_param_route_match_good_uri_params_6 is test do
var r = new AppParamRoute("/user/:id/settings/:foo")
assert not r.match("/")
assert not r.match("/user")
end
class TestRouteMatching
- super TestSuite
+ test
- fun test_glob_route_match_good_uri_prefix1 do
+ fun test_glob_route_match_good_uri_prefix1 is test do
var r = new AppGlobRoute("/*")
assert r.match("/")
assert r.match("/user")
assert r.match("/user/10")
end
- fun test_glob_route_match_good_uri_prefix2 do
+ fun test_glob_route_match_good_uri_prefix2 is test do
var r = new AppGlobRoute("/user/*")
assert not r.match("/")
assert r.match("/user")
assert r.match("/user/10")
end
- fun test_glob_route_match_good_uri_prefix3 do
+ fun test_glob_route_match_good_uri_prefix3 is test do
var r = new AppGlobRoute("/user*")
assert not r.match("/")
assert r.match("/user")
assert r.match("/user/10")
end
- fun test_glob_route_work_with_parameters_1 do
+ fun test_glob_route_work_with_parameters_1 is test do
var r = new AppGlobRoute("/:id/*")
assert not r.match("/")
assert r.match("/user")
assert r.match("/user/10/profile")
end
- fun test_glob_route_work_with_parameters_2 do
+ fun test_glob_route_work_with_parameters_2 is test do
var r = new AppGlobRoute("/:id*")
assert not r.match("/")
assert r.match("/user")
assert r.match("/user/10")
end
- fun test_glob_route_work_with_parameters_3 do
+ fun test_glob_route_work_with_parameters_3 is test do
var r = new AppGlobRoute("/user/:id/*")
assert not r.match("/")
assert not r.match("/user")
assert r.match("/user/10/profile")
end
- fun test_glob_route_work_with_parameters_4 do
+ fun test_glob_route_work_with_parameters_4 is test do
var r = new AppGlobRoute("/user/:id*")
assert not r.match("/")
assert not r.match("/user")
# See the License for the specific language governing permissions and
# limitations under the License.
-module test_popcorn is test_suite
+module test_popcorn is test
import pop_tests
import popcorn
class TestPopcornRouter
super TestPopcorn
+ test
redef fun client_test do
system "curl -s {host}:{port}"
system "curl -s {host}:{port}/products/not_found"
end
- fun test_router do
+ fun test_router is test do
var app = new App
app.use("/", new TestHandler("/"))
app.use("/about", new TestHandler("/about"))
class TestPopcornRoutes
super TestPopcorn
+ test
redef fun client_test do
system "curl -s {host}:{port}"
system "curl -s {host}:{port}/user/id/not_found"
end
- fun test_routes do
+ fun test_routes is test do
var app = new App
app.use("/", new TestHandler("/"))
app.use("/user", new TestHandler("/user"))
# another product.
# Test suite for `attributes_impl`.
-module test_attributes_impl is test_suite
+module test_attributes_impl is test
-import test_suite
import sax::helpers::attributes_impl
class TestAttributesImpl
- super TestSuite
+ test
private fun sample: AttributesImpl do
var subject = new AttributesImpl
return subject
end
- fun test_length do
+ fun test_length is test do
var subject = new AttributesImpl
assert 0 == subject.length
assert 0 == subject.length
end
- fun test_uri do
+ fun test_uri is test do
var subject = sample
assert "http://example.com/" == subject.uri(0)
assert subject.uri(0) == null
end
- fun test_local_name do
+ fun test_local_name is test do
var subject = sample
assert "bar" == subject.local_name(0)
assert subject.local_name(0) == null
end
- fun test_qname do
+ fun test_qname is test do
var subject = sample
assert "foo:bar" == subject.qname(0)
assert subject.qname(0) == null
end
- fun test_type_of do
+ fun test_type_of is test do
var subject = sample
assert "CDATA" == subject.type_of(0)
assert subject.type_of(0) == null
end
- fun test_type_of_qname do
+ fun test_type_of_qname is test do
var subject = sample
assert "CDATA" == subject.type_of("foo:bar")
assert subject.type_of("xml:lang") == null
end
- fun test_value_of do
+ fun test_value_of is test do
var subject = sample
assert "baz" == subject.value_of(0)
assert subject.value_of(0) == null
end
- fun test_value_of_qname do
+ fun test_value_of_qname is test do
var subject = sample
assert "baz" == subject.value_of("foo:bar")
assert subject.value_of("xml:lang") == null
end
- fun test_index_ns do
+ fun test_index_ns is test do
var subject = sample
assert 0 == subject.index_ns("http://example.com/", "bar")
assert -1 == subject.index_ns("http://example.com/", "bar")
end
- fun test_index_of do
+ fun test_index_of is test do
var subject = sample
assert 0 == subject.index_of("foo:bar")
assert -1 == subject.index_of("foo:bar")
end
- fun test_type_ns do
+ fun test_type_ns is test do
var subject = sample
assert "CDATA" == subject.type_ns("http://example.com/", "bar")
assert subject.type_ns("http://example.com/", "bar") == null
end
- fun test_value_ns do
+ fun test_value_ns is test do
var subject = sample
assert "baz" == subject.value_ns("http://example.com/", "bar")
assert subject.value_ns("http://example.com/", "bar") == null
end
- fun test_attributes_set do
+ fun test_attributes_set is test do
var subject = sample
var subject2 = new AttributesImpl
assert subject.length == 4
end
- fun test_set do
+ fun test_set is test do
var subject = sample
subject.set(1, "urn:is:not:often:used", "i-am_ME", "i-am_ME", "ID",
assert "NMTOKENS" == subject.type_of(0)
end
- fun test_remove_at do
+ fun test_remove_at is test do
var subject = sample
subject.remove_at(1)
assert "xml:lang" == subject.qname(1)
end
- fun test_uri_set do
+ fun test_uri_set is test do
var subject = sample
subject.uri(0) = "https://example.org/serious"
assert "https://example.org/serious" == subject.uri(0)
end
- fun test_local_name_set do
+ fun test_local_name_set is test do
var subject = sample
subject.local_name(0) = "trololol"
assert "ImYou42" == subject.local_name(1)
end
- fun test_qname_set do
+ fun test_qname_set is test do
var subject = sample
subject.qname(0) = "go-to:bar"
assert "yo:i-am_ME" == subject.qname(1)
end
- fun test_type_of_set do
+ fun test_type_of_set is test do
var subject = sample
subject.type_of(0) = "NMTOKENS"
assert "ENTITY" == subject.type_of(1)
end
- fun test_value_of_set do
+ fun test_value_of_set is test do
var subject = sample
subject.value_of(0) = "buz"
# another product.
# Test suite for `namespace_support`.
-module test_namespace_support is test_suite
+module test_namespace_support is test
-import test_suite
import sax::helpers::namespace_support
class TestNamespaceSupport
- super TestSuite
+ test
private fun sample: NamespaceSupport do
var subject = new NamespaceSupport
return subject
end
- fun test_reset do
+ fun test_reset is test do
var subject = sample
subject.reset
assert 2 == subject.prefixes.length
end
- fun test_push_context_override_default do
+ fun test_push_context_override_default is test do
var subject = sample
subject.push_context
assert 3 == subject.prefixes.length
end
- fun test_push_context_override_dc do
+ fun test_push_context_override_dc is test do
var subject = sample
subject.push_context
assert 3 == subject.prefixes.length
end
- fun test_push_context_undeclare do
+ fun test_push_context_undeclare is test do
var subject = sample
subject.push_context
assert 2 == subject.prefixes.length
end
- fun test_pop_context do
+ fun test_pop_context is test do
var subject = sample
subject.pop_context
#fun test_declare_prefix # SEE: test_push_context_*
- fun test_process_name do
+ fun test_process_name is test do
var subject = sample
var parts = new Array[String]
assert ["", "p", "p"] == subject.process_name("p", parts, true)
end
- fun test_process_name_xmlns do
+ fun test_process_name_xmlns is test do
var subject = sample
var parts = new Array[String].with_capacity(3)
assert ["http://www.w3.org/1999/xhtml", "xmlns", "xmlns"] == subject.process_name("xmlns", parts, false)
end
- fun test_declare_prefix_illegal do
+ fun test_declare_prefix_illegal is test do
var subject = sample
assert not subject.declare_prefix("xml", "http://example.org")
assert 2 == subject.declared_prefixes.length
end
- fun test_uri do
+ fun test_uri is test do
var subject = sample
assert "http://www.w3.org/1999/xhtml" == subject.uri("")
assert subject.uri("foo") == null
end
- fun test_prefixes do
+ fun test_prefixes is test do
var res = sample.prefixes
assert 3 == res.length else
assert res.has("xmlns")
end
- fun test_prefix do
+ fun test_prefix is test do
var subject = sample
assert subject.prefix("http://www.w3.org/1999/xhtml") == null
assert subject.prefix("https://example.org/serious") == null
end
- fun test_prefixes_of do
+ fun test_prefixes_of is test do
var subject = sample
var res: Collection[String]
assert res.has_all(["dc", "dc2"])
end
- fun test_declared_prefixes do
+ fun test_declared_prefixes is test do
var res = sample.declared_prefixes
assert 2 == res.length else
# another product.
# Tests for SAXophoNit
-module test_saxophonit is test_suite
+module test_saxophonit is test
import sax::helpers::sax_locator_impl
import sax::helpers::attributes_impl
class TestSaxophonit
super SAXTestSuite
+ test
redef fun create_reader do return new XophonReader
- fun test_empty do
+ fun test_empty is test do
before_test
parse_string("<foo />")
expected.document_locator = new SAXLocatorImpl
assert_equals
end
- fun test_simple_element do
+ fun test_simple_element is test do
before_test
parse_string("<foo>bar</foo>")
expected.document_locator = new SAXLocatorImpl
assert_equals
end
- fun test_type_mismatch do
+ fun test_type_mismatch is test do
before_test
parse_string("<a></b>")
expected.document_locator = new SAXLocatorImpl
assert_equals
end
- fun test_attributes do
+ fun test_attributes is test do
var atts = new AttributesImpl
before_test
assert_equals
end
- fun test_nested do
+ fun test_nested is test do
var atts = new AttributesImpl
before_test
assert_equals
end
- fun test_xmldecl do
+ fun test_xmldecl is test do
before_test
parse_string("<?xml version='1.0'?><foo />")
expected.document_locator = new SAXLocatorImpl
assert_equals
end
- fun test_xmldecl_encoding do
+ fun test_xmldecl_encoding is test do
before_test
parse_string("<?xml version=\"1.0\" encoding='utf-8'?><foo />")
expected.document_locator = new SAXLocatorImpl
assert_equals
end
- fun test_xmldecl_standalone do
+ fun test_xmldecl_standalone is test do
before_test
parse_string("<?xml version='1.0' standalone=\"yes\"?><foo />")
expected.document_locator = new SAXLocatorImpl
assert_equals
end
- fun test_xmldecl_both do
+ fun test_xmldecl_both is test do
before_test
parse_string("<?xml version='1.0' encoding='utf-8' standalone=\"yes\"?><foo />")
expected.document_locator = new SAXLocatorImpl
assert_equals
end
- fun test_reference_builtin do
+ fun test_reference_builtin is test do
before_test
parse_string("<foo>&"'<>00:</foo>")
expected.document_locator = new SAXLocatorImpl
assert_equals
end
- fun test_comments do
+ fun test_comments is test do
# TODO For the moment, comments are simply ignored.
before_test
parse_string("<!-- I--><foo>bar<!--l-i-k-e--></foo><!--comments -->")
assert_equals
end
- fun test_ns_simple do
+ fun test_ns_simple is test do
before_test
parse_string("<foo:bar xmlns:foo='https://s.exemple.org' />")
expected.document_locator = new SAXLocatorImpl
assert_equals
end
- fun test_ns_prefix do
+ fun test_ns_prefix is test do
var atts = new AttributesImpl
before_test
assert_equals
end
- fun test_mixed do
+ fun test_mixed is test do
var atts = new AttributesImpl
# TODO For the moment, ignorable white space is not detected.
# another product.
# Test suite for `testing`.
-module test_testing is test_suite
+module test_testing is test
import saxophonit::testing
-import test_suite
class TestSaxEventLogger
- super TestSuite
+ test
# Constants for diff formatting.
private var init_done: Bool = false
- redef fun before_test do
- super
+ fun before_test is before do
if not init_done then
default = a.term_default
ins = a.term_insertion
end
end
- fun test_diff_empty do
+ fun test_diff_empty is test do
assert "" == a.diff(b).to_s
assert "" == b.diff(a).to_s
end
- fun test_diff_equal1 do
+ fun test_diff_equal1 is test do
b.start_document
a.start_document
assert "" == a.diff(b).to_s
assert "" == b.diff(a).to_s
end
- fun test_diff_equal2 do
+ fun test_diff_equal2 is test do
b.start_document
b.end_document
a.start_document
assert "" == b.diff(a).to_s
end
- fun test_diff_insertion do
+ fun test_diff_insertion is test do
var exp: String
var test: String
assert_equals(2, exp, test)
end
- fun test_diff_edition do
+ fun test_diff_edition is test do
var exp: String
var test: String
import sax::ext::decl_handler
import sax::ext::lexical_handler
import console
-import test_suite
# A filter that internally log events it recieves.
#
# Base class for test suites on a SAX reader.
abstract class SAXTestSuite
- super TestSuite
# Logger of the expected event sequence.
var expected = new SAXEventLogger
private var init_done: Bool = false
- redef fun before_test do
- super
+ fun before_test is before do
if not init_done then
reader = create_reader
actual.parent = reader
# See the License for the specific language governing permissions and
# limitations under the License.
-module test_macro is test_suite
+module test_macro is test
-import test_suite
import macro
class TestTemplateString
- super TestSuite
+ test
- fun test_tpl_parse_1 do
+ fun test_tpl_parse_1 is test do
var tpl = """
<!DOCTYPE html>
<html lang="en">
assert res == tpl
end
- fun test_tpl_parse_2 do
+ fun test_tpl_parse_2 is test do
var tpl = """
<!DOCTYPE html>
<html lang="en">
assert res == tpl
end
- fun test_tpl_parse_3 do
+ fun test_tpl_parse_3 is test do
var tpl = """
<!DOCTYPE html>
<html lang="en">
assert res == tpl
end
- fun test_tpl_parse_4 do
+ fun test_tpl_parse_4 is test do
var tpl = """
<!DOCTYPE html>
<html lang="en">
assert res == tpl
end
- fun test_tpl_parse_5 do
+ fun test_tpl_parse_5 is test do
var tpl = """
<!DOCTYPE html>
<html lang="en">
assert res == tpl
end
- fun test_tpl_parse_6 do
+ fun test_tpl_parse_6 is test do
var tpl = """
<!DOCTYPE html>
<html lang="en">
assert res == tpl
end
- fun test_tpl_replace_1 do
+ fun test_tpl_replace_1 is test do
var tpl = """
<!DOCTYPE html>
<html lang="en">
assert res == exp
end
- fun test_tpl_replace_2 do
+ fun test_tpl_replace_2 is test do
var tpl = """
<!DOCTYPE html>
<html lang="en">
assert res == exp
end
- fun test_tpl_replace_3 do
+ fun test_tpl_replace_3 is test do
var tpl = """
<!DOCTYPE html>
<html lang="en">
+++ /dev/null
-[package]
-name=test_suite
-tags=devel,lib
-maintainer=Alexandre Terrasa <alexandre@moz-code.org>
-license=Apache-2.0
-[upstream]
-browse=https://github.com/nitlang/nit/tree/master/lib/test_suite.nit
-git=https://github.com/nitlang/nit.git
-git.directory=lib/test_suite.nit
-homepage=http://nitlanguage.org
-issues=https://github.com/nitlang/nit/issues
+++ /dev/null
-# This file is part of NIT ( http://www.nitlanguage.org ).
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-# Common interface for `nitunit` test-suites.
-module test_suite is
- # Annotation used by test-suite modules.
- new_annotation test_suite
-end
-
-# A test-suite that can be executed by `nitunit`.
-#
-# All test-suite classes must implement `TestSuite`.
-class TestSuite
- # Internal empty init.
- private init nitunit do end
-
- # Method called before each test-case.
- #
- # Redefine this method to factorize code that have to be
- # executed before every test.
- fun before_test do end
-
- # Method called after each test-case.
- #
- # Redefine this method to factorize code that have to be
- # executed after every test.
- fun after_test do end
-end
-
-redef class Sys
- # Internal empty init.
- private init nitunit do end
-
- # No before test for the module
- private fun before_test do end
-
- # No after test for the module
- private fun after_test do end
-
- # Method called before each test-suite.
- #
- # Redefine this method to factorize code that have to be
- # executed before every test suite.
- fun before_module do end
-
- # Method called after each test-suite.
- #
- # Redefine this method to factorize code that have to be
- # executed after every test suite.
- fun after_module do end
-end
TestSuites are Nit modules that define a set of TestCases.
-A test suite is a module that uses the annotation `is test_suite`.
+A test suite is a module that uses the annotation `is test`.
It is common that a test suite focuses on testing a single module.
-In this case, the name of the test_suite is often `test_foo.nit` where `foo.nit` is the tested module.
+In this case, the name of the test suite is often `test_foo.nit` where `foo.nit` is the tested module.
The structure of a test suite is the following:
~~~~
# test suite for module `foo`
-module test_foo is test_suite
+module test_foo is test
-import test_suite
import foo # can be intrude to test private things
class TestFoo
- super TestSuite
+ test
# test case for `foo::Foo::baz`
- fun test_baz do
+ fun baz is test do
var subject = new Foo
assert subject.baz(1, 2) == 3
end
$ nitunit foo.nit
-`nitunit` will execute a test for each method named `test_*` in a class
-subclassing `TestSuite` so multiple tests can be executed for a single method:
+`nitunit` will execute a test for each method with the `test` annotation in a class
+also annotated with `test` so multiple tests can be executed for a single method:
~~~~
class TestFoo
- super TestSuite
+ test
- fun test_baz_1 do
+ fun baz_1 is test do
var subject = new Foo
assert subject.baz(1, 2) == 3
end
- fun test_baz_2 do
+ fun baz_2 is test do
var subject = new Foo
assert subject.baz(1, -2) == -1
end
The test is failed if non-zero is returned by `diff`.
~~~
-module test_mod is test_suite
+module test_mod is test
class TestFoo
- super TestSuite
+ test
- fun test_bar do
+ fun bar is test do
print "Hello!"
end
end
## Configuring TestSuites
-`TestSuite`s also provide methods to configure the test run:
-
-`before_test` and `after_test`: methods called before/after each test case.
+`TestSuite`s also provide annotations to configure the test run:
+`before` and `after` annotations can be applied to methods that must be called before/after each test case.
They can be used to factorize repetitive tasks:
~~~~
class TestFoo
- super TestSuite
+ test
+
var subject: Foo
+
# Mandatory empty init
init do end
+
# Method executed before each test
- fun before_test do
+ fun set_up is before do
subject = new Foo
end
- fun test_baz_1 do
+ fun baz_1 is test do
assert subject.baz(1, 2) == 3
end
- fun test_baz_2 do
+ fun baz_2 is test do
assert subject.baz(1, -2) == -1
end
end
When using custom test attributes, an empty `init` must be declared to allow automatic test running.
-`before_module` and `after_module`: methods called before/after each test suite.
+`before_all` and `after_all` annotations can be applied to methods that must be called before/after each test suite.
They have to be declared at top level:
~~~~
The `NIT_TESTING_PATH` environment variable contains the current test suite
file path.
Nitunit define this variable before the execution of each test suite.
-It can be used to access files based on the current test_suite location:
+It can be used to access files based on the current test suite location:
~~~
class TestWithPath
- super TestSuite
+ test
fun test_suite_path do
assert "NIT_TESTING_PATH".environ != ""
end
end
var ms = gs
- if m.is_test_suite then ms /= 100.0
+ if m.is_test then ms /= 100.0
entity_score += ms
if m.mdoc != null then doc_score += ms else ms /= 10.0
for cd in m.mclassdefs do
# See the License for the specific language governing permissions and
# limitations under the License.
-module test_coloring is test_suite
+module test_coloring is test
-import test_suite
import coloring
class TestPOSetColorer
- super TestSuite
+ test
- fun test_ids_strictly_positive do
+ fun test_ids_strictly_positive is test do
var poset = new POSet[String]
poset.add_node "A"
var modelbuilder = toolcontext.modelbuilder
- # Disable `missing-doc` for `test_suite`
- if source != null and not nmoduledecl.get_annotations("test_suite").is_empty then
+ # Disable `missing-doc` for `test`
+ if source != null and not nmoduledecl.get_annotations("test").is_empty then
toolcontext.warning_blacklist[source].add("missing-doc")
end
redef class MModule
super AnnotatedMEntity
+
+ redef var is_test is lazy do return has_annotation("test")
end
redef class MClassDef
super AnnotatedMEntity
+
+ redef var is_test is lazy do return has_annotation("test")
end
redef class MPropDef
super AnnotatedMEntity
+
+ redef var is_test is lazy do return has_annotation("test")
+
+ redef var is_before is lazy do return has_annotation("before")
+
+ redef var is_before_all is lazy do return has_annotation("before_all")
+
+ redef var is_after is lazy do return has_annotation("after")
+
+ redef var is_after_all is lazy do return has_annotation("after_all")
end
mmodule.mdoc = mdoc
mdoc.original_mentity = mmodule
end
- # Is the module a test suite?
- mmodule.is_test_suite = not decl.get_annotations("test_suite").is_empty
# Is the module generated?
mmodule.is_generated = not decl.get_annotations("generated").is_empty
end
end
end
- # Is `self` a unit test module used by `nitunit`?
- var is_test_suite: Bool = false is writable
-
# Is `self` a module generated by a tool?
#
# This flag has no effect on the semantic.
# Is `self` and abstract class?
var is_abstract: Bool is lazy do return kind == abstract_kind
+ redef var is_test is lazy do return intro.is_test
+
redef fun mdoc_or_fallback
do
# Don’t use `intro.mdoc_or_fallback` because it would create an infinite
end
private var lookup_all_definitions_cache = new HashMap2[MModule, MType, Array[MPROPDEF]]
+
+ redef var is_test is lazy do return intro.is_test
+
+ # Does self have the `before` annotation?
+ var is_before: Bool is lazy do return intro.is_before
+
+ # Does self have the `before_all` annotation?
+ var is_before_all: Bool is lazy do return intro.is_before_all
+
+ # Does self have the `after` annotation?
+ var is_after: Bool is lazy do return intro.is_after
+
+ # Does self have the `after_all` annotation?
+ var is_after_all: Bool is lazy do return intro.is_after_all
end
# A global method
end
redef fun mdoc_or_fallback do return mdoc or else mproperty.mdoc_or_fallback
+
+ # Does self have the `before` annotation?
+ var is_before = false is writable
+
+ # Does self have the `before_all` annotation?
+ var is_before_all = false is writable
+
+ # Does self have the `after` annotation?
+ var is_after = false is writable
+
+ # Does self have the `after_all` annotation?
+ var is_after_all = false is writable
end
# A local definition of a method
# Fictive entities are used internally but they should not be
# exposed to the final user.
var is_fictive: Bool = false is writable
+
+ # Is `self` created for unit testing purpose?
+ #
+ # See `nitunit`.
+ var is_test: Bool = false is writable
end
# Something that represents a concern
v.include_fictive = self.include_fictive
v.include_empty_doc = self.include_empty_doc
v.include_attribute = self.include_attribute
- v.include_test_suite = self.include_test_suite
+ v.include_test = self.include_test
end
# Searches the MEntity that matches `full_name`.
# Should we accept nitunit test suites?
#
# Default is `false`.
- var include_test_suite = false is writable
+ var include_test = false is writable
# Can we accept this `mentity` regarding its test suite status?
- fun accept_test_suite(mentity: MEntity): Bool do
- if include_test_suite then return true
+ fun accept_test(mentity: MEntity): Bool do
+ if include_test then return true
if not mentity isa MModule then return true
- return not mentity.is_test_suite
+ return not mentity.is_test
end
# Should we accept `MAttribute` instances?
if not accept_visibility(mentity) then return false
if not accept_fictive(mentity) then return false
if not accept_empty_doc(mentity) then return false
- if not accept_test_suite(mentity) then return false
+ if not accept_test(mentity) then return false
if not accept_attribute(mentity) then return false
return true
end
# See the License for the specific language governing permissions and
# limitations under the License.
-module test_model_json is test_suite
+module test_model_json is test
-import test_suite
import model_json
import frontend
class TestModelSerialization
- super TestSuite
+ test
var suite_path: String = "NIT_TESTING_PATH".environ
var lib_path: String = "{suite_path.dirname}/../../tests/test_prog"
return model
end
- fun test_refs_to_full_json do
+ fun test_refs_to_full_json is test do
var mentities = new Array[MEntity]
mentities.add model.mpackages.first
mentities.add model.mmodules.first
end
end
- fun test_packages_to_full_json do
+ fun test_packages_to_full_json is test do
for mentity in model.mpackages do
print mentity.to_pretty_full_json
end
end
- fun test_groups_to_full_json do
+ fun test_groups_to_full_json is test do
for mpackage in model.mpackages do
for mentity in mpackage.mgroups do
print mentity.to_pretty_full_json
end
end
- fun test_modules_to_full_json do
+ fun test_modules_to_full_json is test do
for mentity in model.mmodules do
print mentity.to_pretty_full_json
end
end
- fun test_classes_to_full_json do
+ fun test_classes_to_full_json is test do
for mentity in model.mclasses do
print mentity.to_pretty_full_json
end
end
- fun test_classdefs_to_full_json do
+ fun test_classdefs_to_full_json is test do
for mclass in model.mclasses do
for mentity in mclass.mclassdefs do
print mentity.to_pretty_full_json
end
end
- fun test_props_to_full_json do
+ fun test_props_to_full_json is test do
for mentity in model.mproperties do
print mentity.to_pretty_full_json
end
end
- fun test_propdefs_to_full_json do
+ fun test_propdefs_to_full_json is test do
for mprop in model.mproperties do
for mentity in mprop.mpropdefs do
print mentity.to_pretty_full_json
TestSuites are Nit files that define a set of TestCase for a particular module.
-The test suite module must be declared using the `test_suite` annotation.
+The test suite module must be declared using the `test` annotation.
The structure of a test suite is the following:
# test suite for module `foo`
- module test_foo is test_suite
+ module test_foo is test
- import test_suite # import the `TestSuite` class and the `test_suite` annotation
import foo # can be intrude to test private things
class TestFoo
- super TestSuite
+ test
# test case for `foo::Foo::baz`
- fun test_baz do
+ fun baz is test do
var subject = new Foo
assert subject.baz(1, 2) == 3
end
$ nitunit foo.nit -t my_test_suite.nit
-`nitunit` will execute a test for each method named `test_*` in a class named `Test*`
+`nitunit` will execute a test for each method annotated with `test` in a class also annotated with `test`
so multiple tests can be executed for a single method:
class TestFoo
- super TestSuite
+ test
- fun test_baz_1 do
+ fun baz_1 is test do
var subject = new Foo
assert subject.baz(1, 2) == 3
end
- fun test_baz_2 do
+ fun baz_2 is test do
var subject = new Foo
assert subject.baz(1, -2) == -1
end
`TestSuites` also provide methods to configure the test run:
-`before_test` and `after_test`: methods called before/after each test case.
+`before` and `after` annotations can be added to methods that must be called before/after each test case.
They can be used to factorize repetitive tasks:
class TestFoo
- super TestSuite
+ test
var subject: Foo is noinit
# Method executed before each test
- redef fun before_test do
+ redef fun set_up is before do
subject = new Foo
end
- fun test_baz_1 do
+ fun baz_1 is test do
assert subject.baz(1, 2) == 3
end
- fun test_baz_2 do
+ fun baz_2 is test do
assert subject.baz(1, -2) == -1
end
end
When using custom test attributes, a empty init must be declared to allow automatic test running.
-`before_module` and `after_module`: methods called before/after each test suite.
+`before_all` and `after_all` annotations can be set on methods that must be called before/after each test suite.
They have to be declared at top level:
module test_bdd_connector
- import test_suite
import bdd_connector
# Testing the bdd_connector
class TestConnector
- super TestSuite
+ test
# test cases using a server
end
# Method executed before testing the module
- redef fun before_module do
+ fun before_module is before_all do
# start server before all test cases
end
# Method executed after testing the module
- redef fun after_module do
+ fun after_module is after_all do
# stop server after all test cases
end
fun gen_unit(mmodule: MModule, test_file: String): Template do
var with_private = toolcontext.opt_gen_private.value
var tpl = new Template
- tpl.addn "module test_{mmodule.name} is test_suite"
+ tpl.addn "module test_{mmodule.name} is test"
tpl.addn ""
- tpl.addn "import test_suite"
if with_private then
tpl.addn "intrude import {mmodule.name}"
else
if mclassdef.mclass.kind != concrete_kind then continue
tpl.addn ""
tpl.addn "class Test{mclassdef.name}"
- tpl.addn "\tsuper TestSuite"
+ tpl.addn "\ttest"
for mpropdef in mclassdef.mpropdefs do
if not mpropdef isa MMethodDef then continue
var mproperty = mpropdef.mproperty
if not with_private and mproperty.visibility <= protected_visibility then continue
var case_name = case_name(mpropdef)
tpl.addn ""
- tpl.addn "\tfun {case_name} do"
+ tpl.addn "\tfun {case_name} is test do"
tpl.addn "\t\tassert not_implemented: false # TODO remove once implemented"
tpl.addn ""
tpl.addn gen_init(mclassdef)
import testing_base
import html
-private import annotation
+private import parse_annotations
private import realtime
redef class ToolContext
var toolcontext = mbuilder.toolcontext
var suite = new TestSuite(mmodule, toolcontext)
# method to execute before all tests in the module
- var before_module = mmodule.before_test
- if before_module != null then
+ for mmethod in mmodule.before_all do
toolcontext.modelbuilder.total_tests += 1
- suite.before_module = new TestCase(suite, before_module, toolcontext)
+ suite.before_all.add new TestCase(suite, mmethod, toolcontext)
end
# generate all test cases
for mclassdef in mmodule.mclassdefs do
if not mclassdef.is_test then continue
if not suite_match_pattern(mclassdef) then continue
toolcontext.modelbuilder.total_classes += 1
+
+ var before = mclassdef.before
+ var after = mclassdef.after
+
for mpropdef in mclassdef.mpropdefs do
if not mpropdef isa MMethodDef or not mpropdef.is_test then continue
if not case_match_pattern(mpropdef) then continue
toolcontext.modelbuilder.total_tests += 1
var test = new TestCase(suite, mpropdef, toolcontext)
- suite.add_test test
+ test.before = before
+ test.after = after
+ suite.test_cases.add test
end
end
# method to execute after all tests in the module
- var after_module = mmodule.after_test
- if after_module != null then
+ for mmethod in mmodule.after_all do
toolcontext.modelbuilder.total_tests += 1
- suite.after_module = new TestCase(suite, after_module, toolcontext)
+ suite.after_all.add new TestCase(suite, mmethod, toolcontext)
end
suite.run
return suite
# List of `TestCase` to be executed in this suite.
var test_cases = new Array[TestCase]
- # Add a `TestCase` to the suite.
- fun add_test(case: TestCase) do test_cases.add case
-
- # Test to be executed before the whole test suite.
- var before_module: nullable TestCase = null
+ # Tests to be executed before the whole test suite.
+ var before_all = new Array[TestCase]
- # Test to be executed after the whole test suite.
- var after_module: nullable TestCase = null
+ # Tests to be executed after the whole test suite.
+ var after_all = new Array[TestCase]
# Display test suite status in std-out.
fun show_status do
var test_cases = self.test_cases.to_a
- if before_module != null then test_cases.add before_module.as(not null)
- if after_module != null then test_cases.add after_module.as(not null)
+ test_cases.add_all before_all
+ test_cases.add_all after_all
toolcontext.show_unit_status("Test-suite of module " + mmodule.full_name, test_cases)
end
end
toolcontext.info("Execute test-suite {mmodule.name}", 1)
- var before_module = self.before_module
- var after_module = self.after_module
-
- if before_module != null then
+ for before_module in before_all do
before_module.run
toolcontext.clear_progress_bar
toolcontext.show_unit(before_module)
toolcontext.clear_progress_bar
toolcontext.show_unit(case)
end
- if after_module != null then
+ for after_module in after_all do
after_module.fail "Nitunit Error: before_module test failed"
toolcontext.clear_progress_bar
toolcontext.show_unit(after_module)
show_status
end
- if not after_module == null then
+ for after_module in after_all do
after_module.run
toolcontext.clear_progress_bar
toolcontext.show_unit(after_module)
# Write the test unit for `self` in a nit compilable file.
fun write_to_nit do
var file = new Template
- file.addn "intrude import test_suite"
+ file.addn "intrude import core"
file.addn "import {mmodule.name}\n"
file.addn "var name = args.first"
- var before_module = self.before_module
- if before_module != null then
+ for before_module in before_all do
before_module.write_to_nit(file)
end
for case in test_cases do
case.write_to_nit(file)
end
- var after_module = self.after_module
- if after_module != null then
+ for after_module in after_all do
after_module.write_to_nit(file)
end
file.write_to_file("{test_file}.nit")
# Test method to be compiled and tested.
var test_method: MMethodDef
+ # Cases to execute before this one
+ var before = new Array[MMethodDef]
+
+ # Cases to execute after this one
+ var after = new Array[MMethodDef]
+
redef fun full_name do return test_method.full_name
redef fun location do return test_method.location
if test_method.mproperty.is_toplevel then
file.addn "\t{name}"
else
- file.addn "\tvar subject = new {test_method.mclassdef.name}.nitunit"
- file.addn "\tsubject.before_test"
+ file.addn "\tvar subject = new {test_method.mclassdef.name}.intern"
+ for mmethod in before do
+ file.addn "\tsubject.{mmethod.name}"
+ end
file.addn "\tsubject.{name}"
- file.addn "\tsubject.after_test"
+ for mmethod in after do
+ file.addn "\tsubject.{mmethod.name}"
+ end
end
file.addn "end"
end
end
end
-redef class MMethodDef
- # TODO use annotations?
-
- # Is the method a test_method?
- # i.e. begins with "test_"
- private fun is_test: Bool do return name.has_prefix("test_")
+redef class MClassDef
+ # Methods tagged with `before` in this class definition
+ private fun before: Array[MMethodDef] do
+ var res = new Array[MMethodDef]
+ for mpropdef in mpropdefs do
+ if mpropdef isa MMethodDef and mpropdef.is_before then
+ res.add mpropdef
+ end
+ end
+ var in_hierarchy = self.in_hierarchy
+ if in_hierarchy == null then return res
+ for mclassdef in in_hierarchy.direct_greaters do
+ res.add_all mclassdef.before
+ end
+ return res
+ end
- # Is the method a "before_module"?
- private fun is_before_module: Bool do return name == "before_module"
+ # Methods tagged with `before_all` in this class definition
+ private fun before_all: Array[MMethodDef] do
+ var res = new Array[MMethodDef]
+ for mpropdef in mpropdefs do
+ if mpropdef isa MMethodDef and mpropdef.is_before_all then
+ res.add mpropdef
+ end
+ end
+ var in_hierarchy = self.in_hierarchy
+ if in_hierarchy == null then return res
+ for mclassdef in in_hierarchy.direct_greaters do
+ res.add_all mclassdef.before_all
+ end
+ return res
+ end
- # Is the method a "after_module"?
- private fun is_after_module: Bool do return name == "after_module"
-end
+ # Methods tagged with `after` in this class definition
+ private fun after: Array[MMethodDef] do
+ var res = new Array[MMethodDef]
+ for mpropdef in mpropdefs do
+ if mpropdef isa MMethodDef and mpropdef.is_after then
+ res.add mpropdef
+ end
+ end
+ var in_hierarchy = self.in_hierarchy
+ if in_hierarchy == null then return res
+ for mclassdef in in_hierarchy.direct_greaters do
+ res.add_all mclassdef.after
+ end
+ return res
+ end
-redef class MClassDef
- # Is the class a TestClass?
- # i.e. is a subclass of `TestSuite`
- private fun is_test: Bool do
+ # Methods tagged with `after_all` in this class definition
+ private fun after_all: Array[MMethodDef] do
+ var res = new Array[MMethodDef]
+ for mpropdef in mpropdefs do
+ if mpropdef isa MMethodDef and mpropdef.is_after_all then
+ res.add mpropdef
+ end
+ end
var in_hierarchy = self.in_hierarchy
- if in_hierarchy == null then return false
- for sup in in_hierarchy.greaters do
- if sup.name == "TestSuite" then return true
+ if in_hierarchy == null then return res
+ for mclassdef in in_hierarchy.direct_greaters do
+ res.add_all mclassdef.after_all
end
- return false
+ return res
end
end
redef class MModule
- # "before_module" method for this module.
- private fun before_test: nullable MMethodDef do
+ # Methods tagged with `before_all` at the module level (in `Sys`)
+ private fun before_all: Array[MMethodDef] do
for mclassdef in mclassdefs do
- if not mclassdef.name == "Sys" then continue
- for mpropdef in mclassdef.mpropdefs do
- if mpropdef isa MMethodDef and mpropdef.is_before_module then return mpropdef
- end
+ if mclassdef.name == "Sys" then return mclassdef.before_all
end
- return null
+ return new Array[MMethodDef]
end
- # "after_module" method for this module.
- private fun after_test: nullable MMethodDef do
+ # Methods tagged with `after_all` at the module level (in `Sys`)
+ private fun after_all: Array[MMethodDef] do
for mclassdef in mclassdefs do
- if not mclassdef.name == "Sys" then continue
- for mpropdef in mclassdef.mpropdefs do
- if mpropdef isa MMethodDef and mpropdef.is_after_module then return mpropdef
- end
+ if mclassdef.name == "Sys" then return mclassdef.after_all
end
- return null
+ return new Array[MMethodDef]
end
end
# Run NitUnit test suite for `mmodule` (if it is one).
fun test_unit(mmodule: MModule): nullable HTMLTag do
# is the module a test_suite?
- if get_mmodule_annotation("test_suite", mmodule) == null then return null
+ if not mmodule.is_test then return null
toolcontext.info("nitunit: test-suite {mmodule}", 2)
var tester = new NitUnitTester(self)
view.include_fictive = true
view.include_empty_doc = true
view.include_attribute = true
- view.include_test_suite = true
+ view.include_test = true
return view
end
end
==== Test-suite of module test_test_nitunit::test_test_nitunit | tests: 3
[OK] test_test_nitunit$TestX$test_foo
[KO] test_test_nitunit$TestX$test_foo1
- test_test_nitunit.nit:36,2--40,4: Runtime Error in file nitunit.out/gen_test_test_nitunit.nit
+ test_test_nitunit.nit:35,2--39,4: Runtime Error in file nitunit.out/gen_test_test_nitunit.nit
Output
- Runtime error: Assert failed (test_test_nitunit.nit:39)
+ Runtime error: Assert failed (test_test_nitunit.nit:38)
[OK] test_test_nitunit$TestX$test_foo2
</system-out></testcase><testcase classname="nitunit.test_nitunit.X" name="foo" time="0.0"><failure message="Compilation error in nitunit.out/test_nitunit-3.nit">nitunit.out/test_nitunit-3.nit:5,8--27: Error: method or variable `undefined_identifier` unknown in `Sys`.
</failure><system-out>assert undefined_identifier
</system-out></testcase><testcase classname="nitunit.test_nitunit.X" name="foo1" time="0.0"><failure message="Syntax Error: unexpected operator '!'."></failure><system-out>assert !@#$%^&*()
-</system-out></testcase></testsuite><testsuite package="test_test_nitunit::test_test_nitunit"></testsuite><testsuite package="test_test_nitunit"><testcase classname="nitunit.test_test_nitunit.TestX" name="test_foo" time="0.0"><system-err></system-err></testcase><testcase classname="nitunit.test_test_nitunit.TestX" name="test_foo1" time="0.0"><error message="Runtime Error in file nitunit.out/gen_test_test_nitunit.nit">Runtime error: Assert failed (test_test_nitunit.nit:39)
+</system-out></testcase></testsuite><testsuite package="test_test_nitunit::test_test_nitunit"></testsuite><testsuite package="test_test_nitunit"><testcase classname="nitunit.test_test_nitunit.TestX" name="test_foo" time="0.0"><system-err></system-err></testcase><testcase classname="nitunit.test_test_nitunit.TestX" name="test_foo1" time="0.0"><error message="Runtime Error in file nitunit.out/gen_test_test_nitunit.nit">Runtime error: Assert failed (test_test_nitunit.nit:38)
</error></testcase><testcase classname="nitunit.test_test_nitunit.TestX" name="test_foo2" time="0.0"><system-err></system-err></testcase></testsuite></testsuites>
\ No newline at end of file
==== Test-suite of module test_nitunit6::test_nitunit6 | tests: 3
[KO] test_nitunit6::test_nitunit6$core::Sys$before_module
- test_nitunit6.nit:27,1--29,3: Runtime Error in file nitunit.out/gen_test_nitunit6.nit
+ test_nitunit6.nit:25,1--27,3: Runtime Error in file nitunit.out/gen_test_nitunit6.nit
Output
- Runtime error: Assert failed (test_nitunit6.nit:28)
+ Runtime error: Assert failed (test_nitunit6.nit:26)
[KO] test_nitunit6$TestNitunit6$test_foo
- test_nitunit6.nit:22,2--24,4: Nitunit Error: before_module test failed
+ test_nitunit6.nit:20,2--22,4: Nitunit Error: before_module test failed
[KO] test_nitunit6::test_nitunit6$core::Sys$after_module
- test_nitunit6.nit:31,1--33,3: Nitunit Error: before_module test failed
+ test_nitunit6.nit:29,1--31,3: Nitunit Error: before_module test failed
Docunits: Entities: 5; Documented ones: 0; With nitunits: 0
Test suites: Classes: 1; Test Cases: 3; Failures: 3
[OK] test_nitunit7::test_nitunit7$core::Sys$before_module
[OK] test_nitunit7$TestNitunit7$test_foo
[KO] test_nitunit7::test_nitunit7$core::Sys$after_module
- test_nitunit7.nit:31,1--33,3: Runtime Error in file nitunit.out/gen_test_nitunit7.nit
+ test_nitunit7.nit:29,1--31,3: Runtime Error in file nitunit.out/gen_test_nitunit7.nit
Output
- Runtime error: Assert failed (test_nitunit7.nit:32)
+ Runtime error: Assert failed (test_nitunit7.nit:30)
Docunits: Entities: 5; Documented ones: 0; With nitunits: 0
-module test_test_nitunit is test_suite
+module test_test_nitunit is test
-import test_suite
import test_nitunit
class TestX
- super TestSuite
+ test
- fun test_foo do
+ fun test_foo is test do
assert not_implemented: false # TODO remove once implemented
var subject: X
subject.foo
end
- fun test_foo1 do
+ fun test_foo1 is test do
assert not_implemented: false # TODO remove once implemented
var subject: X
subject.foo1(a, b)
end
- fun test_foo3 do
+ fun test_foo3 is test do
assert not_implemented: false # TODO remove once implemented
var subject: X
end
class TestY
- super TestSuite
+ test
- fun test_bra do
+ fun test_bra is test do
assert not_implemented: false # TODO remove once implemented
var subject: Y[X]
assert exp == res
end
- fun test_bra_assign do
+ fun test_bra_assign is test do
assert not_implemented: false # TODO remove once implemented
var subject: Y[X]
subject[e] = i
end
- fun test_plus do
+ fun test_plus is test do
assert not_implemented: false # TODO remove once implemented
var subject: Y[X]
assert exp == res
end
- fun test_minus do
+ fun test_minus is test do
assert not_implemented: false # TODO remove once implemented
var subject: Y[X]
assert exp == res
end
- fun test_star do
+ fun test_star is test do
assert not_implemented: false # TODO remove once implemented
var subject: Y[X]
assert exp == res
end
- fun test_slash do
+ fun test_slash is test do
assert not_implemented: false # TODO remove once implemented
var subject: Y[X]
assert exp == res
end
- fun test_percent do
+ fun test_percent is test do
assert not_implemented: false # TODO remove once implemented
var subject: Y[X]
assert exp == res
end
- fun test_unary_minus do
+ fun test_unary_minus is test do
assert not_implemented: false # TODO remove once implemented
var subject: Y[X]
assert exp == res
end
- fun test_equals do
+ fun test_equals is test do
assert not_implemented: false # TODO remove once implemented
var subject: Y[X]
assert exp == res
end
- fun test_not_equals do
+ fun test_not_equals is test do
assert not_implemented: false # TODO remove once implemented
var subject: Y[X]
assert exp == res
end
- fun test_lt do
+ fun test_lt is test do
assert not_implemented: false # TODO remove once implemented
var subject: Y[X]
assert exp == res
end
- fun test_le do
+ fun test_le is test do
assert not_implemented: false # TODO remove once implemented
var subject: Y[X]
assert exp == res
end
- fun test_compare do
+ fun test_compare is test do
assert not_implemented: false # TODO remove once implemented
var subject: Y[X]
assert exp == res
end
- fun test_ge do
+ fun test_ge is test do
assert not_implemented: false # TODO remove once implemented
var subject: Y[X]
assert exp == res
end
- fun test_gt do
+ fun test_gt is test do
assert not_implemented: false # TODO remove once implemented
var subject: Y[X]
end
class TestZ
- super TestSuite
+ test
- fun test_bra do
+ fun test_bra is test do
assert not_implemented: false # TODO remove once implemented
var subject: Z
assert exp == res
end
- fun test_bra_assign do
+ fun test_bra_assign is test do
assert not_implemented: false # TODO remove once implemented
var subject: Z
subject[i, j] = k
end
- fun test_foo= do
+ fun test_foo= is test do
assert not_implemented: false # TODO remove once implemented
var subject: Z
subject.foo(i) = j
end
- fun test_bar= do
+ fun test_bar= is test do
assert not_implemented: false # TODO remove once implemented
var subject: Z
-module test_test_nitunit is test_suite
+module test_test_nitunit is test
-import test_suite
intrude import test_nitunit
class TestX
- super TestSuite
+ test
- fun test_foo do
+ fun test_foo is test do
assert not_implemented: false # TODO remove once implemented
var subject: X
subject.foo
end
- fun test_foo1 do
+ fun test_foo1 is test do
assert not_implemented: false # TODO remove once implemented
var subject: X
subject.foo1(a, b)
end
- fun test_foo2 do
+ fun test_foo2 is test do
assert not_implemented: false # TODO remove once implemented
var subject: X
assert exp == res
end
- fun test_foo3 do
+ fun test_foo3 is test do
assert not_implemented: false # TODO remove once implemented
var subject: X
assert exp == res
end
- fun test_foo3= do
+ fun test_foo3= is test do
assert not_implemented: false # TODO remove once implemented
var subject: X
end
class TestY
- super TestSuite
+ test
- fun test_bra do
+ fun test_bra is test do
assert not_implemented: false # TODO remove once implemented
var subject: Y[X]
assert exp == res
end
- fun test_bra_assign do
+ fun test_bra_assign is test do
assert not_implemented: false # TODO remove once implemented
var subject: Y[X]
subject[e] = i
end
- fun test_plus do
+ fun test_plus is test do
assert not_implemented: false # TODO remove once implemented
var subject: Y[X]
assert exp == res
end
- fun test_minus do
+ fun test_minus is test do
assert not_implemented: false # TODO remove once implemented
var subject: Y[X]
assert exp == res
end
- fun test_star do
+ fun test_star is test do
assert not_implemented: false # TODO remove once implemented
var subject: Y[X]
assert exp == res
end
- fun test_slash do
+ fun test_slash is test do
assert not_implemented: false # TODO remove once implemented
var subject: Y[X]
assert exp == res
end
- fun test_percent do
+ fun test_percent is test do
assert not_implemented: false # TODO remove once implemented
var subject: Y[X]
assert exp == res
end
- fun test_unary_minus do
+ fun test_unary_minus is test do
assert not_implemented: false # TODO remove once implemented
var subject: Y[X]
assert exp == res
end
- fun test_equals do
+ fun test_equals is test do
assert not_implemented: false # TODO remove once implemented
var subject: Y[X]
assert exp == res
end
- fun test_not_equals do
+ fun test_not_equals is test do
assert not_implemented: false # TODO remove once implemented
var subject: Y[X]
assert exp == res
end
- fun test_lt do
+ fun test_lt is test do
assert not_implemented: false # TODO remove once implemented
var subject: Y[X]
assert exp == res
end
- fun test_le do
+ fun test_le is test do
assert not_implemented: false # TODO remove once implemented
var subject: Y[X]
assert exp == res
end
- fun test_compare do
+ fun test_compare is test do
assert not_implemented: false # TODO remove once implemented
var subject: Y[X]
assert exp == res
end
- fun test_ge do
+ fun test_ge is test do
assert not_implemented: false # TODO remove once implemented
var subject: Y[X]
assert exp == res
end
- fun test_gt do
+ fun test_gt is test do
assert not_implemented: false # TODO remove once implemented
var subject: Y[X]
end
class TestZ
- super TestSuite
+ test
- fun test_bra do
+ fun test_bra is test do
assert not_implemented: false # TODO remove once implemented
var subject: Z
assert exp == res
end
- fun test_bra_assign do
+ fun test_bra_assign is test do
assert not_implemented: false # TODO remove once implemented
var subject: Z
subject[i, j] = k
end
- fun test_foo= do
+ fun test_foo= is test do
assert not_implemented: false # TODO remove once implemented
var subject: Z
subject.foo(i) = j
end
- fun test_bar= do
+ fun test_bar= is test do
assert not_implemented: false # TODO remove once implemented
var subject: Z
-test_nitunit4/test_bad_comp.nit:27,10--19: Error: method or variable `bad_method` unknown in `TestSuiteBadComp`.
-test_nitunit4/test_bad_comp2.nit:19,7--22: Error: a class named `test_nitunit4::TestSuiteBadComp` is already defined in module `test_bad_comp` at test_nitunit4/test_bad_comp.nit:19,1--29,3.
+test_nitunit4/test_bad_comp.nit:25,10--19: Error: method or variable `bad_method` unknown in `TestSuiteBadComp`.
+test_nitunit4/test_bad_comp2.nit:17,7--22: Error: a class named `test_nitunit4::TestSuiteBadComp` is already defined in module `test_bad_comp` at test_nitunit4/test_bad_comp.nit:17,1--27,3.
==== Test-suite of module test_nitunit4::test_bad_comp | tests: 2
[KO] test_nitunit4$TestSuiteBadComp$test_good
- test_nitunit4/test_bad_comp.nit:22,2--24,4: Compilation Error
+ test_nitunit4/test_bad_comp.nit:20,2--22,4: Compilation Error
Output
- test_nitunit4/test_bad_comp.nit:27,10--19: Error: method or variable `bad_method` unknown in `TestSuiteBadComp`.
+ test_nitunit4/test_bad_comp.nit:25,10--19: Error: method or variable `bad_method` unknown in `TestSuiteBadComp`.
[KO] test_nitunit4$TestSuiteBadComp$test_bad
- test_nitunit4/test_bad_comp.nit:26,2--28,4: Compilation Error
+ test_nitunit4/test_bad_comp.nit:24,2--26,4: Compilation Error
Output
- test_nitunit4/test_bad_comp.nit:27,10--19: Error: method or variable `bad_method` unknown in `TestSuiteBadComp`.
+ test_nitunit4/test_bad_comp.nit:25,10--19: Error: method or variable `bad_method` unknown in `TestSuiteBadComp`.
==== Test-suite of module test_nitunit4::test_bad_comp2 | tests: 2
[KO] test_nitunit4$TestSuiteBadComp$test_good
- test_nitunit4/test_bad_comp2.nit:22,2--24,4: Compilation Error
+ test_nitunit4/test_bad_comp2.nit:20,2--22,4: Compilation Error
Output
- nitunit.out/gen_test_bad_comp2.nit:14,10--17: Error: expected 1 argument(s) for `test_bad(param: Bool)`; got 0. See introduction at `test_nitunit4::TestSuiteBadComp::test_bad`.
+ nitunit.out/gen_test_bad_comp2.nit:11,10--17: Error: expected 1 argument(s) for `test_bad(param: Bool)`; got 0. See introduction at `test_nitunit4::TestSuiteBadComp::test_bad`.
[KO] test_nitunit4$TestSuiteBadComp$test_bad
- test_nitunit4/test_bad_comp2.nit:26,2--28,4: Compilation Error
+ test_nitunit4/test_bad_comp2.nit:24,2--26,4: Compilation Error
Output
- nitunit.out/gen_test_bad_comp2.nit:14,10--17: Error: expected 1 argument(s) for `test_bad(param: Bool)`; got 0. See introduction at `test_nitunit4::TestSuiteBadComp::test_bad`.
+ nitunit.out/gen_test_bad_comp2.nit:11,10--17: Error: expected 1 argument(s) for `test_bad(param: Bool)`; got 0. See introduction at `test_nitunit4::TestSuiteBadComp::test_bad`.
==== Test-suite of module test_nitunit4::test_nitunit4 | tests: 4
[KO] test_nitunit4$TestTestSuite$test_foo
- test_nitunit4/test_nitunit4.nit:22,2--26,4: Runtime Error in file nitunit.out/gen_test_nitunit4.nit
+ test_nitunit4/test_nitunit4.nit:23,2--27,4: Runtime Error in file nitunit.out/gen_test_nitunit4.nit
Output
Before Test
Tested method
After Test
- Runtime error: Assert failed (test_nitunit4/test_nitunit4_base.nit:31)
+ Runtime error: Assert failed (test_nitunit4/test_nitunit4_base.nit:28)
[OK] test_nitunit4$TestTestSuite$test_bar
[KO] test_nitunit4$TestTestSuite$test_baz
- test_nitunit4/test_nitunit4.nit:32,2--34,4: Difference with expected output: diff -u test_nitunit4/test_baz.res nitunit.out/gen_test_nitunit4_test_baz.out1
+ test_nitunit4/test_nitunit4.nit:33,2--35,4: Difference with expected output: diff -u test_nitunit4/test_baz.res nitunit.out/gen_test_nitunit4_test_baz.out1
Output
Diff
--- expected:test_nitunit4/test_baz.res
+After Test
[KO] test_nitunit4$TestTestSuite$test_sav_conflict
- test_nitunit4/test_nitunit4.nit:36,2--38,4: Conflicting expected output: test_nitunit4/test_nitunit4.sav/test_sav_conflict.res, test_nitunit4/sav/test_sav_conflict.res and test_nitunit4/test_sav_conflict.res all exist
+ test_nitunit4/test_nitunit4.nit:37,2--39,4: Conflicting expected output: test_nitunit4/test_nitunit4.sav/test_sav_conflict.res, test_nitunit4/sav/test_sav_conflict.res and test_nitunit4/test_sav_conflict.res all exist
Output
Before Test
Tested method
After Test
-==== Test-suite of module test_nitunit4::test_nitunit4_base | tests: 0
-==== Test-suite of module test_nitunit4::test_nitunit4_base | tests: 0
-
Docunits: Entities: 21; Documented ones: 0; With nitunits: 0
-Test suites: Classes: 4; Test Cases: 8; Failures: 7
+Test suites: Classes: 3; Test Cases: 8; Failures: 7
[FAILURE] 7/8 tests failed.
`nitunit.out` is not removed for investigation.
-<testsuites><testsuite package="test_nitunit4>"></testsuite><testsuite package="test_nitunit4::nitunit4"></testsuite><testsuite package="test_nitunit4::test_bad_comp"></testsuite><testsuite package="test_bad_comp"><testcase classname="nitunit.test_nitunit4.TestSuiteBadComp" name="test_good" time="0.0"><failure message="Compilation Error">test_nitunit4/test_bad_comp.nit:27,10--19: Error: method or variable `bad_method` unknown in `TestSuiteBadComp`.
-</failure></testcase><testcase classname="nitunit.test_nitunit4.TestSuiteBadComp" name="test_bad" time="0.0"><failure message="Compilation Error">test_nitunit4/test_bad_comp.nit:27,10--19: Error: method or variable `bad_method` unknown in `TestSuiteBadComp`.
-</failure></testcase></testsuite><testsuite package="test_nitunit4::test_bad_comp2"></testsuite><testsuite package="test_bad_comp2"><testcase classname="nitunit.test_nitunit4.TestSuiteBadComp" name="test_good" time="0.0"><failure message="Compilation Error">nitunit.out/gen_test_bad_comp2.nit:14,10--17: Error: expected 1 argument(s) for `test_bad(param: Bool)`; got 0. See introduction at `test_nitunit4::TestSuiteBadComp::test_bad`.
-</failure></testcase><testcase classname="nitunit.test_nitunit4.TestSuiteBadComp" name="test_bad" time="0.0"><failure message="Compilation Error">nitunit.out/gen_test_bad_comp2.nit:14,10--17: Error: expected 1 argument(s) for `test_bad(param: Bool)`; got 0. See introduction at `test_nitunit4::TestSuiteBadComp::test_bad`.
+<testsuites><testsuite package="test_nitunit4>"></testsuite><testsuite package="test_nitunit4::nitunit4"></testsuite><testsuite package="test_nitunit4::test_bad_comp"></testsuite><testsuite package="test_bad_comp"><testcase classname="nitunit.test_nitunit4.TestSuiteBadComp" name="test_good" time="0.0"><failure message="Compilation Error">test_nitunit4/test_bad_comp.nit:25,10--19: Error: method or variable `bad_method` unknown in `TestSuiteBadComp`.
+</failure></testcase><testcase classname="nitunit.test_nitunit4.TestSuiteBadComp" name="test_bad" time="0.0"><failure message="Compilation Error">test_nitunit4/test_bad_comp.nit:25,10--19: Error: method or variable `bad_method` unknown in `TestSuiteBadComp`.
+</failure></testcase></testsuite><testsuite package="test_nitunit4::test_bad_comp2"></testsuite><testsuite package="test_bad_comp2"><testcase classname="nitunit.test_nitunit4.TestSuiteBadComp" name="test_good" time="0.0"><failure message="Compilation Error">nitunit.out/gen_test_bad_comp2.nit:11,10--17: Error: expected 1 argument(s) for `test_bad(param: Bool)`; got 0. See introduction at `test_nitunit4::TestSuiteBadComp::test_bad`.
+</failure></testcase><testcase classname="nitunit.test_nitunit4.TestSuiteBadComp" name="test_bad" time="0.0"><failure message="Compilation Error">nitunit.out/gen_test_bad_comp2.nit:11,10--17: Error: expected 1 argument(s) for `test_bad(param: Bool)`; got 0. See introduction at `test_nitunit4::TestSuiteBadComp::test_bad`.
</failure></testcase></testsuite><testsuite package="test_nitunit4::test_nitunit4"></testsuite><testsuite package="test_nitunit4"><testcase classname="nitunit.test_nitunit4.TestTestSuite" name="test_foo" time="0.0"><error message="Runtime Error in file nitunit.out/gen_test_nitunit4.nit">Before Test
Tested method
After Test
-Runtime error: Assert failed (test_nitunit4/test_nitunit4_base.nit:31)
+Runtime error: Assert failed (test_nitunit4/test_nitunit4_base.nit:28)
</error></testcase><testcase classname="nitunit.test_nitunit4.TestTestSuite" name="test_bar" time="0.0"><system-err>Before Test
Tested method
After Test
</error></testcase><testcase classname="nitunit.test_nitunit4.TestTestSuite" name="test_sav_conflict" time="0.0"><error message="Conflicting expected output: test_nitunit4/test_nitunit4.sav/test_sav_conflict.res, test_nitunit4/sav/test_sav_conflict.res and test_nitunit4/test_sav_conflict.res all exist">Before Test
Tested method
After Test
-</error></testcase></testsuite><testsuite package="test_nitunit4::test_nitunit4_base"></testsuite><testsuite package="test_nitunit4_base"></testsuite></testsuites>
\ No newline at end of file
+</error></testcase></testsuite><testsuite package="test_nitunit4::test_nitunit4_base"></testsuite></testsuites>
\ No newline at end of file
syntax_annotations3.nit:16,2--20: Warning: unknown annotation `invariant`.
syntax_annotations3.nit:19,3--12: Warning: unknown annotation `pre`.
syntax_annotations3.nit:20,3--22: Warning: unknown annotation `post`.
-syntax_annotations3.nit:21,3--19: Warning: unknown annotation `test`.
syntax_annotations3.nit:28,3--7: Warning: unknown annotation `inter`.
syntax_annotations3.nit:33,16--18: Warning: unknown annotation `u32`.
-syntax_annotations3.nit:34,19--36: Warning: unknown annotation `after`.
syntax_annotations3.nit:34,12--36: Warning: unknown annotation `daemon`.
syntax_annotations3.nit:34,3--37: Warning: unknown annotation `ondebug`.
syntax_annotations3.nit:35,3--7: Warning: unknown annotation `final`.
# See the License for the specific language governing permissions and
# limitations under the License.
-module test_bad_comp is test_suite
-
-import test_suite
+module test_bad_comp is test
class TestSuiteBadComp
- super TestSuite
+ test
- fun test_good do
+ fun test_good is test do
assert true
end
- fun test_bad do
+ fun test_bad is test do
assert bad_method
end
end
# See the License for the specific language governing permissions and
# limitations under the License.
-module test_bad_comp2 is test_suite
-
-import test_suite
+module test_bad_comp2 is test
class TestSuiteBadComp
- super TestSuite
+ test
- fun test_good do
+ fun test_good is test do
assert true
end
- fun test_bad(param: Bool) do
+ fun test_bad(param: Bool) is test do
assert param
end
end
# See the License for the specific language governing permissions and
# limitations under the License.
-module test_nitunit4 is test_suite
+module test_nitunit4 is test
import test_nitunit4_base
class TestTestSuite
super SuperTestSuite
+ test
- fun test_foo do
+ fun test_foo is test do
print "Tested method"
assert before
before = false
end
- fun test_bar do
+ fun test_bar is test do
print "Tested method"
end
- fun test_baz do
+ fun test_baz is test do
print "Tested method"
end
- fun test_sav_conflict do
+ fun test_sav_conflict is test do
print "Tested method"
end
end
# See the License for the specific language governing permissions and
# limitations under the License.
-module test_nitunit4_base is test_suite
-
-import test_suite
+module test_nitunit4_base
class SuperTestSuite
- super TestSuite
var before = false
- redef fun before_test do
+ fun before_test is before do
print "Before Test"
before = true
end
- redef fun after_test do
+ fun after_test is after do
print "After Test"
assert before
end
# See the License for the specific language governing permissions and
# limitations under the License.
-module test_nitunit5 is test_suite
-
-import test_suite
+module test_nitunit5 is test
class TestNitunit5
- super TestSuite
+ test
- fun test_path_is_set do
+ fun test_path_is_set is test do
assert "NIT_TESTING_PATH".environ != ""
end
- fun test_path_is_suite_path do
+ fun test_path_is_suite_path is test do
assert "NIT_TESTING_PATH".environ.basename == "test_nitunit5.nit"
end
end
# See the License for the specific language governing permissions and
# limitations under the License.
-module test_nitunit6 is test_suite
-
-import test_suite
+module test_nitunit6 is test
class TestNitunit6
- super TestSuite
+ test
- fun test_foo do
+ fun test_foo is test do
assert true
end
end
-redef fun before_module do
+fun before_module is before_all do
assert false
end
-redef fun after_module do
+fun after_module is after_all do
assert false
end
# See the License for the specific language governing permissions and
# limitations under the License.
-module test_nitunit7 is test_suite
-
-import test_suite
+module test_nitunit7 is test
class TestNitunit7
- super TestSuite
+ test
- fun test_foo do
+ fun test_foo is test do
assert true
end
end
-redef fun before_module do
+fun before_module is before_all do
assert true
end
-redef fun after_module do
+fun after_module is after_all do
assert false
end
# limitations under the License.
# NitUnit file for test_nitunit module.
-module test_test_nitunit is test_suite
+module test_test_nitunit is test
-import test_suite
intrude import test_nitunit
class TestX
- super TestSuite
+ test
var subject: X is noinit
- redef fun before_test do
+ fun before_test is before do
subject = new X
end
- fun test_foo do
+ fun test_foo is test do
subject.foo
end
# will fail
- fun test_foo1 do
+ fun test_foo1 is test do
subject.foo1(10, 20)
assert false
end
- fun test_foo2 do
+ fun test_foo2 is test do
assert subject.foo2
end
end