ci: comment compare
MODIFY
.github/workflows/test262.yml
.github/workflows/test262.yml
@@ -33,17 +33,15 @@ jobs:
uses: Swatinem/rust-cache@v1
- name: Run Test262 suite
continue-on-error: true
- run: cargo xtask coverage --json
- - name: Rename the emitted file
- run: |
- mv base_results.json new_results.json
+ run: cargo xtask coverage --json > new_results.json
- name: Save test results
uses: actions/upload-artifact@v2
with:
name: new_results
path: new_results.json
- compare:
+# This job compares the coverage results from this PR and the coverage results from master
+ coverage-comparison:
needs: coverage
name: Compare coverage
runs-on: ${{ matrix.os }}
@@ -56,8 +54,7 @@ jobs:
uses: actions/checkout@v2
with:
submodules: recursive
- # To restore once the main branch has the new command
- # ref: main
+ ref: main
- name: Install toolchain
uses: actions-rs/toolchain@v1
with:
@@ -67,10 +64,55 @@ jobs:
uses: Swatinem/rust-cache@v1
- name: Run Test262 suite on main branch
continue-on-error: true
- run: cargo xtask coverage --json
+ run: cargo xtask coverage --json > base_results.json
- name: Download PRs test results
uses: actions/download-artifact@v2
with:
name: new_results
- name: Compare results on ${{ matrix.os }}
- run: cargo xtask compare ./base_results.json ./new_results.json --markdown
+ if: github.event_name == 'pull_request'
+ id: comparison
+ shell: bash
+ run: |
+ comment="$(cargo xtask compare ./base_results.json ./new_results.json --markdown)"
+ comment="${comment//'%'/'%25'}"
+ comment="${comment//$'\n'/'%0A'}"
+ comment="${comment//$'\r'/'%0D'}"
+ echo "::set-output name=comment::$comment"
+
+ - name: Get the PR number
+ if: github.event_name == 'pull_request'
+ id: pr-number
+ uses: kkak10/pr-number-action@v1.3
+
+ - name: Find Previous Comment
+ if: github.event_name == 'pull_request'
+ uses: peter-evans/find-comment@v1.3.0
+ id: previous-comment
+ with:
+ issue-number: ${{ steps.pr-number.outputs.pr }}
+ body-includes: Test262 conformance changes
+
+ - name: Update comment
+ if: github.event_name == 'pull_request' && steps.previous-comment.outputs.comment-id
+ uses: peter-evans/create-or-update-comment@v1.4.5
+ continue-on-error: true
+ with:
+ comment-id: ${{ steps.previous-comment.outputs.comment-id }}
+ body: |
+ ### Test262 comparison coverage results on ${{ matrix.os }}
+
+ ${{ steps.comparison.outputs.comment }}
+ edit-mode: replace
+
+ - name: Write a new comment
+ if: github.event_name == 'pull_request' && !steps.previous-comment.outputs.comment-id
+ uses: peter-evans/create-or-update-comment@v1.4.5
+ continue-on-error: true
+ with:
+ issue-number: ${{ steps.pr-number.outputs.pr }}
+ body: |
+ ### Test262 comparison coverage results on ${{ matrix.os }}
+
+ ${{ steps.comparison.outputs.comment }}
+

