Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Use #!python to specify if an example must be run with the python pro…

…gram.

Not all of our examples will run successfully in CPython, as we will have some
code examples of how to use Ruby code from Python, and that will certainly dont
work on other Python implementations.

So now, every example explicitly specified which Python interpreters it must be
run with.
  • Loading branch information...
commit 1a72147bd3cf7deb03e892b1783c40f1ca8003ae 1 parent e5faf1a
Victor Hugo Borja authored
7 spec/examples/README.md
View
@@ -25,8 +25,11 @@ with two command line arguments, you should have the first line in the
Files not having that comment as first line will just be ignored.
Typhon is expected to be compatible as possible with the `python`
-program. Because of this all tests run with `typhon` will be also run
-with `python` and the output is expected to be equal.
+program. Because of this all tests run with `typhon` might also need
+to be run with `python` and the output is expected to be equal.
+
+ #! typhon examples/hello.py
+ #! python examples/hello.py
Also, some examples output memory locations like `0x0AF30` in that cases
.out files can use ruby regexes like: `#{/0x\w+/}`.
1  spec/examples/builtins.out
View
@@ -1,4 +1,5 @@
#! typhon examples/builtins.py
+#! python examples/builtins.py
__main__
wat
<type 'object'>
1  spec/examples/classes.out
View
@@ -1,2 +1,3 @@
#! typhon examples/classes.py
+#! python examples/classes.py
10
1  spec/examples/decorators.out
View
@@ -1,4 +1,5 @@
#! typhon examples/decorators.py
+#! python examples/decorators.py
1 2 3
<class '__main__.test'> 1 2 3
1 2 3
1  spec/examples/descriptors.out
View
@@ -1,4 +1,5 @@
#! typhon examples/descriptors.py
+#! python examples/descriptors.py
datadesc <__main__.DataDesc object at #{/0x\w+/}> None <class '__main__.test'>
desc <__main__.Desc object at #{/0x\w+/}> None <class '__main__.test'>
datadesc <__main__.DataDesc object at #{/0x\w+/}> <__main__.test object at #{/0x\w+/}> <class '__main__.test'>
1  spec/examples/embed_func.out
View
@@ -1,4 +1,5 @@
#! typhon examples/embed_func.py
+#! python examples/embed_func.py
zoom!
('floom', 'b')
boom
1  spec/examples/eval.out
View
@@ -1,2 +1,3 @@
#! typhon examples/eval.py
+#! python examples/eval.py
726
1  spec/examples/from_import.out
View
@@ -1,3 +1,4 @@
#! typhon examples/from_import.py
+#! python examples/from_import.py
imported
FOO
1  spec/examples/from_import_as.out
View
@@ -1,3 +1,4 @@
#! typhon examples/from_import_as.py
+#! python examples/from_import_as.py
imported
FOO
1  spec/examples/func.out
View
@@ -1,4 +1,5 @@
#! typhon examples/func.py
+#! python examples/func.py
---
hello Jack
wat: stuff
1  spec/examples/hello.out
View
@@ -1,2 +1,3 @@
#! typhon examples/hello.py
+#! python examples/hello.py
hello world
1  spec/examples/import.out
View
@@ -1,4 +1,5 @@
#! typhon examples/import.py
+#! python examples/import.py
imported
imported module
BAR
1  spec/examples/import_as.out
View
@@ -1,3 +1,4 @@
#! typhon examples/import_as.py
+#! python examples/import_as.py
imported
imported
1  spec/examples/literals.out
View
@@ -1 +1,2 @@
#! typhon examples/literals.py
+#! python examples/literals.py
1  spec/examples/numbers.out
View
@@ -1,4 +1,5 @@
#! typhon examples/numbers.py
+#! python examples/numbers.py
boom
<type 'int'> <type 'long'> <type 'int'>
11
1  spec/examples/pass.out
View
@@ -1,2 +1,3 @@
#! typhon examples/pass.py
+#! python examples/pass.py
None
1  spec/examples/singletons.out
View
@@ -1,4 +1,5 @@
#! typhon examples/singletons.py
+#! python examples/singletons.py
None
<type 'NoneType'>
NotImplemented
43 spec/examples_spec.rb
View
@@ -1,14 +1,18 @@
require 'open3'
+require 'strscan'
base = File.expand_path("..", File.dirname(__FILE__))
Dir.glob(File.expand_path("**/*.out", File.dirname(__FILE__))) do |file|
- content = File.read file
- m = /#!\s*typhon\s+(.*)$/.match(content)
- next unless m
- cmd = m[1]
- content = content.sub(/.*?\n/, '')
+ scanner = StringScanner.new(File.read file)
+ runner_re = /^#!\s*(typhon|python)\s+(.*)(\n|\r\n)/
+ runners = {}
+
+ runners[scanner[1]] = scanner[2] while scanner.scan runner_re
+ next if runners.empty?
+
+ content = scanner.rest
# Allow regexp literals inside the file content so we can match
# things like memory addresses or anything that can vary
@@ -19,26 +23,17 @@
expect = Regexp.new(Object.new.instance_eval content)
- describe "Example output of `typhon #{cmd}`" do
- it "should match content of #{file}" do
- stdio = nil
- Dir.chdir base do
- stdio = Open3.popen3("./bin/typhon #{cmd}")
+ runners.each do |program, cmd|
+ describe "Output of `#{program} #{cmd}`" do
+ it "should match content of #{file}" do
+ stdio = nil
+ program = "./bin/typhon" if program == "typhon"
+ Dir.chdir base do
+ stdio = Open3.popen3("#{program} #{cmd}")
+ end
+ output = stdio[1].read
+ output.should =~ expect
end
- output = stdio[1].read
- output.should =~ expect
end
end
-
- describe "Example output of `python #{cmd}`" do
- it "should match content of #{file}" do
- stdio = nil
- Dir.chdir base do
- stdio = Open3.popen3("python #{cmd}")
- end
- output = stdio[1].read
- output.should =~ expect
- end
- end
-
end
Please sign in to comment.
Something went wrong with that request. Please try again.