Skip to content
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

Tests: Always pretty-print token streams #2421

Merged
merged 2 commits into from
Jun 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions test-suite.html
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,8 @@ <h2 id="writing-tests-explaining-the-simplified-token-stream">Explaining the sim
<li>All strings that are either empty or only contain whitespace, are removed from the token stream.</li>
<li>All empty structures are removed.</li>
</ul>
<p>To get a pretty-printed version of the simplified token stream of a failed test, add the <code>--pretty</code> modifier. Keep in mind that the pretty-printed token stream is indented using spaces, you may need to convert these to tabs. (Most editors today have an option which handles the conversion for you.)</p>

<pre><code class="language-bash">npm run test:languages -- --pretty</code></pre>
<p>Note: The pretty-printed simplified token stream is indented using 4 spaces. You have to convert these to tabs after you copy-pasted the JSON. (Most editors today have an option that handles the conversion for you.)</p>

<p>For further information: reading the tests of the test runner (<code>tests/testrunner-tests.js</code>) will help you understand the transformation.</p>
</section>
Expand Down
5 changes: 2 additions & 3 deletions tests/helper/test-case.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,8 @@ module.exports = {
*
* @param {string} languageIdentifier
* @param {string} filePath
* @param {boolean} [pretty=false]
*/
runTestCase(languageIdentifier, filePath, pretty = false) {
runTestCase(languageIdentifier, filePath) {
const testCase = this.parseTestCaseFile(filePath);
const usedLanguages = this.parseLanguageNames(languageIdentifier);

Expand Down Expand Up @@ -79,7 +78,7 @@ module.exports = {
const columnNumber = expectedJsonLines.pop().length + 1;
const lineNumber = testCase.expectedLineOffset + expectedJsonLines.length;

const tokenStreamStr = pretty ? TokenStreamTransformer.prettyprint(simplifiedTokenStream) : actual;
const tokenStreamStr = TokenStreamTransformer.prettyprint(simplifiedTokenStream);
const message = "\n\nActual Token Stream:" +
"\n-----------------------------------------\n" +
tokenStreamStr +
Expand Down
3 changes: 1 addition & 2 deletions tests/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ const testSuite =
? TestDiscovery.loadSomeTests(__dirname + "/languages", argv.language)
// load complete test suite
: TestDiscovery.loadAllTests(__dirname + "/languages");
const pretty = 'pretty' in argv;

// define tests for all tests in all languages in the test suite
for (const language in testSuite) {
Expand All @@ -28,7 +27,7 @@ for (const language in testSuite) {

it("– should pass test case '" + fileName + "'", function () {
if (path.extname(filePath) === '.test') {
TestCase.runTestCase(language, filePath, pretty);
TestCase.runTestCase(language, filePath);
} else {
TestCase.runTestsWithHooks(language, require(filePath));
}
Expand Down