Skip to content
This repository was archived by the owner on Oct 14, 2020. It is now read-only.

Add Rust version 1.33.0 #690

Closed
LesnyRumcajs opened this issue Feb 6, 2019 · 20 comments
Closed

Add Rust version 1.33.0 #690

LesnyRumcajs opened this issue Feb 6, 2019 · 20 comments

Comments

@LesnyRumcajs
Copy link

Please complete the following information:

  • Name: Rust
  • Version: 1.32.0

Couldn't find a better category. It would be nice to have newest Rust available on Codewars. It would be even nicer if existing katas would have access to this new Rust version (or at least 1.25). Katas created with Rust 1.15 are most probably finishable with higher version of Rust because of it's renowned backward compatibility (they run tests with major crates to check this, I guess katas are not as complicated as Diesel, Serde or Hyper. It makes me a little bit sad when I finish writing the code, get compiler error, and finally notice that the particular kata is for 1.15 exclusively.

👍 reaction might help.

@kazk
Copy link
Member

kazk commented Feb 6, 2019

Yeah, I've been wanting to add a newer version and get rid of 1.15.

Rust on Codewars was originally contributed by the community, then I rewrote it so we can use Cargo while keeping it compatible (#466). So 1.15 on Codewars is a hack. When I added 1.25, I removed most of the hacks and that's why it's not compatible. See Rust wiki page for the differences.

Also, the test output is manually parsed and it's not standardized so this changes between versions. I've been waiting for the JSON output that was proposed years ago, but I don't think it's been finalized yet :(

It's more work than it seems.

@LesnyRumcajs
Copy link
Author

I see. Thanks for the feedback.

@kazk
Copy link
Member

kazk commented Feb 6, 2019

I just created a new wiki page of a list of Rust 1.15 kata to be updated.
You can use that to avoid them or help us update :)

We currently have 117 kata with 1.25 enabled and 95 with 1.15.

@LesnyRumcajs
Copy link
Author

Great, I'll get to it. :)

@hedgehog1024
Copy link

I just created a new wiki page of a list of Rust 1.15 kata to be updated.
You can use that to avoid them or help us update :)

I wish to help. However, I see no way to translate a kata from one Rust version to another. How one can do it?

@kazk
Copy link
Member

kazk commented Feb 7, 2019

@hedgehog1024 Thanks :)

You've completed "Don't give me five!" so I'll use that for example.

When changing language version, we usually just do it by editing kata. So open the kata editor by clicking "Edit Kata".

