Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fnmatch not implemented? #2002

Closed
TV4Fun opened this issue Jan 13, 2014 · 3 comments
Closed

fnmatch not implemented? #2002

TV4Fun opened this issue Jan 13, 2014 · 3 comments

Comments

@TV4Fun
Copy link
Contributor

TV4Fun commented Jan 13, 2014

Though it includes a header for it, emscripten seems to produce an error when trying to run code using fnmatch. On incoming branch using nodejs interpreter, LLVM 3.2. A simple test program:

include <iostream>

include <fnmatch.h>

using namespace std;

int main()
{
cout << fnmatch("*", ".", 0);
return 0;
}

works fine compiled with g++. Compiling with em++ produces warning: unresolved symbol: fnmatch, when run produces:
exception thrown: ReferenceError: _fnmatch is not defined,ReferenceError: _fnmatch is not defined
at Object._main (/home/joel/ogre-llvm/a.out.js:6250:2)
at Object.callMain (/home/joel/ogre-llvm/a.out.js:55247:30)
at doRun (/home/joel/ogre-llvm/a.out.js:55286:25)
at run (/home/joel/ogre-llvm/a.out.js:55299:5)
at Object.<anonymous> (/home/joel/ogre-llvm/a.out.js:55342:1)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)

/home/joel/ogre-llvm/a.out.js:55264
throw e;
^
ReferenceError: _fnmatch is not defined
at Object._main (/home/joel/ogre-llvm/a.out.js:6250:2)
at Object.callMain (/home/joel/ogre-llvm/a.out.js:55247:30)
at doRun (/home/joel/ogre-llvm/a.out.js:55286:25)
at run (/home/joel/ogre-llvm/a.out.js:55299:5)
at Object.<anonymous> (/home/joel/ogre-llvm/a.out.js:55342:1)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)

@kripken
Copy link
Member

kripken commented Jan 14, 2014

Looks like a missing libc function. Can you perhaps make a slightly less trivial testcase, and I'll add this in and test against that? (want to make sure we test actual functionality before merging)

@TV4Fun
Copy link
Contributor Author

TV4Fun commented Jan 15, 2014

Certainly try this:

// Begin test_fnmatch.cpp
#include <fnmatch.h>
#include <iostream>
#include <vector>
#include <string>

using namespace std;

class TestCase {
public:
    TestCase(const string& pattern, const string& testString, int flags, int expected) :
        pattern(pattern),
        testString(testString),
        flags(flags),
        expected(expected)
    {}
    string pattern;
    string testString;
    int flags;
    int expected;
};

int main()
{
    vector<TestCase> testCases;

    testCases.push_back(TestCase("*","anything",0,0));
    testCases.push_back(TestCase("*.txt","readme.txt",0,0));
    testCases.push_back(TestCase("*.txt","readme.info",0,FNM_NOMATCH));
    testCases.push_back(TestCase("*.t?t","readme.txt",0,0));
    testCases.push_back(TestCase("*.t?t","readme.tot",0,0));
    testCases.push_back(TestCase("*.t?t","readme.txxt",0,FNM_NOMATCH));
    testCases.push_back(TestCase("[a-g]1","c1",0,0));
    testCases.push_back(TestCase("[a-g]1","i1",0,FNM_NOMATCH));
    testCases.push_back(TestCase("[!a-g]1","i1",0,0));
    testCases.push_back(TestCase("a\\*","anything",0,FNM_NOMATCH));
    testCases.push_back(TestCase("a\\*","a*",0,0));
    testCases.push_back(TestCase("a\\*","a*",FNM_NOESCAPE,FNM_NOMATCH));
    testCases.push_back(TestCase("a\\*","a\\*",FNM_NOESCAPE,0));
    testCases.push_back(TestCase("*readme","/etc/readme",0,0));
    testCases.push_back(TestCase("*readme","/etc/readme",FNM_PATHNAME,FNM_NOMATCH));
    testCases.push_back(TestCase("/*/readme","/etc/readme",FNM_PATHNAME,0));
    testCases.push_back(TestCase("*readme","/etc/.readme",0,0));
    testCases.push_back(TestCase("*readme",".readme",FNM_PERIOD,FNM_NOMATCH));
    testCases.push_back(TestCase("*.readme","/etc/.readme",FNM_PERIOD,0));
    testCases.push_back(TestCase("*.readme","/etc/.readme",FNM_PERIOD|FNM_PATHNAME,FNM_NOMATCH));
    testCases.push_back(TestCase("/*/.readme","/etc/.readme",FNM_PERIOD|FNM_PATHNAME,0));
    testCases.push_back(TestCase("ReAdME","readme",0,FNM_NOMATCH));
    testCases.push_back(TestCase("ReAdME","readme",FNM_CASEFOLD,0));

    bool pass = true;

    for (vector<TestCase>::const_iterator it = testCases.begin(); it != testCases.end(); ++it)
    {
        int result = fnmatch(it->pattern.c_str(), it->testString.c_str(), it->flags);
        if (result == it->expected)
            cout << "Pass: ";
        else
        {
            cout << "Fail: ";
            pass = false;
        }

        cout << "fnmatch(" << it->pattern << ", " << it->testString << ", "
             << it->flags << ") returned " << result << ", expected "
             << it->expected << endl;
    }

    if (pass)
    {
        cout << "All tests passed." << endl;
        return 0;
    }
    else
    {
        cout << "Some tests failed." << endl;
        return 1;
    }
}

kripken added a commit that referenced this issue Jan 16, 2014
@kripken
Copy link
Member

kripken commented Jan 16, 2014

Thanks, nice testcase!

Pushed to incoming. Note that I had to remove one of your cases, using FNM_CASEFOLD, because looks like it is not supported yet in the musl libc which is what we use.

@kripken kripken closed this as completed Jan 16, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants