commit ccbb5aae01605da2d13f090ce0b73456838e4a9f
parent 792df590410d3a8aa39b9ec4f4a69eaa4036409c
Author: Thomas Frössman <thomasf@jossystem.se>
Date: Wed, 12 Mar 2014 20:12:29 +0100
add tests/
Diffstat:
18 files changed, 534 insertions(+), 0 deletions(-)
diff --git a/tests/.gitignore b/tests/.gitignore
@@ -0,0 +1,2 @@
+elpa/
+screenshots/
+\ No newline at end of file
diff --git a/tests/README.org b/tests/README.org
@@ -0,0 +1,5 @@
+* What is this?
+At the moment early sketches that might become something.
+
+The idea is to automate screenshooting to allow reviewing theme changes more
+quickly.
diff --git a/tests/emacs-visual-test.el b/tests/emacs-visual-test.el
@@ -0,0 +1,46 @@
+;;; emacs-visual-test.el ---
+
+;;; Commentary:
+;;
+
+(load-file "init.el")
+(require 's)
+(require 'dash)
+(require 'f)
+
+(defconst screenshots-directory
+ (f-expand "screenshots" tests-directory))
+
+(defun visual-test-find-file (name)
+ (find-file (expand-file-name name "test-files")))
+
+(defun visual-test-screenshot ()
+ (call-process "scrot" nil nil nil "-u"
+ (f-expand "screenshot-%Y-%m-%d_%H-%M-%S_$wx$h.png"
+ screenshots-directory))
+ (message "saved screenshot"))
+
+;; set theme
+(load-theme 'solarized-dark t)
+;; open a file
+(visual-test-find-file "django-template.html")
+;; enable web-mode
+(web-mode)
+;; go to some position
+(goto-char 27)
+;; Prepare taking a screenshot
+(run-with-idle-timer 2 nil
+ '(lambda ()
+ (visual-test-screenshot)
+ ;; (keyboard-quit)
+ (kill-buffer)
+ (kill-emacs)
+ ))
+
+;; open ispell-complete word interaction
+(call-interactively 'ispell-complete-word)
+
+
+(provide 'emacs-visual-test)
+
+;;; emacs-visual-test.el ends here
diff --git a/tests/emacs-visual-test.sh b/tests/emacs-visual-test.sh
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+emacs -q -l emacs-visual-test.el
diff --git a/tests/init.el b/tests/init.el
@@ -0,0 +1,57 @@
+(defconst tests-directory
+ (if load-file-name
+ (file-name-directory load-file-name)
+ default-directory))
+
+(setq
+ package-user-dir (expand-file-name "elpa" tests-directory)
+ inhibit-startup-message t
+ inhibit-splash-screen t
+ inhibit-startup-buffer-menu t
+ inhibit-startup-echo-area-message t
+ initial-scratch-message ";;_
+;; __ _,******
+;; ,------, _ _,**
+;; | Moo! | _ ____,****
+;; ;------; _
+;; \\ ^__^
+;; \\ (^^)\\_______
+;; ^-(..)\\ )\\/\\/^_^
+;; ||----w |
+;; __.-''*-,.,____||_____||___,_.-
+;; '' ''
+
+")
+
+(require 'package)
+(add-to-list 'package-archives
+ '("melpa" . "http://melpa.milkbox.net/packages/") t)
+
+(when (< emacs-major-version 24)
+ (add-to-list 'package-archives '("gnu" . "http://elpa.gnu.org/packages/")))
+
+(package-initialize)
+
+(let ((deps '(web-mode
+ js2-mode
+ haskell-mode
+ undo-tree
+ dash
+ s
+ f))
+ (refreshed nil))
+ (dolist (pkg deps)
+ (when (not (package-installed-p pkg))
+ (when (not refreshed)
+ (package-refresh-contents)
+ (setq refreshed t))
+ (package-install pkg))))
+
+(defconst solarized-directory
+ (expand-file-name "../" tests-directory))
+(setq load-path (cons solarized-directory load-path))
+(if (boundp 'custom-theme-load-path)
+ (add-to-list 'custom-theme-load-path solarized-directory))
+
+(tool-bar-mode -1)
+(menu-bar-mode -1)
diff --git a/tests/test-files/c.c b/tests/test-files/c.c
@@ -0,0 +1,26 @@
+#define UNICODE
+#include <windows.h>
+
+int main(int argc, char **argv) {
+ int speed = 0, speed1 = 0, speed2 = 0; // 1-20
+ printf("Set Mouse Speed by Maverick\n");
+
+ SystemParametersInfo(SPI_GETMOUSESPEED, 0, &speed, 0);
+ printf("Current speed: %2d\n", speed);
+
+ if (argc == 1) return 0;
+ if (argc >= 2) sscanf(argv[1], "%d", &speed1);
+ if (argc >= 3) sscanf(argv[2], "%d", &speed2);
+
+ if (argc == 2) // set speed to first value
+ speed = speed1;
+ else if (speed == speed1 || speed == speed2) // alternate
+ speed = speed1 + speed2 - speed;
+ else
+ speed = speed1; // start with first value
+
+ SystemParametersInfo(SPI_SETMOUSESPEED, 0, speed, 0);
+ SystemParametersInfo(SPI_GETMOUSESPEED, 0, &speed, 0);
+ printf("New speed: %2d\n", speed);
+ return 0;
+}
diff --git a/tests/test-files/django-template.html b/tests/test-files/django-template.html
@@ -0,0 +1,39 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <link rel="stylesheet" href="style.css" />
+ <title>{% block title %}My amazing site{% endblock %}</title>
+</head>
+
+<body>
+ <div id="sidebar">
+ {% block sidebar %}
+ <ul>
+ <li><a href="/">Home</a></li>
+ <li><a href="/blog/">Blog</a></li>
+ </ul>
+ {% endblock %}
+ </div>
+
+ <div id="content">
+ {% block content %}{% endblock %}
+ </div>
+</body>
+</html>
+
+{% extends "base_generic.html" %}
+
+{% block title %}{{ section.title }}{% endblock %}
+
+{% block content %}
+<h1>{{ section.title }}</h1>
+
+{% for story in story_list %}
+<h2>
+ <a href="{{ story.get_absolute_url }}">
+ {{ story.headline|upper }}
+ </a>
+</h2>
+<p>{{ story.tease|truncatewords:"100" }}</p>
+{% endfor %}
+{% endblock %}
+\ No newline at end of file
diff --git a/tests/test-files/haskell.hs b/tests/test-files/haskell.hs
@@ -0,0 +1,40 @@
+{-# LANGUAGE OverloadedStrings #-}
+module Main where
+
+--import Prelude hiding (id)
+--import Control.Category (id)
+import Control.Arrow ((>>>), (***), arr)
+import Control.Monad (forM_)
+-- import Data.Monoid (mempty, mconcat)
+
+-- import System.FilePath
+
+import Hakyll
+
+
+main :: IO ()
+main = hakyll $ do
+
+ route "css/*" $ setExtension "css"
+ compile "css/*" $ byExtension (error "Not a (S)CSS file")
+ [ (".css", compressCssCompiler)
+ , (".scss", sass)
+ ]
+
+ route "js/**" idRoute
+ compile "js/**" copyFileCompiler
+
+ route "img/*" idRoute
+ compile "img/*" copyFileCompiler
+
+ compile "templates/*" templateCompiler
+
+ forM_ ["test.md", "index.md"] $ \page -> do
+ route page $ setExtension "html"
+ compile page $ pageCompiler
+ >>> applyTemplateCompiler "templates/default.html"
+ >>> relativizeUrlsCompiler
+
+sass :: Compiler Resource String
+sass = getResourceString >>> unixFilter "sass" ["-s", "--scss"]
+ >>> arr compressCss
diff --git a/tests/test-files/html.html b/tests/test-files/html.html
@@ -0,0 +1,21 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html><head>
+<title>A Tiny Page</title>
+<style type="text/css">
+<!--
+ p { font-size:15pt; color:#000 }
+ -->
+</style></head><!-- real comment -->
+<body bgcolor="#FFFFFF" text="#000000" link="#0000CC">
+<script language="javascript" type="text/javascript">
+ function changeHeight(h) {
+ var tds = document.getElementsByTagName("td");
+ for(var i = 0; i < tds.length; i++) {
+ tds[i].setAttribute("height", h + "px");
+ }}
+</script>
+<h1>abc</h1>
+<h2>def</h2>
+<p>Testing page</p>
+</body></html>
+
diff --git a/tests/test-files/java.java b/tests/test-files/java.java
@@ -0,0 +1,16 @@
+import java.util.Map;
+import java.util.TreeSet;
+
+public class GetEnv {
+ /**
+ * let's test generics
+ * @param args the command line arguments
+ */
+ public static void main(String[] args) {
+ // get a map of environment variables
+ Map<String, String> env = System.getenv();
+ // build a sorted set out of the keys and iterate
+ for(String k: new TreeSet<String>(env.keySet())) {
+ System.out.printf("%s = %s\n", k, env.get(k));
+ }
+ } }
diff --git a/tests/test-files/javascript.js b/tests/test-files/javascript.js
@@ -0,0 +1,20 @@
+/**
+sample javascript from xui
+*/
+
+var undefined,
+ xui,
+ window = this,
+ string = new String('string'),
+ document = window.document,
+ simpleExpr = /^#?([\w-]+)$/,
+ idExpr = /^#/,
+ tagExpr = /<([\w:]+)/,
+ slice = function (e) { return [].slice.call(e, 0); };
+ try { var a = slice(document.documentElement.childNodes)[0].nodeType; }
+ catch(e){ slice = function (e) { var ret=[]; for (var i=0; e[i]; i++)
+ ret.push(e[i]); return ret; }; }
+
+window.x$ = window.xui = xui = function(q, context) {
+ return new xui.fn.find(q, context);
+};
diff --git a/tests/test-files/pandoc.md b/tests/test-files/pandoc.md
@@ -0,0 +1,26 @@
+% Pandoc Test File
+% Ethan Schoonover
+% March 22, 2011
+
+%% format: markdown+lhs
+
+> import Hakyll
+> main :: IO ()
+> main = hakyll $ do
+> compile "css/*" $ byExtension (error "Not a (S)CSS file")
+
+Using *Pandoc*
+=============
+
+In this document the technical terms `water` and `ice` will be replaced by
+H~2~O.^[a contrived footnote]
+
+## Heading styles can be mixed
+
+And matched, and they still fold **properly**
+
+* * * *
+
+Some code:
+
+ a verbatim or "code" block
diff --git a/tests/test-files/perl.pl b/tests/test-files/perl.pl
@@ -0,0 +1,33 @@
+#!perl -w
+
+# Time-stamp: <2002/04/06, 13:12:13 (EST), maverick, csvformat.pl>
+# Two pass CSV file to table formatter
+
+$delim = $#ARGV >= 1 ? $ARGV[1] : ',';
+print STDERR "Split pattern: $delim\n";
+
+# first pass
+open F, "<$ARGV[0]" or die;
+while(<F>)
+{
+ chomp;
+ $i = 0;
+ map { $max[$_->[1]] = $_->[0] if $_->[0] > ($max[$_->[1]] || 0) }
+ (map {[length $_, $i++]} split($delim));
+}
+close F;
+
+print STDERR 'Field width: ', join(', ', @max), "\n";
+print STDERR join(' ', map {'-' x $_} @max);
+
+# second pass
+open F, "<$ARGV[0]" or die;
+while(<F>)
+ {
+ chomp;
+ $i = 0;
+ map { printf("%-$max[$_->[1]]s ", $_->[0]) }
+ (map {[$_, $i++]} split($delim));
+ print "\n";
+}
+close F;
diff --git a/tests/test-files/php.php b/tests/test-files/php.php
@@ -0,0 +1,29 @@
+<?php
+require_once($GLOBALS['g_campsiteDir']. "/$ADMIN_DIR/country/common.php");
+require_once($GLOBALS['g_campsiteDir']. "/classes/SimplePager.php");
+camp_load_translation_strings("api");
+
+$f_country_language_selected = camp_session_get('f_language_selected', '');
+$f_country_offset = camp_session_get('f_country_offset', 0);
+if (empty($f_country_language_selected)) {
+ $f_country_language_selected = null;
+}
+$ItemsPerPage = 20;
+$languages = Language::GetLanguages(null, null, null, array(), array(), true);
+$numCountries = Country::GetNumCountries($f_country_language_selected);
+
+$pager = new SimplePager($numCountries, $ItemsPerPage, "index.php?");
+
+$crumbs = array();
+$crumbs[] = array(getGS("Configure"), "");
+$crumbs[] = array(getGS("Countries"), "");
+echo camp_html_breadcrumbs($crumbs);
+
+?>
+
+<?php if ($g_user->hasPermission("ManageCountries")) { ?>
+<table BORDER="0" CELLSPACING="0" CELLPADDING="1">
+ <tr>
+ <td><a href="add.php"><?php putGS("Add new"); ?></a></td>
+ </tr>
+</table>
diff --git a/tests/test-files/python.py b/tests/test-files/python.py
@@ -0,0 +1,67 @@
+# test python (sample from offlineimap)
+
+class ExitNotifyThread(Thread):
+ """This class is designed to alert a "monitor" to the fact that a thread has
+ exited and to provide for the ability for it to find out why."""
+ def run(self):
+ global exitthreads, profiledir
+ self.threadid = thread.get_ident()
+ try:
+ if not profiledir: # normal case
+ Thread.run(self)
+ else:
+ try:
+ import cProfile as profile
+ except ImportError:
+ import profile
+ prof = profile.Profile()
+ try:
+ prof = prof.runctx("Thread.run(self)", globals(), locals())
+ except SystemExit:
+ pass
+ prof.dump_stats( \
+ profiledir + "/" + str(self.threadid) + "_" + \
+ self.getName() + ".prof")
+ except:
+ self.setExitCause('EXCEPTION')
+ if sys:
+ self.setExitException(sys.exc_info()[1])
+ tb = traceback.format_exc()
+ self.setExitStackTrace(tb)
+ else:
+ self.setExitCause('NORMAL')
+ if not hasattr(self, 'exitmessage'):
+ self.setExitMessage(None)
+
+ if exitthreads:
+ exitthreads.put(self, True)
+
+ def setExitCause(self, cause):
+ self.exitcause = cause
+ def getExitCause(self):
+ """Returns the cause of the exit, one of:
+ 'EXCEPTION' -- the thread aborted because of an exception
+ 'NORMAL' -- normal termination."""
+ return self.exitcause
+ def setExitException(self, exc):
+ self.exitexception = exc
+ def getExitException(self):
+ """If getExitCause() is 'EXCEPTION', holds the value from
+ sys.exc_info()[1] for this exception."""
+ return self.exitexception
+ def setExitStackTrace(self, st):
+ self.exitstacktrace = st
+ def getExitStackTrace(self):
+ """If getExitCause() is 'EXCEPTION', returns a string representing
+ the stack trace for this exception."""
+ return self.exitstacktrace
+ def setExitMessage(self, msg):
+ """Sets the exit message to be fetched by a subsequent call to
+ getExitMessage. This message may be any object or type except
+ None."""
+ self.exitmessage = msg
+ def getExitMessage(self):
+ """For any exit cause, returns the message previously set by
+ a call to setExitMessage(), or None if there was no such message
+ set."""
+ return self.exitmessage
diff --git a/tests/test-files/ruby.rb b/tests/test-files/ruby.rb
@@ -0,0 +1,49 @@
+# ruby test file ruby.rb
+
+include Enumerable
+
+def initialize(rbconfig)
+@rbconfig = rbconfig
+@no_harm = false
+end
+
+def load_savefile
+begin
+ File.foreach(savefile()) do |line|
+ k, v = *line.split(/=/, 2)
+ self[k] = v.strip
+ end
+rescue Errno::ENOENT
+ setup_rb_error $!.message + "\n#{File.basename($0)} config first"
+end
+end
+
+if c['rubylibdir']
+ # V > 1.6.3
+ libruby = "#{c['prefix']}/lib/ruby"
+ siterubyverarch = c['sitearchdir']
+end
+parameterize = lambda {|path|
+ path.sub(/\A#{Regexp.quote(c['prefix'])}/, '$prefix')
+}
+
+if arg = c['configure_args'].split.detect {|arg| /--with-make-prog=/ =~ arg }
+ makeprog = arg.sub(/'/, '').split(/=/, 2)[1]
+else
+ makeprog = 'make'
+end
+
+def setup_rb_error(msg)
+ raise SetupError, msg
+end
+
+if $0 == __FILE__
+ begin
+ ToplevelInstaller.invoke
+ rescue SetupError
+ raise if $DEBUG
+ $stderr.puts $!.message
+ $stderr.puts "Try 'ruby #{$0} --help' for detailed usage."
+ exit 1
+ end
+end
diff --git a/tests/test-files/shell.sh b/tests/test-files/shell.sh
@@ -0,0 +1,29 @@
+#!/bin/bash
+
+cd $ROOT_DIR
+DOT_FILES="lastpass weechat ssh Xauthority"
+for dotfile in $DOT_FILES; do conform_link "$DATA_DIR/$dotfile" ".$dotfile"; done
+
+# }}}
+# crontab update from file {{{
+# TODO: refactor with suffix variables (or common cron values)
+
+case "$PLATFORM" in
+ linux)
+ #conform_link "$CONF_DIR/shell/zshenv" ".zshenv"
+ crontab -l > $ROOT_DIR/tmp/crontab-conflict-arch
+ cd $ROOT_DIR/$CONF_DIR/cron
+ if [[ "$(diff ~/tmp/crontab-conflict-arch crontab-current-arch)" == ""
+ ]];
+ then # no difference with current backup
+ logger "$LOG_PREFIX: crontab live settings match stored "\
+ "settings; no restore required"
+ rm ~/tmp/crontab-conflict-arch
+ else # current crontab settings in file do not match live settings
+ crontab $ROOT_DIR/$CONF_DIR/cron/crontab-current-arch
+ logger "$LOG_PREFIX: crontab stored settings conflict with "\
+ "live settings; stored settings restored. "\
+ "Previous settings recorded in ~/tmp/crontab-conflict-arch."
+ fi
+ ;;
+
diff --git a/tests/test-files/tex.tex b/tests/test-files/tex.tex
@@ -0,0 +1,24 @@
+% Time-stamp: <2004/04/06, 16:46:43 (EST), maverick, test.tex>
+\subsection{Strict diagonal-dominance}
+Suppose we are given a matrix $A=L+D$, where $L$ is a Laplacian and
+$D$ is a nonnegative diagonal matrix, for which we seek to construct a
+preconditioner.
+
+We may construct a Support Tree Preconditioner, $B =
+\begin{pmatrix} T & U\\U\TT & W\end{pmatrix}$ for $L$ and to use $B'
+=\begin{pmatrix} T & U \\U\TT & W+D\end{pmatrix}$ as a preconditioner
+for $A$. If we let $Q = W - U\TT T\IV U$, by Lemma~\ref{lem:stcg} it
+suffices to bound $\sigma(A/Q+D)$ and $\sigma(Q+D/A)$.
+
+\begin{proposition}\label{prop:XZ-YZ}
+If $X$, $Y$, and $Z$ are spsd matrices of the same size then
+$\sigma(X+Z/Y+Z) \leq \max\{\sigma(X/Y),\, 1\}$.
+\end{proposition}
+
+\Proof We have $\sigma(X+Z/Y+Z) =
+\min\{\tau \mid \forall\vv{x},\, \tau\cdot \vv{x}\TT (Y+Z)\vv{x} \geq
+ \vv{x}\TT(X+Z)\vv{x}\} =
+\min\{\tau \mid \forall\vv{x},\, (\tau-1)\cdot \vv{x}\TT Z\vv{x} +
+ \tau \cdot\vv{x}\TT Y\vv{x} \geq \vv{x}\TT X\vv{x}\} \leq
+\max\{1,\,\sigma(X/Y)\}$.\QED
+