(EDIT: See "Coauthor Kata" in Privileges if you don't see "Edit Kata". You might not have enough honor points or you might need to let others know by making a suggestion comment.)

image

The original test looks like the following:

// At the moment random tests are not possible for RUST
// https://github.com/Codewars/codewars-runner-cli/issues/240

#[test]
fn basic_tests() {
    assert_eq!(dont_give_me_five(1, 9), 8);
    assert_eq!(dont_give_me_five(4, 17), 12);
}

#[test]
fn advanced_tests() {
    assert_eq!(dont_give_me_five(1, 90), 72);
    assert_eq!(dont_give_me_five(-4, 17), 20);
    assert_eq!(dont_give_me_five(-4, 37), 38);
    assert_eq!(dont_give_me_five(-14, -1), 13);
    assert_eq!(dont_give_me_five(-14, -6), 9);
}

(BTW, it's possible to add random tests even on 1.15)

To change this to make it compatible with 1.25, we need to put them inside a child module tests.

#[cfg(test)]
mod tests {
use dont_give_me_five; // or use super::*;

// TODO add random tests

#[test]
fn basic_tests() {
    assert_eq!(dont_give_me_five(1, 9), 8);
    assert_eq!(dont_give_me_five(4, 17), 12);
}

#[test]
fn advanced_tests() {
    assert_eq!(dont_give_me_five(1, 90), 72);
    assert_eq!(dont_give_me_five(-4, 17), 20);
    assert_eq!(dont_give_me_five(-4, 37), 38);
    assert_eq!(dont_give_me_five(-14, -1), 13);
    assert_eq!(dont_give_me_five(-14, -6), 9);
}
}
+ #[cfg(test)]
+ mod tests {
+ use dont_give_me_five;
 
+ }

You can verify this by clicking "Validate Solution" after changing the language version to 1.25. Don't forget to also update the "Example Test Cases".

image

When you're done, just click "Re-Publish" (this might take some time to finish).

image

To use crates like rand, do something like the following:

#[cfg(test)]
extern crate rand;

#[cfg(test)]
mod tests {
    use add; // function to test
    use rand;
    use rand::distributions::{IndependentSample, Range};
    #[test]
    fn returns_sum() {
        let between = Range::new(1, 10);
        let mut rng = rand::thread_rng();
        let x = between.ind_sample(&mut rng);
        let y = between.ind_sample(&mut rng);
        assert_eq!(add(x, y), x + y);
    }
}

@LesnyRumcajs
Copy link
Author

LesnyRumcajs commented Feb 7, 2019

Actually I don't have edit kata option. Is higher kyu required for this?
image

@kazk
Copy link
Member

kazk commented Feb 7, 2019

You're right. I completely forgot about that :( You need 4000 honor points. See this table.

@LesnyRumcajs
Copy link
Author

Grinding time!

@LesnyRumcajs
Copy link
Author

@kazk are you positive 4000 honor points is the only requirement? I still can't edit katas the way you described it.

image

@kazk
Copy link
Member

kazk commented Feb 11, 2019

@LesnyRumcajs 4000 honor points should be the only requirement from a user. It should show "Edit Kata" if you have 4000 points and the kata doesn't have contribution disabled.

It can be a cache issue if you had loaded that page before. Can you try if "Edit Kata" shows on other kata?

@LesnyRumcajs
Copy link
Author

@kazk Ya, I relogged, cleared the cache and checked out even from a different machine. Strangely I hadn't received any notification about my new super powers when passed 4k.

@kazk
Copy link
Member

kazk commented Feb 11, 2019

@LesnyRumcajs Something might be broken. It'll be tracked on codewars/codewars.com#1723

@LesnyRumcajs
Copy link
Author

@kazk Okay, I'm starting to update the katas. If I can't edit it (no issues in past week, contributing disabled), should I add an issue so the kata author will do it himself / herself (or wait till I can do it myself)?

@kazk
Copy link
Member

kazk commented Feb 12, 2019

@LesnyRumcajs Thanks!
I'd suggest creating a suggestion comment with a link to the wiki page.

Something like:

Need to update Rust to 1.25. See List of Rust 1.15 Kata to Update.

That's what the other user helping to update Haskell is doing.

@kazk kazk self-assigned this Feb 24, 2019
@kazk
Copy link
Member

kazk commented Feb 24, 2019

@LesnyRumcajs I think I can add Rust 1.32 soon (luckily the test output looks the same).

The only issue I've found so far is rand. Rust 1.25 has 0.4.2 and I'd like to update to the latest 0.6.5 for Rust 1.32. So any kata using rand needs to be updated in order to make it compatible.

I'll probably wait for Rust 1.33 (2019-02-28) though. I hope changes from 1.32 doesn't affect us.


For future versions, I'd like to have at most 2 versions at the same time. We can add a new version when all of the kata using older versions are updated to newer one. I'm going to make 1.33 an exception because 1.15 is a huge hack and requires larger effort to update to 1.25.

So for now we can have versions:

  • 1.15
  • 1.25
  • 1.33

Next step is to drop 1.15 by updating existing kata using it to 1.25+:

  • 1.25
  • 1.33

Then, before adding another version, I'll ask the community to update any kata using older version to newer one so we can drop the older one. I'll help with making a list of kata to update and also run a script to update them if it's compatible without code change.

If we need significant change for some reason, I'll consider adding a version temporarily.

@bartsmykla
Copy link

Hi @kazk is there a way to help creators of Katas to move from 1.15 to newer ones, or they need to do that themselves?

@LesnyRumcajs
Copy link
Author

@bartsmykla You can help by following @kazk guide here: #690 (comment)

@kazk
Copy link
Member

kazk commented Feb 25, 2019

@bartsmykla Thanks. You can also post a comment suggesting an update and maybe others can help. See #690 (comment)

@kazk kazk added the status/next next up label Feb 25, 2019
@kazk kazk changed the title Add Rust version 1.32.0 Add Rust version 1.33.0 Feb 28, 2019
@kazk kazk added status/ready Ready to be deployed and removed status/next next up labels Mar 1, 2019
@kazk
Copy link
Member

kazk commented Mar 1, 2019

Added Rust 1.33!

I ran a script to update compatible kata to use 1.33 and looks like we have 164 kata with 1.33 enabled.

@kazk kazk closed this as completed Mar 1, 2019
@kazk kazk removed the status/ready Ready to be deployed label Mar 1, 2019
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Projects
None yet
Development

No branches or pull requests

4 participants