-
-
Notifications
You must be signed in to change notification settings - Fork 172
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Moved tokenizer.rs and tree_construction.rs tests into crates for issue #445 #457
Conversation
Moved tokenizer.rs from tests to its crate. Also added the #[cfg(test)] and mod declaration as requested.
It was copied into its crate.
Copied tree_construction.rs from tests into its specific crate. I also put it in the module as requested.
Deleted tree_construction.rs from the test folder as it was copied over to a crate
#[cfg(test)] | ||
mod tests{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think an extra tests
module is necessary here. You already made a module by adding the file. So, I guess rename the file to tests.rs
and add #[cfg(test)
over the module definition in tokenizer.rs (which is missing btw)
Removes the #[cfg(test)] from the file and removed extra indentation. Also renamed it to tests.rs as asked.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now only the module declaration is missing. You need to add
#[cfg(test)
mod tests
to crates/gosub_html5/src/tokenizer.rs under line 6. E.g. here: https://github.com/gosub-browser/gosub-engine/blob/99d8f224649772511d392f396ca8e010c102ee7d/crates/gosub_html5/src/tokenizer.rs#L1-L6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Now we only need to look at what CI says
use gosub_testing::testing::tree_construction::Harness; | ||
use test_case::test_case; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems to not like these imports for some reason when i run make test
locally. Where is the test_case
macro being defined?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's an external crate. Basically just run
cargo add test_case --dev -p gosub_html5
It also seems like fmt and clippy aren't happy, it can be fixed via make format
I haven't looked really into what is wrong, again I'll do that tomorrow.
I'm seeing this in the CI logs too: |
Oh, yeah... I started the test run and then completely forgot about it... I'll take a look tomorrow. |
Okay, looks like, the old module definition is still there. Just delete this file: and in Cargo.toml these lines |
Looks like I also had to do |
looks like the testing data files for |
Deleted the [[test]] lines.
Okay, so let's just run CI again and see what fails... |
So, if you want to speed things up, I can push a commit to fix the rest of the checks. I don't know if you want that, since from as far as I know, this is in context of some sort of class. |
So, here is what is missing: In crates/gosub_html5/Cargo.toml (just appended to the bottom)
afterward, change the Here is the complete diff
diff --git a/Cargo.lock b/Cargo.lock
index 7d8f68a..0c729b3 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1324,9 +1324,11 @@ dependencies = [
"derive_more",
"gosub_css3",
"gosub_shared",
+ "gosub_testing",
"lazy_static",
"log",
"phf",
+ "test-case",
"thiserror",
"ureq",
"url",
diff --git a/crates/gosub_html5/Cargo.toml b/crates/gosub_html5/Cargo.toml
index a06f337..22b9e39 100644
--- a/crates/gosub_html5/Cargo.toml
+++ b/crates/gosub_html5/Cargo.toml
@@ -20,3 +20,8 @@ log = { version = "0.4.21", features = [] }
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
ureq = "2.9.7"
+
+[dev-dependencies]
+test-case = "3.3.1"
+gosub_testing = { path = "../gosub_testing", features = [] }
+
diff --git a/crates/gosub_testing/src/testing.rs b/crates/gosub_testing/src/testing.rs
index e0deb4b..3bd5bd5 100644
--- a/crates/gosub_testing/src/testing.rs
+++ b/crates/gosub_testing/src/testing.rs
@@ -2,5 +2,5 @@
pub mod tokenizer;
pub mod tree_construction;
-pub const FIXTURE_ROOT: &str = "./tests/data/html5lib-tests";
+pub const FIXTURE_ROOT: &str = "../../tests/data/html5lib-tests";
pub const TREE_CONSTRUCTION_PATH: &str = "tree-construction"; lastly, run You can push it in one commit if you want. |
yep it is for a class! As the class TA i was planning to commit the rest of the fixes after the due date (maybe later this week) unless @kaigidwani wants to give it a shot. |
i ended up just moving the data files to the crate since it seems like |
Yes if possible I would like to give it a shot, but I wouldn't be able to get to this until Thursday, just because of how my schedule is working out with finals season. T-T |
I actually don't really care, but it would keep test-files in one directory, however as you said, the path is relative to the crate, which is a bit messy... Do it like you want. If you have the solution with moving the test files already, you can also use that. |
Yeah, no problem, you can only learn things when making your hands dirty, and since you can't break anything, I don't see there any reason why not letting you (or others) doing that. When I think about my starts of coding, I don't think it was any better 😉 |
Hey, sorry to go back on what I said, but my plans are getting more complicated and I'd like to take some time off before I have to start my Summer job. Since you already have that push would it be alright if you went through with it? Thanks so much for the help with this, I really appreciate it. |
Yup, I can do that |
@Sharktheone just pushed my commits to hopefully finish up this PR - currently rerunning the tests locally to double check they still work. I figure since the tests and these data files are linked using a macro, it may be best to keep the data as close to the functions being tested as possible - similar to how it may be beneficial to keep the tests close to the code so that they are more likely to remain up to date. |
Ah, thanks, looks good |
Okay, somehow I can't push to the PR branch, neither over a new remote nor over the GitHub ref, maybe because it's the main branch? So these are my changes to get also the benchmarks working
diff --git a/Cargo.lock b/Cargo.lock
index 0c729b3..e60b7be 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1321,6 +1321,7 @@ dependencies = [
name = "gosub_html5"
version = "0.1.0"
dependencies = [
+ "criterion",
"derive_more",
"gosub_css3",
"gosub_shared",
diff --git a/Cargo.toml b/Cargo.toml
index 8b5692d..087e20b 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -18,14 +18,6 @@ members = [
[[example]]
name = "html5-parser"
-[[bench]]
-name = "tokenizer"
-harness = false
-
-[[bench]]
-name = "tree_construction"
-harness = false
-
[[bench]]
name = "tree_iterator"
harness = false
diff --git a/crates/gosub_html5/Cargo.toml b/crates/gosub_html5/Cargo.toml
index 9cfa992..8cb481e 100644
--- a/crates/gosub_html5/Cargo.toml
+++ b/crates/gosub_html5/Cargo.toml
@@ -23,4 +23,13 @@ ureq = "2.9.7"
[dev-dependencies]
gosub_testing = { path = "../gosub_testing" }
test-case = "3.3.1"
+criterion = { version = "0.5.1", features = ["html_reports"] }
+
+[[bench]]
+name = "tokenizer"
+harness = false
+
+[[bench]]
+name = "tree_construction"
+harness = false
diff --git a/benches/tokenizer.rs b/crates/gosub_html5/benches/tokenizer.rs
similarity index 100%
rename from benches/tokenizer.rs
rename to crates/gosub_html5/benches/tokenizer.rs
diff --git a/benches/tree_construction.rs b/crates/gosub_html5/benches/tree_construction.rs
similarity index 100%
rename from benches/tree_construction.rs
rename to crates/gosub_html5/benches/tree_construction.rs
|
There you go! TIL you can just copy paste the diff into a text file and |
Interesting... looks like it somehow didn't apply the diff --git a/Cargo.toml b/Cargo.toml
index 8b5692d..087e20b 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -18,14 +18,6 @@ members = [
[[example]]
name = "html5-parser"
-[[bench]]
-name = "tokenizer"
-harness = false
-
-[[bench]]
-name = "tree_construction"
-harness = false
-
[[bench]]
name = "tree_iterator"
harness = false part from the diff |
Done |
Okay, looks good. Looks like the last problem is commit signing. |
Is there a particular reason this is required? I couldn't see much in |
I don't know, why have set this up to block merging with unsigned commits, maybe @jaytaph can say anything about that. |
Hmm, that's interesting. I have no clue why that's happening... I guess, just add yourself to the AUTHORS file and call it a day? |
Don't worry about the authors file. The check isn't that good, and should be either be changed or even removed (and maybe there are other - better - actions available for this. I haven't done the research). As far as signed commits: they are preferred to make sure that code committed is signed off by that specific user. Even though everybody can commit, we should make sure that it's committed by the same user. For instance, There could come PR that looks like (co-)authored by one of the core members even though it's written by "evil hacker" that includes a backdoor (fortunately, that never happens /s). So with signed commits, we assure that that commit really comes from that specific user. This becomes more important with many contributers and PRs. Btw, signed tags will be a thing later on as soon as we actually have taggable code :) |
finally figured out commit signing |
Okay, I'm able to merge this now! 🎉 |
For issue #445, I have copied the tokenizer.rs over into crates/gosub_html5/src/tokenizer as test.rs. I have also moved the contents of tree_construction.rs onto the end of crates/gosub_html5/src/parser/tree_builder.rs. I made sure to add the module declarations and #[cfg(test)] above them.