rust-playground icon indicating copy to clipboard operation
rust-playground copied to clipboard

Auto selection of test cfg doesn't respect /**/ comments

Open DrAlta opened this issue 2 years ago • 2 comments

this will run is test by default

/*
#[cfg(test)]
mod tests {
use crate::{Vignette, VignettePart, VignetteSet};
    #[test]
    fn test1(){
        assert_eq!(1, 1)
    }
}
*/

this with run as build by default

/*
#[cfg(test)]
mod tests {
use crate::{Vignette, VignettePart, VignetteSet};
    //#[test]
    fn test1(){
        assert_eq!(1, 1)
    }
}
*/

I'm guessing it that the playground doesn't check for comments, it just checks for something like /^\s*#[test]/

DrAlta avatar Dec 01 '22 18:12 DrAlta

I think the detection is on a best effort basis. It's done using regex and it might affect usability a bit if it had to try to parse the code to determine if a block is commented out.

c-git avatar Dec 03 '22 06:12 c-git

This will strip out the commits

const commitRegex = /(.*)\/\*[^(\\\*)]*\*\/(.*)/m;
function strip (input) {
  let match = input.match(commitRegex);
  while (match) {
    input = `${match[1]}${match[2]}`;
    console.log(input);
    match = input.match(commitRegex);
  }
  return(input);
};

DrAlta avatar Dec 03 '22 22:12 DrAlta