|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "markdown", |
| 5 | + "metadata": {}, |
| 6 | + "source": [ |
| 7 | + "Checking Projects with testthat\n", |
| 8 | + "-----------------------------\n", |
| 9 | + "\n", |
| 10 | + "In this notebook, a testthat reporter sends test output to the jupyter client.\n", |
| 11 | + "To see this in action, paste this javascript into your console:\n", |
| 12 | + "\n", |
| 13 | + "```\n", |
| 14 | + "Jupyter.notebook.kernel.comm_manager.register_target('dc_project',\n", |
| 15 | + " function(comm, msg) {\n", |
| 16 | + " // comm is the frontend comm instance\n", |
| 17 | + " // msg is the comm_open message, which can carry data\n", |
| 18 | + "\n", |
| 19 | + " // Register handlers for later messages:\n", |
| 20 | + " comm.on_msg(function(msg) { console.log('msg:', msg)} );\n", |
| 21 | + " comm.on_close(function(msg) { console.log('close msg:', msg)});\n", |
| 22 | + " //comm.send({'foo': 0});\n", |
| 23 | + " })\n", |
| 24 | + "```" |
| 25 | + ] |
| 26 | + }, |
| 27 | + { |
| 28 | + "cell_type": "code", |
| 29 | + "execution_count": null, |
| 30 | + "metadata": {}, |
| 31 | + "outputs": [], |
| 32 | + "source": [ |
| 33 | + "# TODO: load testthat funcs into an envir, or make parent?\n", |
| 34 | + "library(testthat)\n", |
| 35 | + "IRkernel.testthat::run_tests({\n", |
| 36 | + " test_that(\"a passing test\", {\n", |
| 37 | + " expect_equal(2, 2)\n", |
| 38 | + " expect_equal(3, 3)\n", |
| 39 | + " })\n", |
| 40 | + "\n", |
| 41 | + " test_that(\"a failing test\", {\n", |
| 42 | + " expect_equal(2, 3)\n", |
| 43 | + " expect_equal(3, 4)\n", |
| 44 | + " })\n", |
| 45 | + " \n", |
| 46 | + " test_that(\"an erroring test\", {\n", |
| 47 | + " stopifnot(FALSE)\n", |
| 48 | + " expect_equat(2, 2)\n", |
| 49 | + " })\n", |
| 50 | + "})" |
| 51 | + ] |
| 52 | + } |
| 53 | + ], |
| 54 | + "metadata": { |
| 55 | + "kernelspec": { |
| 56 | + "display_name": "R", |
| 57 | + "language": "R", |
| 58 | + "name": "ir" |
| 59 | + }, |
| 60 | + "language_info": { |
| 61 | + "codemirror_mode": "r", |
| 62 | + "file_extension": ".r", |
| 63 | + "mimetype": "text/x-r-source", |
| 64 | + "name": "R", |
| 65 | + "pygments_lexer": "r", |
| 66 | + "version": "3.3.1" |
| 67 | + } |
| 68 | + }, |
| 69 | + "nbformat": 4, |
| 70 | + "nbformat_minor": 2 |
| 71 | +} |
0 commit comments