about summary refs log blame commit diff stats
path: root/090scenario_filesystem_test.mu
blob: b487bfe08bfbdcad76a9b035c6bc488d60c1ad3f (plain) (tree)
1
2
3
4
5
6
7
8
9



                                                       
                    



            
                                                        



                             
                                







                         
 
                                 
             
                    
   
                                                                      



                           
                                                 
                                               




                                                                     


















                                                                      

                                         
                    
             
   
                                                                      



                           
                                                 
                                               




                                                                     

                                                       
                    




             
                                                                      



                           
                                                 
                                               
                                                  
                                                





                                                                     
# Check our support for fake file systems in scenarios.

scenario read-from-fake-file [
  local-scope
  assume-resources [
    [a] <- [
      |xyz|
    ]
  ]
  contents:&:source:char <- start-reading resources, [a]
  1:char/raw <- read contents
  2:char/raw <- read contents
  3:char/raw <- read contents
  4:char/raw <- read contents
  _, 5:bool/raw <- read contents
  memory-should-contain [
    1 <- 120  # x
    2 <- 121  # y
    3 <- 122  # z
    4 <- 10  # newline
    5 <- 1  # eof
  ]
]

scenario write-to-new-fake-file [
  local-scope
  assume-resources [
  ]
  sink:&:sink:char, writer:num/routine <- start-writing resources, [a]
  sink <- write sink, 120/x
  sink <- write sink, 121/y
  close sink
  wait-for-routine writer
  contents-read-back:text <- slurp resources, [a]
  10:bool/raw <- equal contents-read-back, [xy]
  memory-should-contain [
    10 <- 1  # file contents read back exactly match what was written
  ]
]

scenario write-to-new-fake-file-2 [
  local-scope
  assume-resources [
    [a] <- [
      |abc|
    ]
  ]
  sink:&:sink:char, writer:num/routine <- start-writing resources, [b]
  sink <- write sink, 120/x
  sink <- write sink, 121/y
  close sink
  wait-for-routine writer
  contents-read-back:text <- slurp resources, [b]
  10:bool/raw <- equal contents-read-back, [xy]
  memory-should-contain [
    10 <- 1  # file contents read back exactly match what was written
  ]
]

scenario write-to-fake-file-that-exists [
  local-scope
  assume-resources [
    [a] <- []
  ]
  sink:&:sink:char, writer:num/routine <- start-writing resources, [a]
  sink <- write sink, 120/x
  sink <- write sink, 121/y
  close sink
  wait-for-routine writer
  contents-read-back:text <- slurp resources, [a]
  10:bool/raw <- equal contents-read-back, [xy]
  memory-should-contain [
    10 <- 1  # file contents read back exactly match what was written
  ]
]

scenario write-to-existing-file-preserves-other-files [
  local-scope
  assume-resources [
    [a] <- []
    [b] <- [
      |bcd|
    ]
  ]
  sink:&:sink:char, writer:num/routine <- start-writing resources, [a]
  sink <- write sink, 120/x
  sink <- write sink, 121/y
  close sink
  wait-for-routine writer
  contents-read-back:text <- slurp resources, [a]
  10:bool/raw <- equal contents-read-back, [xy]
  other-file-contents:text <- slurp resources, [b]
  11:bool/raw <- equal other-file-contents, [bcd
]
  memory-should-contain [
    10 <- 1  # file contents read back exactly match what was written
    11 <- 1  # other files also continue to persist unchanged
  ]
]
        
                                                      
                

                                                               
                             










                                                    


                                            




                





                                           

                                         







                                         






                               
             

            


                                       
                                         
                   

                                         

                                     
      




                             


               

                                                             

                
                          
                                   
                             

                          
                                   
                             
              
                            
                                         
                               

                             
                          
                                   


                             
                          
                                  
                                 


              
       
#!/bin/bash

set -o errtrace

STATUS=development

error_handler()
{
        ERR_CODE=$?
        echo "Error $ERR_CODE with command '$BASH_COMMAND' on line ${BASH_LINENO[0]}. Exiting."
        exit $ERR_CODE

}

trap error_handler ERR

debian_prepare()
{
    echo
    echo Profanity installer ... updating apt repositories
    echo
    sudo apt-get update

    echo
    echo Profanity installer... installing dependencies
    echo
    sudo apt-get -y install git automake autoconf libssl-dev libexpat1-dev libncursesw5-dev libglib2.0-dev libnotify-dev libcurl3-dev libxss-dev libotr5-dev libreadline-dev libtool libgpgme11-dev

}

fedora_prepare()
{
    echo
    echo Profanity installer... installing dependencies
    echo

    sudo dnf -y install gcc git autoconf automake openssl-devel expat-devel ncurses-devel glib2-devel libnotify-devel libcurl-devel libXScrnSaver-devel libotr3-devel readline-devel libtool gpgme-devel
}