MODIFY
crates/rslint_parser/src/parser.rs
crates/rslint_parser/src/parser.rs
@@ -423,19 +423,24 @@ impl<'t> Parser<'t> {
}
/// Bump and add an error event
- pub fn err_and_bump(&mut self, err: impl Into<ParserError>) {
+ pub fn err_and_bump(&mut self, err: impl Into<ParserError>, unknown_syntax_kind: SyntaxKind) {
let m = self.start();
self.bump_any();
- m.complete(self, SyntaxKind::ERROR);
+ m.complete(self, unknown_syntax_kind);
self.error(err);
}
- pub fn err_if_not_ts(&mut self, mut marker: impl BorrowMut<CompletedMarker>, err: &str) {
+ pub fn err_if_not_ts(
+ &mut self,
+ mut marker: impl BorrowMut<CompletedMarker>,
+ err: &str,
+ unknown_syntax_kind: SyntaxKind,
+ ) {
if self.typescript() {
return;
}
let borrow = marker.borrow_mut();
- borrow.change_kind(self, SyntaxKind::ERROR);
+ borrow.change_kind(self, unknown_syntax_kind);
let err = self.err_builder(err).primary(borrow.range(self), "");
self.error(err);
@@ -489,7 +494,11 @@ impl<'t> Parser<'t> {
start..end
}
- pub fn expr_with_semi_recovery(&mut self, assign: bool) -> Option<CompletedMarker> {
+ pub fn expr_with_semi_recovery(
+ &mut self,
+ assign: bool,
+ unknown_syntax_kind: SyntaxKind,
+ ) -> Option<CompletedMarker> {
let func = if assign {
syntax::expr::assign_expr
} else {
@@ -504,7 +513,7 @@ impl<'t> Parser<'t> {
self.error(err);
self.bump_any();
- m.complete(self, SyntaxKind::ERROR);
+ m.complete(self, unknown_syntax_kind);
return None;
}
@@ -715,7 +724,7 @@ impl CompletedMarker {
}
pub fn err_if_not_ts(&mut self, p: &mut Parser, err: &str) {
- p.err_if_not_ts(self, err);
+ p.err_if_not_ts(self, err, SyntaxKind::ERROR);
}
}

MODIFY
crates/rslint_parser/src/syntax/expr.rs
crates/rslint_parser/src/syntax/expr.rs
@@ -1012,7 +1012,7 @@ pub fn primary_expr(p: &mut Parser) -> Option<CompletedMarker> {
))
.primary(p.cur_tok().range, "");
- p.err_and_bump(err);
+ p.err_and_bump(err, ERROR);
m.complete(p, ERROR)
} else {
let err = p

MODIFY
crates/rslint_parser/src/syntax/stmt.rs
crates/rslint_parser/src/syntax/stmt.rs
@@ -113,7 +113,7 @@ pub fn stmt(p: &mut Parser, recovery_set: impl Into<Option<TokenSet>>) -> Option
// We must explicitly handle this case or else infinite recursion can happen
if p.at_ts(token_set![T!['}'], T![import], T![export]]) {
- p.err_and_bump(err);
+ p.err_and_bump(err, ERROR);
return None;
}
@@ -171,7 +171,7 @@ fn expr_stmt(p: &mut Parser) -> Option<CompletedMarker> {
m.complete(p, ERROR);
}
- let mut expr = p.expr_with_semi_recovery(false)?;
+ let mut expr = p.expr_with_semi_recovery(false, ERROR)?;
// Labelled stmt
if expr.kind() == JS_REFERENCE_IDENTIFIER_EXPRESSION && p.at(T![:]) {
expr.change_kind(p, NAME);
@@ -255,7 +255,7 @@ pub fn throw_stmt(p: &mut Parser) -> CompletedMarker {
p.error(err);
} else {
- p.expr_with_semi_recovery(false);
+ p.expr_with_semi_recovery(false, ERROR);
}
semi(p, start..p.cur_tok().range.end);
m.complete(p, JS_THROW_STATEMENT)
@@ -347,7 +347,7 @@ pub fn return_stmt(p: &mut Parser) -> CompletedMarker {
let start = p.cur_tok().range.start;
p.expect(T![return]);
if !p.has_linebreak_before_n(0) && p.at_ts(STARTS_EXPR) {
- p.expr_with_semi_recovery(false);
+ p.expr_with_semi_recovery(false, ERROR);
}
semi(p, start..p.cur_tok().range.end);
let complete = m.complete(p, JS_RETURN_STATEMENT);
@@ -779,13 +779,13 @@ fn variable_initializer(p: &mut Parser) {
let m = p.start();
p.expect(T![=]);
- p.expr_with_semi_recovery(true);
+ p.expr_with_semi_recovery(true, ERROR);
m.complete(p, SyntaxKind::JS_EQUAL_VALUE_CLAUSE);
}
// A do.. while statement, such as `do {} while (true)`
-// test do_while_stmt
+// test do_while_stmtR
// do { } while (true)
// do throw Error("foo") while (true)
pub fn do_stmt(p: &mut Parser) -> CompletedMarker {

MODIFY
xtask/src/compare/mod.rs
xtask/src/compare/mod.rs
@@ -3,7 +3,11 @@ use std::path::PathBuf;
mod results;
-pub fn run(base_result_path: Option<&str>, new_result_path: Option<&str>, markdown: bool) {
+pub fn coverage_compare(
+ base_result_path: Option<&str>,
+ new_result_path: Option<&str>,
+ markdown: bool,
+) {
// resolve the path passed as argument, or retrieve the default one
let base_result_dir = if let Some(base_result_path) = base_result_path {
PathBuf::from(base_result_path)

MODIFY
xtask/src/coverage/files.rs
xtask/src/coverage/files.rs
@@ -7,12 +7,9 @@ use std::any::Any;
use std::fs::read_to_string;
use std::io;
use std::path::PathBuf;
-use std::{fs::File, io::Write};
use walkdir::WalkDir;
use yastl::Pool;
-use crate::{project_root, BASE_RESULT_FILE};
-
const BASE_PATH: &str = "xtask/src/coverage/test262/test";
#[derive(Debug, Clone)]
@@ -98,7 +95,7 @@ fn read_metadata(code: &str) -> io::Result<MetaData> {
serde_yaml::from_str(yaml).map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))
}
-pub fn get_test_files(query: Option<&str>, pool: &Pool) -> Vec<TestFile> {
+pub fn get_test_files(query: Option<&str>, pool: &Pool, json: bool) -> Vec<TestFile> {
let start = std::time::Instant::now();
let files = WalkDir::new(BASE_PATH)
@@ -146,11 +143,13 @@ pub fn get_test_files(query: Option<&str>, pool: &Pool) -> Vec<TestFile> {
let files = rx.into_iter().collect();
pb.finish_and_clear();
+ if !json {
println!(
"{} test files in {:.2}s",
"Loaded".bold().bright_green(),
start.elapsed().as_secs_f32()
);
+ }
files
}
@@ -260,16 +259,9 @@ impl TestResults {
self.details.iter().filter(|res| res.fail.is_none()).count()
}
- /// Saves results into a JSON file inside the temporary directory of the OS
+ /// Prints results of the coverage to STDOUT in JSON format
pub fn dump_to_json(&self) {
let json = serde_json::to_string(&self).unwrap();
- let path = project_root().join(BASE_RESULT_FILE);
-
- let mut file = File::create(&path).expect("Can't open the JSON file");
-
- file.write_all(json.as_bytes())
- .expect("Can't write in the JSON file");
- println!();
- println!("The test result report has been saved in: {:?}", &path);
+ println!("{}", json);
}
}

MODIFY
xtask/src/coverage/mod.rs
xtask/src/coverage/mod.rs
@@ -11,7 +11,7 @@ use yastl::Pool;
pub const TEST_JSON_PATH: &str = "xtask/src/base_results.json";
pub fn run(query: Option<&str>, pool: Pool, json: bool) {
- let files = get_test_files(query, &pool);
+ let files = get_test_files(query, &pool, json);
let num_ran = files.len();
let detailed = num_ran < 10;
@@ -71,6 +71,10 @@ pub fn run(query: Option<&str>, pool: Pool, json: bool) {
let _ = std::panic::take_hook();
pb.finish_and_clear();
+
+ if json {
+ test_results.dump_to_json();
+ } else {
println!(
"\n{} {} tests in {:.2}s\n",
"Ran".bold().bright_green(),
@@ -95,7 +99,6 @@ pub fn run(query: Option<&str>, pool: Pool, json: bool) {
table.columns.insert(counter, column);
counter += 1;
};
-
create_column("Tests ran".into());
create_column("Passed".green());
create_column("Failed".red());
@@ -105,17 +108,13 @@ pub fn run(query: Option<&str>, pool: Pool, json: bool) {
vec![&num_ran, &passed, &errored, &panicked, &coverage];
table.print(vec![numbers]);
-
- if json {
- test_results.dump_to_json();
- }
-
if passed > 0 {
std::process::exit(1);
} else {
std::process::exit(0);
}
}
+}
pub fn run_test_file(file: TestFile) -> TestResult {
let TestFile { code, meta, path } = file;

MODIFY
xtask/src/main.rs
xtask/src/main.rs
@@ -32,7 +32,7 @@ fn main() -> Result<()> {
let base_result_path = free.get(0).map(String::as_str);
let new_result_path = free.get(1).map(String::as_str);
- compare::run(base_result_path, new_result_path, markdown);
+ compare::coverage_compare(base_result_path, new_result_path, markdown);
Ok(())
}
// "docgen" => {

ci: comment compare (#1782)