aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2021-03-14 18:43:21 +0000
committergingerBill <bill@gingerbill.org>2021-03-14 18:43:21 +0000
commitf5142aaec41edbb85f9306216c6b199fa5adb7bb (patch)
treebf1eb80ce88441d9bde998c9d4b879f7a7d0965c
parentdb0ac2ba984a4b395a6dfba8fcb7ab128ad96f19 (diff)
Change from `test_*` prefix to `@(test)` attribute for `odin test`
-rw-r--r--core/testing/runner.odin8
-rw-r--r--src/check_decl.cpp7
-rw-r--r--src/checker.cpp21
-rw-r--r--src/checker.hpp1
-rw-r--r--src/entity.cpp2
-rw-r--r--src/parser.cpp1
6 files changed, 22 insertions, 18 deletions
diff --git a/core/testing/runner.odin b/core/testing/runner.odin
index 3acd25aca..efeaa04f6 100644
--- a/core/testing/runner.odin
+++ b/core/testing/runner.odin
@@ -48,14 +48,12 @@ runner :: proc(internal_tests: []Internal_Test) -> bool {
reset_t(t);
defer end_t(t);
- name := strings.trim_prefix(it.name, "test_");
-
if prev_pkg != it.pkg {
prev_pkg = it.pkg;
logf(t, "[Package: %s]", it.pkg);
}
- logf(t, "[Test: %s]", name);
+ logf(t, "[Test: %s]", it.name);
// TODO(bill): Catch panics
{
@@ -63,9 +61,9 @@ runner :: proc(internal_tests: []Internal_Test) -> bool {
}
if t.error_count != 0 {
- logf(t, "[%s : FAILURE]", name);
+ logf(t, "[%s : FAILURE]", it.name);
} else {
- logf(t, "[%s : SUCCESS]", name);
+ logf(t, "[%s : SUCCESS]", it.name);
total_success_count += 1;
}
}
diff --git a/src/check_decl.cpp b/src/check_decl.cpp
index 95a3cb25a..a08da3a2d 100644
--- a/src/check_decl.cpp
+++ b/src/check_decl.cpp
@@ -687,6 +687,9 @@ void check_proc_decl(CheckerContext *ctx, Entity *e, DeclInfo *d) {
check_decl_attributes(ctx, d->attributes, proc_decl_attribute, &ac);
}
+ if (ac.test) {
+ e->flags |= EntityFlag_Test;
+ }
e->Procedure.is_export = ac.is_export;
e->deprecated_message = ac.deprecated_message;
ac.link_name = handle_link_name(ctx, e->token, ac.link_name, ac.link_prefix);
@@ -701,8 +704,8 @@ void check_proc_decl(CheckerContext *ctx, Entity *e, DeclInfo *d) {
}
}
- bool is_foreign = e->Procedure.is_foreign;
- bool is_export = e->Procedure.is_export;
+ bool is_foreign = e->Procedure.is_foreign;
+ bool is_export = e->Procedure.is_export;
if (e->pkg != nullptr && e->token.string == "main") {
if (pt->param_count != 0 ||
diff --git a/src/checker.cpp b/src/checker.cpp
index fdf9cefea..19c852621 100644
--- a/src/checker.cpp
+++ b/src/checker.cpp
@@ -1891,20 +1891,13 @@ void generate_minimum_dependency_set(Checker *c, Entity *start) {
continue;
}
- String name = e->token.string;
- String prefix = str_lit("test_");
-
- if (!string_starts_with(name, prefix)) {
+ if ((e->flags & EntityFlag_Test) == 0) {
continue;
}
+ String name = e->token.string;
- bool is_tester = false;
- if (name != prefix) {
- is_tester = true;
- } else {
- error(e->token, "Invalid testing procedure name: %.*s", LIT(name));
- }
+ bool is_tester = true;
Type *t = base_type(e->type);
GB_ASSERT(t->kind == Type_Proc);
@@ -2414,7 +2407,13 @@ DECL_ATTRIBUTE_PROC(foreign_block_decl_attribute) {
}
DECL_ATTRIBUTE_PROC(proc_decl_attribute) {
- if (name == "export") {
+ if (name == "test") {
+ if (value != nullptr) {
+ error(value, "'%.*s' expects no parameter, or a string literal containing \"file\" or \"package\"", LIT(name));
+ }
+ ac->test = true;
+ return true;
+ } else if (name == "export") {
ExactValue ev = check_decl_attribute_value(c, value);
if (ev.kind == ExactValue_Invalid) {
ac->is_export = true;
diff --git a/src/checker.hpp b/src/checker.hpp
index 168c00d33..abdb601a9 100644
--- a/src/checker.hpp
+++ b/src/checker.hpp
@@ -104,6 +104,7 @@ struct AttributeContext {
bool require_declaration;
bool has_disabled_proc;
bool disabled_proc;
+ bool test;
String link_name;
String link_prefix;
isize init_expr_list_count;
diff --git a/src/entity.cpp b/src/entity.cpp
index 7951cf614..2786fcc6d 100644
--- a/src/entity.cpp
+++ b/src/entity.cpp
@@ -64,6 +64,8 @@ enum EntityFlag : u32 {
EntityFlag_Disabled = 1<<24,
+ EntityFlag_Test = 1<<25,
+
};
enum EntityState {
diff --git a/src/parser.cpp b/src/parser.cpp
index 1b3a37c3b..46eb9145c 100644
--- a/src/parser.cpp
+++ b/src/parser.cpp
@@ -3932,6 +3932,7 @@ Ast *parse_for_stmt(AstFile *f) {
}
+
if (allow_token(f, Token_do)) {
body = convert_stmt_to_body(f, parse_stmt(f));
if (build_context.disallow_do) {