opensuse_prepare()
{
    echo
    echo Profanity installer...installing dependencies
    echo
    sudo zypper -n in gcc git automake make autoconf libopenssl-devel expat libexpat-devel ncurses-devel glib2-devel libnotify-devel libcurl-devel libXScrnSaver-devel libotr-devel readline-devel libtool libgpgme-devel
}

centos_prepare()
{
    echo
    echo Profanity installer...installing dependencies
    echo

    sudo yum -y install epel-release
    sudo yum -y install git
    sudo yum -y install gcc autoconf automake cmake
    sudo yum -y install openssl-devel expat-devel ncurses-devel glib2-devel libnotify-devel libcurl-devel libXScrnSaver-devel libotr-devel readline-devel libtool gpgme-devel
}

cygwin_prepare()
{
    echo
    echo Profanity installer... installing dependencies
    echo

    if ! command -v apt-cyg &>/dev/null; then cyg_install_apt_cyg; fi
    if [ -n "$CYG_MIRROR" ]; then
        apt-cyg -m $CYG_MIRROR install git make gcc-core m4 automake autoconf pkg-config openssl-devel libexpat-devel zlib-devel libncursesw-devel libglib2.0-devel libcurl-devel libidn-devel libssh2-devel libkrb5-devel openldap-devel libgcrypt-devel libreadline-devel libgpgme-devel libtool
    else
        apt-cyg install git make gcc-core m4 automake autoconf pkg-config openssl-devel libexpat-devel zlib-devel libncursesw-devel libglib2.0-devel libcurl-devel libidn-devel libssh2-devel libkrb5-devel openldap-devel libgcrypt-devel libreadline-devel libgpgme-devel libtool

    fi
}

install_lib_mesode()
{
    echo
    echo Profanity installer... installing libmesode
    echo
    git clone https://github.com/boothj5/libmesode.git
    cd libmesode
    ./bootstrap.sh
    ./configure --prefix=$1
    make
    sudo make install

    cd ..
}

install_profanity()
{
    echo
    echo Profanity installer... installing Profanity
    echo
    if [ "${STATUS}" = "development" ]; then
        ./bootstrap.sh
    fi
    ./configure
    make
    sudo make install
}

cyg_install_apt_cyg()
{
    echo
    echo Profanity installer... installing apt-cyg
    echo
    wget https://raw.githubusercontent.com/transcode-open/apt-cyg/master/apt-cyg
    #wget --no-check-certificate https://raw.github.com/boothj5/apt-cyg/master/apt-cyg
    #wget http://apt-cyg.googlecode.com/svn/trunk/apt-cyg
    chmod +x apt-cyg
    mv apt-cyg /usr/local/bin/

}
cyg_install_lib_mesode()
{
    echo
    echo Profanity installer... installing libmesode
    echo
    git clone https://github.com/boothj5/libmesode.git
    cd libmesode
    ./bootstrap.sh
    ./bootstrap.sh # second call seems to fix problem on cygwin
    ./configure --prefix=/usr
    make
    make install

    cd ..
}

cyg_install_profanity()
{
    echo
    echo Profanity installer... installing Profanity
    echo
    if [ "${STATUS}" = "development" ]; then
        ./bootstrap.sh
    fi
    ./configure
    make
    make install
}

cleanup()
{
    echo
    echo Profanity installer... cleaning up
    echo

    echo Removing libmesode repository...
    rm -rf libmesode

    echo
    echo Profanity installer... complete!
    echo
    echo Type \'profanity\' to run.
    echo
}

while getopts m: opt
do
    case "$opt" in
        m) CYG_MIRROR=$OPTARG;;
    esac
done

OS=`uname -s`
DIST=unknown

if [ "${OS}" = "Linux" ]; then
    if [ -f /etc/fedora-release ]; then
        DIST=fedora
    elif [ -f /etc/debian_version ]; then
        DIST=debian
    elif [ -f /etc/centos-release ]; then
        DIST=centos
    elif [ -f /etc/os-release ]; then
        DIST=opensuse
    fi
else
    echo $OS | grep -i cygwin
    if [ "$?" -eq 0 ]; then
        DIST=cygwin
    fi
fi

case "$DIST" in
unknown)    echo The install script will not work on this OS.
            echo Try a manual install instead.
            exit
            ;;
fedora)     fedora_prepare
            install_lib_mesode /usr
            install_profanity
            ;;
debian)     debian_prepare
            install_lib_mesode /usr
            install_profanity
            ;;
opensuse)   opensuse_prepare
            install_lib_mesode /usr/local
            sudo /sbin/ldconfig
            install_profanity
            ;;
centos)     centos_prepare
            install_lib_mesode /usr
            sudo ldconfig
            install_profanity
            ;;
cygwin)     cygwin_prepare
            cyg_install_lib_mesode
            cyg_install_profanity
            ;;
esac

cleanup