Commit 75bdbab2 authored by jan.koester's avatar jan.koester
Browse files

test

parent ce0b9e77
Loading
Loading
Loading
Loading
+16 −2
Changes for src/shell.cpp: 16 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -3713,6 +3713,13 @@ int fresh::Shell::parse(const std::string &input,bool applyErrexit){
    size_t e=input.find_last_not_of(" \t\r\n");
    std::string trimmed=input.substr(s,e-s+1);

    // a condition (applyErrexit false) exempts everything it runs
    struct NoErrexitScope {
        int &depth; bool on;
        NoErrexitScope(int &d,bool o):depth(d),on(o){ if(on) ++depth; }
        ~NoErrexitScope(){ if(on) --depth; }
    } noErrexitScope(_noErrexit,!applyErrexit);

    std::vector<ShellWord> words=tokenizeShellWords(trimmed);
    if(words.empty())
        return _exitCode;
@@ -3846,7 +3853,11 @@ int fresh::Shell::parse(const std::string &input,bool applyErrexit){
                shouldRun=(_exitCode!=0);

            if(shouldRun){
                {
                    bool exempt=(w=="&&" || w=="||" || (segstart<i && words[segstart].text=="!"));
                    NoErrexitScope scope(_noErrexit,exempt);
                    _exitCode=runSegmentWords(trimmed,words,segstart,i);
                }
                Environment::instance().setLastStatus(_exitCode);
                runPendingTraps();

@@ -3862,7 +3873,7 @@ int fresh::Shell::parse(const std::string &input,bool applyErrexit){
                // statement), so re-testing that same returned number
                // against set -e a second time at this outer level would
                // wrongly abort on a failure real shells already let pass.
                if(applyErrexit && _errexit && _exitCode!=0 && w==";" && !isCompoundStart(words,segstart))
                if(applyErrexit && _errexit && _noErrexit==0 && _exitCode!=0 && w==";" && !isCompoundStart(words,segstart))
                    requestExit(_exitCode);
            }

@@ -3938,13 +3949,16 @@ int fresh::Shell::parse(const std::string &input,bool applyErrexit){
            shouldRun=(_exitCode!=0);

        if(shouldRun){
            {
                NoErrexitScope scope(_noErrexit,words[segstart].text=="!");
                _exitCode=runSegmentWords(trimmed,words,segstart,words.size());
            }
            Environment::instance().setLastStatus(_exitCode);
            runPendingTraps();

            // See the matching comment above: a compound command's own
            // internal set -e handling already did the right thing.
            if(applyErrexit && _errexit && _exitCode!=0 && !isCompoundStart(words,segstart))
            if(applyErrexit && _errexit && _noErrexit==0 && _exitCode!=0 && !isCompoundStart(words,segstart))
                requestExit(_exitCode);
        }
    }
+5 −0
Changes for src/shell.h: 5 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -646,6 +646,11 @@ namespace fresh {
        bool _runningTraps;
        bool _exitTrapRun;
        bool _errexit;
        // >0 while running a context POSIX exempts from set -e: an
        // if/while/until condition, a command before && or ||, a
        // "!" pipeline -- including everything nested in it (function
        // bodies, eval, sourced files).
        int _noErrexit=0;
        std::vector<std::string> _history;
        std::istream *_heredocSource;