diff options
author | Dan Gohman <sunfish@mozilla.com> | 2014-05-07 16:28:52 -0700 |
---|---|---|
committer | Dan Gohman <sunfish@mozilla.com> | 2014-05-07 16:36:57 -0700 |
commit | 42357af40b707c282d00f335bee1e87aab505a1e (patch) | |
tree | 82fd4e3dd088e7ac28758c16a8af765c911531c2 | |
parent | 490a4b27d1f8a93f09d44dc725e6042dcd7bd635 (diff) |
Add the testcase for https://github.com/kripken/emscripten/issues/2334 to the testsuite.
-rw-r--r-- | tests/fs/test_writeFile.cc | 43 | ||||
-rw-r--r-- | tests/fs/test_writeFile.out | 3 | ||||
-rw-r--r-- | tests/test_core.py | 6 |
3 files changed, 52 insertions, 0 deletions
diff --git a/tests/fs/test_writeFile.cc b/tests/fs/test_writeFile.cc new file mode 100644 index 00000000..31466b8e --- /dev/null +++ b/tests/fs/test_writeFile.cc @@ -0,0 +1,43 @@ +// https://github.com/kripken/emscripten/issues/2334 + +#include <fstream> +#include <iostream> +#include <string> + +#include <emscripten/emscripten.h> + +int main() +{ + EM_ASM( + FS.writeFile("testfile", "a=1\nb=2\nc=3"); + ); + + std::ifstream file("testfile"); + + while(!file.eof() && !file.fail()) + { + std::string line; + getline(file, line); + std::string name; + + std::cout << "read " << line << std::endl; + + size_t equalsPos = 1; + + size_t notSpace = line.find_first_not_of(" \t", equalsPos); + + if(notSpace != std::string::npos && notSpace != equalsPos) + { + line.erase(std::remove_if(line.begin(), line.begin() + notSpace, isspace), line.end()); + + equalsPos = line.find('='); + } + + if(equalsPos == std::string::npos) + continue; + + name = line.substr(0, equalsPos); + } + + return 0; +} diff --git a/tests/fs/test_writeFile.out b/tests/fs/test_writeFile.out new file mode 100644 index 00000000..16e520be --- /dev/null +++ b/tests/fs/test_writeFile.out @@ -0,0 +1,3 @@ +read a=1 +read b=2 +read c=3 diff --git a/tests/test_core.py b/tests/test_core.py index cf2730d0..76d3415c 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -4259,6 +4259,12 @@ def process(filename): out = path_from_root('tests', 'fs', 'test_trackingdelegate.out') self.do_run_from_file(src, out) + def test_fs_writeFile(self): + self.emcc_args += ['-s', 'DISABLE_EXCEPTION_CATCHING=1'] + src = path_from_root('tests', 'fs', 'test_writeFile.cc') + out = path_from_root('tests', 'fs', 'test_writeFile.out') + self.do_run_from_file(src, out) + def test_unistd_access(self): self.clear() if not self.is_emscripten_abi(): return self.skip('asmjs-unknown-emscripten needed for inline js') |