From 9aa2e9ec14a80b60ea5da2a16905e355af38b3f1 Mon Sep 17 00:00:00 2001 From: nodiscc Date: Mon, 20 May 2019 19:40:06 +0200 Subject: move tests-related files to a tests/ directory --- .travis.yml | 6 ++-- Dangerfile | 39 -------------------------- test.js | 85 -------------------------------------------------------- tests/Dangerfile | 39 ++++++++++++++++++++++++++ tests/test.js | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 127 insertions(+), 127 deletions(-) delete mode 100644 Dangerfile delete mode 100644 test.js create mode 100644 tests/Dangerfile create mode 100644 tests/test.js diff --git a/.travis.yml b/.travis.yml index 9267efe1..3881cdab 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,12 +9,12 @@ before_install: - gem install danger before_script: - + script: - git diff master.. --unified=0 README.md | grep --perl-regexp --only-matching --silent "(?<=^\+).*" >> temp.md || (exit 0) - - node test.js temp.md + - node tests/test.js temp.md - awesome_bot temp.md --allow-redirect || (exit 0) - - danger --verbose + - danger --dangerfile tests/Dangerfile --verbose notifications: email: false diff --git a/Dangerfile b/Dangerfile deleted file mode 100644 index 115931df..00000000 --- a/Dangerfile +++ /dev/null @@ -1,39 +0,0 @@ -# Danger CI configuration file -# https://danger.systems/guides/getting_started.html - -# Check for changes to README.md -has_readme_changes = git.modified_files.include?("README.md") - -# Ensure there is a summary for a pull request -fail 'Please provide a summary in the Pull Request description' if github.pr_body.length < 5 - -# Warn if PR guideline boxes are not checked. -warn 'Please check PR guidelines and check the boxes.' if github.pr_body.include? '- [ ]' - -# Warn if pull request is not updated -warn 'Please provide a descriptive title for the Pull Request' if github.pr_title.include? 'Update README.md' - -# Warn when there are merge commits in the diff -warn 'Please rebase to get rid of the merge commits in this Pull Request' if git.commits.any? { |c| c.message =~ /^Merge branch 'master'/ } - -# Check links -if has_readme_changes - require 'json' - results = File.read 'ab-results-temp.md-markdown-table.json' - j = JSON.parse results - if j['error']==true - warn j['title'] - markdown j['message'] - end -end - -# Check syntax -if has_readme_changes - require 'json' - syntaxresults = File.read 'syntaxcheck.json' - sj = JSON.parse syntaxresults - if sj['error']==true - fail sj['title'] - markdown sj['message'] - end -end diff --git a/test.js b/test.js deleted file mode 100644 index 94e7798c..00000000 --- a/test.js +++ /dev/null @@ -1,85 +0,0 @@ -// Accepts input of any filename, ie. node test.js README.md - -const fs = require('fs'); - -let log = '{\n'; -let issuelog = ' "message": "#### Syntax Issues\\n\\n Name | Entry\\n----|----------------------\\n'; - -const file = fs.readFileSync(process.argv[2], 'utf8'); // Reads argv into var file - -function entryFilter(md) { // Function to find lines with entries - const linepatt = /^\s{0,2}-\s\[.*`/; - return linepatt.test(md); -} - -function split(text) { // Function to split lines into array - return text.split(/\r?\n/); -} - -function findPattern(text) { // Test entries against 8 patterns. If matches pattern returns true - const nodnospatt = /^\s{0,2}-\s\[.*?\]\(.*?\) - .{0,249}?\. `.*?` `.*?`/; // Regex for entries with no demo and no source code - const slpatt = /^\s{0,2}-\s\[.*?\]\(.*?\) - .{0,249}?\. \(\[Demo\b\]\(.*?\), \[Source Code\b\]\(.*?\)\) `.*?` `.*?`/; // Regex for entries with demo and source code - const nodpatt = /^\s{0,2}-\s\[.*?\]\(.*?\) - .{0,249}?\. \(\[Source Code\]\(.*?\)\) `.*?` `.*?`/; // Regex for entries with no demo - const nospatt = /^\s{0,2}-\s\[.*?\]\(.*?\) - .{0,249}?\. \(\[Demo\]\(.*?\)\) `.*?` `.*?`/; // Regex for entries with no source code - const pnodnospatt = /^\s{0,2}-\s\[.*?\]\(.*?\) `⚠` - .{0,249}?\. `.*?` `.*?`/; // Regex for entries with proprietary with no demo and no source code - const pslpatt = /^\s{0,2}-\s\[.*?\]\(.*?\) `⚠` - .{0,249}?\. \(\[Demo\b\]\(.*?\), \[Source Code\b\]\(.*?\)\) `.*?` `.*?`/; // Regex for entries with proprietary with demo and source code - const pnodpatt = /^\s{0,2}-\s\[.*?\]\(.*?\) `⚠` - .{0,249}?\. \(\[Source Code\]\(.*?\)\) `.*?` `.*?`/; // Regex for entries with proprietary with no demo - const pnospatt = /^\s{0,2}-\s\[.*?\]\(.*?\) `⚠` - .{0,249}?\. \(\[Demo\]\(.*?\)\) `.*?` `.*?`/; // Regex for entries with proprietary with no source code - if (nodnospatt.test(text) === true) { - return true; - } else if (slpatt.test(text) === true) { - return true; - } else if (nodpatt.test(text) === true) { - return true; - } else if (nospatt.test(text) === true) { - return true; - } else if (pnodnospatt.test(text) === true) { - return true; - } else if (pslpatt.test(text) === true) { - return true; - } else if (pnodpatt.test(text) === true) { - return true; - } else if (pnospatt.test(text) === true) { - return true; - } - return false; -} - -function entryErrorCheck(md) { - const namepatt = /^\s{0,2}-\s\[(.*?)\]/; // regex pattern to find name of entryArray - const entries = split(md); // Inserts each line into the entries array - let totalFail = 0; - let totalPass = 0; - let total = 0; - const entryArray = []; - for (let i = 0, len = entries.length; i < len; i += 1) { // Loop to create array of objects - entryArray[i] = new Object; - entryArray[i].raw = entries[i]; - if (entryFilter(entries[i]) === true) { // filter out lines that don't with * [) - total += 1; - entryArray[i].name = namepatt.exec(entries[i])[1]; // Parses name of entry - entryArray[i].pass = findPattern(entries[i]); // Tests against known patterns - if (entryArray[i].pass === true) { // If entry passes increment totalPass counter - totalPass += 1; - } else { - console.log(`${entryArray[i].name} Failed.`); // If entry fails increment totalFail counter and append error to issuelog - // entryArray[i].error = findError(entries[i]) //WIP - totalFail += 1; - issuelog += `${entryArray[i].name} | ${entries[i]} \\n`; - } - } - } - if (totalFail > 0) { // Logs # passed & failed to console, and failures to syntaxcheck.json - console.log(`${totalFail} Failed, ${totalPass} Passed, of ${total}`); - log += ` "error": true,\n "title": "Found ${totalFail} entries with syntax error(s).",\n`; - fs.writeFileSync('syntaxcheck.json', `${log} ${issuelog} "\n}`); - process.exit(1); - } else { // Logs # of entries passed to console and error: false to syntaxcheck.json - console.log(`${totalFail} Failed, ${totalPass} Passed, of ${total} \n`); - log += ' "error": false\n}'; - fs.writeFileSync('syntaxcheck.json', log); - process.exit(0); - } -} - -entryErrorCheck(file); diff --git a/tests/Dangerfile b/tests/Dangerfile new file mode 100644 index 00000000..115931df --- /dev/null +++ b/tests/Dangerfile @@ -0,0 +1,39 @@ +# Danger CI configuration file +# https://danger.systems/guides/getting_started.html + +# Check for changes to README.md +has_readme_changes = git.modified_files.include?("README.md") + +# Ensure there is a summary for a pull request +fail 'Please provide a summary in the Pull Request description' if github.pr_body.length < 5 + +# Warn if PR guideline boxes are not checked. +warn 'Please check PR guidelines and check the boxes.' if github.pr_body.include? '- [ ]' + +# Warn if pull request is not updated +warn 'Please provide a descriptive title for the Pull Request' if github.pr_title.include? 'Update README.md' + +# Warn when there are merge commits in the diff +warn 'Please rebase to get rid of the merge commits in this Pull Request' if git.commits.any? { |c| c.message =~ /^Merge branch 'master'/ } + +# Check links +if has_readme_changes + require 'json' + results = File.read 'ab-results-temp.md-markdown-table.json' + j = JSON.parse results + if j['error']==true + warn j['title'] + markdown j['message'] + end +end + +# Check syntax +if has_readme_changes + require 'json' + syntaxresults = File.read 'syntaxcheck.json' + sj = JSON.parse syntaxresults + if sj['error']==true + fail sj['title'] + markdown sj['message'] + end +end diff --git a/tests/test.js b/tests/test.js new file mode 100644 index 00000000..94e7798c --- /dev/null +++ b/tests/test.js @@ -0,0 +1,85 @@ +// Accepts input of any filename, ie. node test.js README.md + +const fs = require('fs'); + +let log = '{\n'; +let issuelog = ' "message": "#### Syntax Issues\\n\\n Name | Entry\\n----|----------------------\\n'; + +const file = fs.readFileSync(process.argv[2], 'utf8'); // Reads argv into var file + +function entryFilter(md) { // Function to find lines with entries + const linepatt = /^\s{0,2}-\s\[.*`/; + return linepatt.test(md); +} + +function split(text) { // Function to split lines into array + return text.split(/\r?\n/); +} + +function findPattern(text) { // Test entries against 8 patterns. If matches pattern returns true + const nodnospatt = /^\s{0,2}-\s\[.*?\]\(.*?\) - .{0,249}?\. `.*?` `.*?`/; // Regex for entries with no demo and no source code + const slpatt = /^\s{0,2}-\s\[.*?\]\(.*?\) - .{0,249}?\. \(\[Demo\b\]\(.*?\), \[Source Code\b\]\(.*?\)\) `.*?` `.*?`/; // Regex for entries with demo and source code + const nodpatt = /^\s{0,2}-\s\[.*?\]\(.*?\) - .{0,249}?\. \(\[Source Code\]\(.*?\)\) `.*?` `.*?`/; // Regex for entries with no demo + const nospatt = /^\s{0,2}-\s\[.*?\]\(.*?\) - .{0,249}?\. \(\[Demo\]\(.*?\)\) `.*?` `.*?`/; // Regex for entries with no source code + const pnodnospatt = /^\s{0,2}-\s\[.*?\]\(.*?\) `⚠` - .{0,249}?\. `.*?` `.*?`/; // Regex for entries with proprietary with no demo and no source code + const pslpatt = /^\s{0,2}-\s\[.*?\]\(.*?\) `⚠` - .{0,249}?\. \(\[Demo\b\]\(.*?\), \[Source Code\b\]\(.*?\)\) `.*?` `.*?`/; // Regex for entries with proprietary with demo and source code + const pnodpatt = /^\s{0,2}-\s\[.*?\]\(.*?\) `⚠` - .{0,249}?\. \(\[Source Code\]\(.*?\)\) `.*?` `.*?`/; // Regex for entries with proprietary with no demo + const pnospatt = /^\s{0,2}-\s\[.*?\]\(.*?\) `⚠` - .{0,249}?\. \(\[Demo\]\(.*?\)\) `.*?` `.*?`/; // Regex for entries with proprietary with no source code + if (nodnospatt.test(text) === true) { + return true; + } else if (slpatt.test(text) === true) { + return true; + } else if (nodpatt.test(text) === true) { + return true; + } else if (nospatt.test(text) === true) { + return true; + } else if (pnodnospatt.test(text) === true) { + return true; + } else if (pslpatt.test(text) === true) { + return true; + } else if (pnodpatt.test(text) === true) { + return true; + } else if (pnospatt.test(text) === true) { + return true; + } + return false; +} + +function entryErrorCheck(md) { + const namepatt = /^\s{0,2}-\s\[(.*?)\]/; // regex pattern to find name of entryArray + const entries = split(md); // Inserts each line into the entries array + let totalFail = 0; + let totalPass = 0; + let total = 0; + const entryArray = []; + for (let i = 0, len = entries.length; i < len; i += 1) { // Loop to create array of objects + entryArray[i] = new Object; + entryArray[i].raw = entries[i]; + if (entryFilter(entries[i]) === true) { // filter out lines that don't with * [) + total += 1; + entryArray[i].name = namepatt.exec(entries[i])[1]; // Parses name of entry + entryArray[i].pass = findPattern(entries[i]); // Tests against known patterns + if (entryArray[i].pass === true) { // If entry passes increment totalPass counter + totalPass += 1; + } else { + console.log(`${entryArray[i].name} Failed.`); // If entry fails increment totalFail counter and append error to issuelog + // entryArray[i].error = findError(entries[i]) //WIP + totalFail += 1; + issuelog += `${entryArray[i].name} | ${entries[i]} \\n`; + } + } + } + if (totalFail > 0) { // Logs # passed & failed to console, and failures to syntaxcheck.json + console.log(`${totalFail} Failed, ${totalPass} Passed, of ${total}`); + log += ` "error": true,\n "title": "Found ${totalFail} entries with syntax error(s).",\n`; + fs.writeFileSync('syntaxcheck.json', `${log} ${issuelog} "\n}`); + process.exit(1); + } else { // Logs # of entries passed to console and error: false to syntaxcheck.json + console.log(`${totalFail} Failed, ${totalPass} Passed, of ${total} \n`); + log += ' "error": false\n}'; + fs.writeFileSync('syntaxcheck.json', log); + process.exit(0); + } +} + +entryErrorCheck(file); -- cgit v1.2.3