Commits

Kirill Simonov  committed ceaebd3

Added regression tests.

  • Participants
  • Parent commits e03b874

Comments (0)

Files changed (4)

File cogs.local.py

+#
+# Copyright (c) 2013, Prometheus Research, LLC
+# Released under MIT license, see `LICENSE` for details.
+#
+
+
+from cogs import task, env
+from cogs.fs import exe
+
+
+@task
+def TEST():
+    """run regression tests"""
+    with env(debug=True):
+        exe("pbbt test/input.yaml test/output.yaml -q")
+
+
+@task
+def TRAIN():
+    """run regression tests in the train mode"""
+    with env(debug=True):
+        exe("pbbt test/input.yaml test/output.yaml --train")
+
+
+@task
+def PURGE_TEST():
+    """purge stale output records from regression tests"""
+    with env(debug=True):
+        exe("pbbt test/input.yaml test/output.yaml -q --train --purge")
+
+
+@task
+def LINT():
+    """detect errors in the source code with PyFlakes"""
+    with env(debug=True):
+        exe("pyflakes src/cogs")
+
+

File src/cogs/run.py

 
 
 from .core import Failure, Environment, env, _to_name
-from .log import log, warn, debug, fail
+from .log import warn, debug, fail
 import sys
 import types
 import os, os.path
 def run(argv):
 
     # Load standard tasks and settings.
-    from . import std
+    __import__('cogs.std')
 
     # Load extensions registered using the entry point.
     if env.shell.entry_point:

File test/input.yaml

+title: Regression tests for Cogs
+tests:
+
+- title: Hello World
+  tests:
+  - sh: cogs hello world
+    cd: &cd1 demo/01-hello
+  - sh: cogs hello
+    ignore: &ignore-hello |
+      Hello, (.*)!
+    cd: *cd1
+  - sh: cogs help hello
+    cd: *cd1
+
+- title: Extending Cogs
+  tests:
+  - sh: pip install -q -e .
+    cd: &cd2 demo/02-hello-extension
+  - sh: cogs hello world
+    cd: *cd2
+  - sh: cogs hello
+    ignore: *ignore-hello
+    cd: *cd2
+  - sh: cogs help hello
+    cd: *cd2
+  - sh: pip uninstall -q -y Cogs-Hello
+    cd: *cd2
+
+- title: Factorial & Fibonacci
+  tests:
+  - sh: cogs factorial 10
+    cd: &cd3 demo/03-factorial-fibonacci
+  - sh: cogs fibonacci 10
+    cd: *cd3
+  - sh: cogs help
+    cd: *cd3
+  - sh: cogs help factorial
+    cd: *cd3
+  - sh: cogs help fibonacci
+    cd: *cd3
+  - sh: cogs factorial ten
+    exit: 1
+    cd: *cd3
+  - sh: cogs factorial -- -10
+    exit: 1
+    cd: *cd3
+  - sh: cogs fibonacci ten
+    exit: 1
+    cd: *cd3
+  - sh: cogs fibonacci -- -10
+    exit: 1
+    cd: *cd3
+
+- title: Options
+  tests:
+  - sh: cogs write-hello
+    ignore: *ignore-hello
+    cd: &cd4 demo/04-write-hello
+  - sh: cogs write-hello -o ../../test/hello.txt
+    cd: *cd4
+  - read: test/hello.txt
+    ignore: *ignore-hello
+  - rm: test/hello.txt
+  - sh: cogs write-hello --output=../../test/hello.txt world
+    cd: *cd4
+  - read: test/hello.txt
+  - rm: test/hello.txt
+  - sh: cogs help write-hello
+    cd: *cd4
+

File test/output.yaml

+suite: regression-tests-for-cogs
+tests:
+- suite: hello-world
+  tests:
+  - sh: cogs hello world
+    stdout: |
+      Hello, World!
+  - sh: cogs hello
+    stdout: |
+      Hello, Xi!
+  - sh: cogs help hello
+    stdout: |+
+      HELLO - greet someone (if not specified, the current user)
+      Usage: cogs hello [<name>]
+
+- suite: extending-cogs
+  tests:
+  - sh: pip install -q -e .
+    stdout: ''
+  - sh: cogs hello world
+    stdout: |
+      Hello, World!
+  - sh: cogs hello
+    stdout: |
+      Hello, Xi!
+  - sh: cogs help hello
+    stdout: |+
+      HELLO - greet someone (if not specified, the current user)
+      Usage: cogs hello [<name>]
+
+  - sh: pip uninstall -q -y Cogs-Hello
+    stdout: ''
+- suite: factorial-fibonacci
+  tests:
+  - sh: cogs factorial 10
+    stdout: |
+      10! = 3628800
+  - sh: cogs fibonacci 10
+    stdout: |
+      F_10 = 55
+  - sh: cogs help
+    stdout: |+
+      Cogs - A task dispatching utility
+      Usage: cogs [<settings>...] <task> [<arguments>...]
+
+      Run cogs help for general usage and a list of tasks,
+      settings and other help topics.
+
+      Run cogs help <topic> for help on a specific topic.
+
+      Available tasks:
+        factorial <n>            : calculate n!
+        fibonacci <n>            : calculate the n-th Fibonacci number
+        help [<topic>]           : display help on tasks and settings
+
+      Settings:
+        --debug                  : print debug information
+
+  - sh: cogs help factorial
+    stdout: |+
+      FACTORIAL - calculate n!
+      Usage: cogs factorial <n>
+
+      This task calculates the value of the factorial of the given
+      positive number n.  Factorial of n, also known as n!, is
+      defined by the formula:
+
+          n! = 1*2*...*(n-1)*n
+
+  - sh: cogs help fibonacci
+    stdout: |+
+      FIBONACCI - calculate the n-th Fibonacci number
+      Usage: cogs fibonacci <n>
+
+      The n-th Fibonacci number F_n is defined by:
+
+          F_0 = 0
+          F_1 = 1
+          F_n = F_{n-1}+F_{n-2} (n>1)
+
+  - sh: cogs factorial ten
+    stdout: |+
+      FATAL ERROR: n must be an integer
+
+  - sh: cogs factorial -- -10
+    stdout: |+
+      FATAL ERROR: n must be positive
+
+  - sh: cogs fibonacci ten
+    stdout: |+
+      FATAL ERROR: invalid value for argument <n>: invalid literal for int() with base 10: 'ten'
+
+  - sh: cogs fibonacci -- -10
+    stdout: |+
+      FATAL ERROR: n must be non-negative
+
+- suite: options
+  tests:
+  - sh: cogs write-hello
+    stdout: |
+      Hello, Xi!
+  - sh: cogs write-hello -o ../../test/hello.txt
+    stdout: ''
+  - read: test/hello.txt
+    data: |
+      Hello, Xi!
+  - sh: cogs write-hello --output=../../test/hello.txt world
+    stdout: ''
+  - read: test/hello.txt
+    data: |
+      Hello, World!
+  - sh: cogs help write-hello
+    stdout: |+
+      WRITE-HELLO
+      Usage: cogs write-hello [<name>]
+
+      Options:
+        output
+