UNPKG

5.88 kBHTMLView Raw
1<p><a href="https://www.npmjs.com/package/citeproc-test-runner">Citeproc Test Runner</a> (CTR for short) is a productivity tool for maintaining citation styles in the popular <a href="https://citationstyles.org/">Citation Style Language</a> (CSL) used by <a href="https://www.zotero.org/">Zotero</a>, <a href="https://www.mendeley.com/">Mendeley</a>, <a href="https://juris-m.github.io/">Jurism</a> and other projects. The script assumes that <a href="https://nodejs.org/">node</a>, <a href="https://www.java.com/en/download/">java</a> and <a href="https://mochajs.org/">mocha</a> are installed (the last globally with <code>npm i -g mocha</code>). With those in place, installation is a one-liner:</p>
2<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"> <span class="kw">npm</span> install -g citeproc-test-runner</code></pre></div>
3<p>After installation, starting the program with <code>cslrun</code> will spit out instructions pointing back to this document. The remaining steps for setup are explained below. The instructions assume that you have a GitHub account (if you don't yet have an account, you should <a href="https://github.com">create a free account now</a>).</p>
4<h2 id="setting-up">Setting up</h2>
5<p>CTR can build tests for individual styles, using items from a shared public library. This allows style maintainers to quickly confirm that changes subsequently made to the style do not have unwanted side effects.</p>
6<p>Tests are identified to a style using its <em>slug name</em>, which is the last portion of the style's CSL <code>id</code> string. For example, the slug name of the style <code>http://www.zotero.org/styles/cell</code> is <code>cell</code>.</p>
7<p>Tests are written into and run from a local <em>style tests directory</em>. To facilitate the sharing of tests among maintainers, this directory should be a clone of <em>your personal fork</em> of the <a href="https://github.com/Juris-M/jm-style-tests">jm-style-tests</a> repository on GitHub:</p>
8<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"> <span class="kw">&lt;visit</span> https://github.com/Juris-M/jm-style-tests and fork the repository<span class="kw">&gt;</span>
9 <span class="kw">git</span> clone https://github.com/my-github-name/jm-style-tests.git</code></pre></div>
10<p>After cloning your fork of the tests repository, set the path to it in the CTR configuration file, located in the user home directory <code>~/.cslrun.yaml</code>:</p>
11<div class="sourceCode"><pre class="sourceCode yaml"><code class="sourceCode yaml"><span class="fu">groupID:</span> 2319948
12<span class="fu">path:</span>
13 <span class="fu">styletests:</span> /path/to/jm-style-tests
14 <span class="fu">local:</span> false
15 <span class="fu">std:</span> false
16 <span class="fu">src:</span> false
17 <span class="fu">locale:</span> false
18 <span class="fu">modules:</span> false
19 <span class="fu">cslschema:</span> false
20 <span class="fu">cslmschema:</span> false</code></pre></div>
21<p>By default, CTR builds tests from <a href="https://www.zotero.org/groups/2319948/jurism_style_test_items?">Jurism Style Test Items</a>, a public group library (to use a different source library, set its <code>id</code> as the <code>groupID</code> value in <code>~/.cslrun.yaml</code>). To make items available for a given style, join the group and create a top-level collection with its slug name, and add some items to the collection. It is helpful to write a short description of the item to be tests (i.e. within 30 characters or so) into the Abstract field.</p>
22<p>To build tests, use <code>cslrun</code> with the <code>-w</code> option to set the style to be tested, and the <code>-U</code> option to update test fixtures from the group library:</p>
23<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"> <span class="kw">cslrun</span> -w /path/to/cell.csl -U</code></pre></div>
24<p>This will write test fixtures to a subdirectory of the style tests directory, named for the slug name of the style (if the subdirectory does not exist, it will be created). Finish the tests by using <code>cslrun</code> with the <code>a</code> option to run all tests, and the <code>-k</code> option to confirm output:</p>
25<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"> <span class="kw">cslrun</span> -w /path/to/cell.csl -a -k</code></pre></div>
26<p>With the <code>-k</code> option, <code>cslrun</code> will show the style output as a failed test, prompting for confirmation that the output is correct. If <code>Y</code> is selected for each failing fixture, all tests will pass. Use <code>ctrl-c</code> to exit <code>cslrun</code> and return to the command line.</p>
27<p>To share the tests. check them in and push them to your <code>jm-style-tests</code> repository on GitHub:</p>
28<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"> <span class="kw">cd</span> /path/to/jm-style-tests
29 <span class="kw">git</span> commit -m <span class="st">&quot;Add tests for cell&quot;</span> -a
30 <span class="kw">git</span> push</code></pre></div>
31<p>Then jump to GitHub and file a pull request to the main <code>jm-style-tests</code> project to have your tests added to the suite.</p>
32<p>That's pretty much it. You can rerun the tests against the style anytime. If the <code>-k</code> option is omitted, <code>cslrun</code> will simply watch the CSL file, revalidating it and rerunning all tests whenever it is saved, to convert any plain text editor into a poorman's CSL IDE:</p>
33<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"> <span class="kw">cslrun</span> -w /path/to/cell.csl -a</code></pre></div>
34<p>A few other options are available on CTR. See <code>cslrun -h</code> for further details.</p>
35<p>Enjoy!</p>
36<p>FB</p>