aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorRyan Kelly <ryan@rfk.id.au>2014-02-25 17:15:58 +1100
committerRyan Kelly <ryan@rfk.id.au>2014-02-26 15:32:44 +1100
commitfee89ee4a91f0d1eed465ca785b5353f02913ab4 (patch)
tree48574e32a8f164530db45b32b3e3365e48050e67 /tests
parent80de5f33b5f3ce2b7d938b2f1a1909c1cca81733 (diff)
Ensure that fileno() returns -1 when given an invalid file pointer.
Diffstat (limited to 'tests')
-rw-r--r--tests/test_core.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/tests/test_core.py b/tests/test_core.py
index 19bb9ca1..c40d73f4 100644
--- a/tests/test_core.py
+++ b/tests/test_core.py
@@ -4058,6 +4058,28 @@ def process(filename):
self.emcc_args += ['--embed-file', 'three_numbers.txt']
self.do_run(src, 'match = 3\nx = -1.0, y = 0.1, z = -0.1\n')
+ def test_fileno(self):
+ if self.emcc_args is None: return self.skip('requires emcc')
+ open(os.path.join(self.get_dir(), 'empty.txt'), 'w').write('')
+ src = r'''
+ #include <stdio.h>
+ #include <unistd.h>
+ int main()
+ {
+ FILE* fp = fopen("empty.txt", "r");
+ if (fp) {
+ printf("%d\n", fp);
+ printf("%d\n", fileno(fp));
+ printf("%d\n", fileno((FILE*)42)); // nonexistent stream
+ } else {
+ printf("failed to open empty.txt\n");
+ }
+ return 0;
+ }
+ '''
+ self.emcc_args += ['--embed-file', 'empty.txt']
+ self.do_run(src, '4\n3\n-1\n')
+
def test_readdir(self):
src = open(path_from_root('tests', 'dirent', 'test_readdir.c'), 'r').read()
self.do_run(src, 'success', force_c=True)